diff --git a/zkevm-circuits/src/super_circuit.rs b/zkevm-circuits/src/super_circuit.rs index e2dc6c4882..78e7637c69 100644 --- a/zkevm-circuits/src/super_circuit.rs +++ b/zkevm-circuits/src/super_circuit.rs @@ -49,7 +49,11 @@ //! - [x] Bytecode Circuit //! - [x] Tx Circuit //! - [ ] MPT Circuit -pub(crate) mod precompile_block_trace; +#[cfg(feature = "scroll")] +mod eip1559; +#[cfg(feature = "scroll")] +mod eip2930; +mod precompile_block_trace; #[cfg(any(feature = "test", test))] pub(crate) mod test; diff --git a/zkevm-circuits/src/super_circuit/eip1559.rs b/zkevm-circuits/src/super_circuit/eip1559.rs new file mode 100644 index 0000000000..40bb1a488f --- /dev/null +++ b/zkevm-circuits/src/super_circuit/eip1559.rs @@ -0,0 +1,57 @@ +//! Helper functions for super circuit tests of EIP-1559 + +use super::CircuitsParams; +use eth_types::{address, l2_types::BlockTrace}; +use ethers_signers::{LocalWallet, Signer}; +use mock::{eth, gwei, TestContext, MOCK_CHAIN_ID}; +use rand::SeedableRng; +use rand_chacha::ChaCha20Rng; + +pub(crate) fn test_block_trace() -> BlockTrace { + let mut rng = ChaCha20Rng::seed_from_u64(2); + let wallet_a = LocalWallet::new(&mut rng).with_chain_id(MOCK_CHAIN_ID); + + let addr_a = wallet_a.address(); + let addr_b = address!("0x0000000000000000000000000000000000001559"); + + TestContext::<2, 1>::new( + None, + |accs| { + accs[0].address(addr_b).balance(eth(1)); + accs[1].address(addr_a).balance(gwei(80_000)); + }, + |mut txs, _accs| { + txs[0] + .from(addr_a) + .to(addr_b) + .gas_price(gwei(2)) + .gas(30_000.into()) + .value(gwei(20_000)) + .max_fee_per_gas(gwei(2)) + .max_priority_fee_per_gas(gwei(2)) + .transaction_type(2); // Set tx type to EIP-1559. + }, + |block, _tx| block.number(0xcafe_u64), + ) + .unwrap() + .l2_trace() + .clone() +} + +pub(crate) fn test_circuits_params(max_txs: usize, max_calldata: usize) -> CircuitsParams { + CircuitsParams { + max_txs, + max_calldata, + max_rws: 256, + max_copy_rows: 256, + max_exp_steps: 256, + max_bytecode: 512, + max_mpt_rows: 2049, + max_poseidon_rows: 512, + max_evm_rows: 0, + max_keccak_rows: 0, + max_inner_blocks: 1, + max_rlp_rows: 500, + ..Default::default() + } +} diff --git a/zkevm-circuits/src/super_circuit/eip2930.rs b/zkevm-circuits/src/super_circuit/eip2930.rs new file mode 100644 index 0000000000..57483df306 --- /dev/null +++ b/zkevm-circuits/src/super_circuit/eip2930.rs @@ -0,0 +1,71 @@ +//! Helper functions for super circuit tests of EIP-2930 + +use super::CircuitsParams; +use eth_types::{address, l2_types::BlockTrace, AccessList, AccessListItem, H256}; +use ethers_signers::{LocalWallet, Signer}; +use mock::{eth, gwei, TestContext, MOCK_CHAIN_ID}; +use rand::SeedableRng; +use rand_chacha::ChaCha20Rng; + +pub(crate) fn test_block_trace() -> BlockTrace { + let mut rng = ChaCha20Rng::seed_from_u64(2); + let wallet_a = LocalWallet::new(&mut rng).with_chain_id(MOCK_CHAIN_ID); + + let addr_a = wallet_a.address(); + let addr_b = address!("0x0000000000000000000000000000000000002930"); + + let test_access_list = AccessList(vec![ + AccessListItem { + address: address!("0x0000000000000000000000000000000000001111"), + storage_keys: [10, 11].map(H256::from_low_u64_be).to_vec(), + }, + AccessListItem { + address: address!("0x0000000000000000000000000000000000002222"), + storage_keys: [20, 22].map(H256::from_low_u64_be).to_vec(), + }, + AccessListItem { + address: address!("0x0000000000000000000000000000000000003333"), + storage_keys: [30, 33].map(H256::from_low_u64_be).to_vec(), + }, + ]); + + TestContext::<2, 1>::new( + None, + |accs| { + accs[0].address(addr_b).balance(eth(20)); + accs[1].address(addr_a).balance(eth(20)); + }, + |mut txs, _accs| { + txs[0] + .from(addr_a) + .to(addr_b) + .gas_price(gwei(2)) + .gas(1_000_000.into()) + .value(eth(2)) + .transaction_type(1) // Set tx type to EIP-2930. + .access_list(test_access_list); + }, + |block, _tx| block.number(0xcafe_u64), + ) + .unwrap() + .l2_trace() + .clone() +} + +pub(crate) fn test_circuits_params(max_txs: usize, max_calldata: usize) -> CircuitsParams { + CircuitsParams { + max_txs, + max_calldata, + max_rws: 256, + max_copy_rows: 256, + max_exp_steps: 256, + max_bytecode: 512, + max_mpt_rows: 2049, + max_poseidon_rows: 512, + max_evm_rows: 0, + max_keccak_rows: 0, + max_inner_blocks: 1, + max_rlp_rows: 500, + ..Default::default() + } +} diff --git a/zkevm-circuits/src/super_circuit/test.rs b/zkevm-circuits/src/super_circuit/test.rs index 7688643673..b4dc3bb1db 100644 --- a/zkevm-circuits/src/super_circuit/test.rs +++ b/zkevm-circuits/src/super_circuit/test.rs @@ -485,3 +485,34 @@ fn serial_test_super_circuit_precompile_sha256() { test_super_circuit::(block, circuits_params); } + +#[ignore] +#[cfg(feature = "scroll")] +#[test] +fn serial_test_super_circuit_eip_1559_tx() { + const MAX_TXS: usize = 1; + const MAX_CALLDATA: usize = 256; + + let block_trace = eip1559::test_block_trace(); + let circuits_params = eip1559::test_circuits_params(MAX_TXS, MAX_CALLDATA); + + test_super_circuit::( + block_trace, + circuits_params, + ); +} +#[ignore] +#[cfg(feature = "scroll")] +#[test] +fn serial_test_super_circuit_eip_2930_tx() { + const MAX_TXS: usize = 1; + const MAX_CALLDATA: usize = 256; + + let block_trace = eip2930::test_block_trace(); + let circuits_params = eip2930::test_circuits_params(MAX_TXS, MAX_CALLDATA); + + test_super_circuit::( + block_trace, + circuits_params, + ); +}