From 60280f3236e85cf97cecb72e3da1f0ed718e73b1 Mon Sep 17 00:00:00 2001 From: Dream Wu Date: Thu, 19 Sep 2024 12:08:23 +0800 Subject: [PATCH] add eip155 --- .../src/evm_circuit/tests/eip155.rs | 39 +++++++++++++++++++ .../src/evm_circuit/tests/pre-eip155.rs | 11 ------ .../src/evm_circuit/util/common_gadget.rs | 4 +- .../{tx_2930.rs => tx_eip2930.rs} | 0 4 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 zkevm-circuits/src/evm_circuit/tests/eip155.rs rename zkevm-circuits/src/evm_circuit/util/common_gadget/{tx_2930.rs => tx_eip2930.rs} (100%) diff --git a/zkevm-circuits/src/evm_circuit/tests/eip155.rs b/zkevm-circuits/src/evm_circuit/tests/eip155.rs new file mode 100644 index 0000000000..023e418643 --- /dev/null +++ b/zkevm-circuits/src/evm_circuit/tests/eip155.rs @@ -0,0 +1,39 @@ +// tests for eip155 tx +#[cfg(test)] +mod test { + use crate::test_util::CircuitTestBuilder; + use eth_types::{address, AccessList, AccessListItem, Error, Word, H256}; + use ethers_signers::Signer; + use mock::{eth, gwei, TestContext, MOCK_ACCOUNTS, MOCK_WALLETS}; + + // test with empty access list. + #[test] + fn test_eip2930_tx_for_empty_access_list() { + let ctx = build_ctx(gwei(80_000)).unwrap(); + } + + fn build_ctx( + sender_balance: Word, + ) -> Result, Error> { + TestContext::new( + None, + |accs| { + accs[0] + .address(MOCK_WALLETS[0].address()) + .balance(sender_balance); + accs[1].address(MOCK_ACCOUNTS[0]).balance(eth(1)); + }, + |mut txs, _accs| { + txs[0] + .from(MOCK_WALLETS[0].clone()) + .to(MOCK_ACCOUNTS[0]) + .gas(40_000.into()) + .gas_price(30_000.into()) + .value(gwei(20_000)) + // Set tx type to EIP-155. + .transaction_type(0); + }, + |block, _tx| block.number(0xcafeu64), + ) + } +} diff --git a/zkevm-circuits/src/evm_circuit/tests/pre-eip155.rs b/zkevm-circuits/src/evm_circuit/tests/pre-eip155.rs index 968bd5b08a..9357843d1f 100644 --- a/zkevm-circuits/src/evm_circuit/tests/pre-eip155.rs +++ b/zkevm-circuits/src/evm_circuit/tests/pre-eip155.rs @@ -11,17 +11,6 @@ mod test { use ethers_core::{types::Bytes, utils::get_contract_address}; use mock::{eth, gwei, MockTransaction, TestContext, MOCK_ACCOUNTS}; - fn gas(call_data: &[u8]) -> Word { - Word::from( - GasCost::TX.as_u64() - + 2 * OpcodeId::PUSH32.constant_gas_cost().as_u64() - + call_data - .iter() - .map(|&x| if x == 0 { 4 } else { 16 }) - .sum::(), - ) - } - // Note: all pre-eip155 txs here for testing have signature data. don't need to generate signature dynamically // because ethers-rs lib's helper `sign_transaction_sync` doesn't support pre-eip155 type. #[test] diff --git a/zkevm-circuits/src/evm_circuit/util/common_gadget.rs b/zkevm-circuits/src/evm_circuit/util/common_gadget.rs index de2ee03757..2e0eaa5e8b 100644 --- a/zkevm-circuits/src/evm_circuit/util/common_gadget.rs +++ b/zkevm-circuits/src/evm_circuit/util/common_gadget.rs @@ -32,13 +32,13 @@ use halo2_proofs::{ plonk::{Error, Expression}, }; -mod tx_access_list; mod tx_eip1559; +mod tx_eip2930; mod tx_l1_fee; mod tx_l1_msg; -pub(crate) use tx_access_list::TxAccessListGadget; pub(crate) use tx_eip1559::TxEip1559Gadget; +pub(crate) use tx_eip2930::TxAccessListGadget; pub(crate) use tx_l1_fee::TxL1FeeGadget; pub(crate) use tx_l1_msg::TxL1MsgGadget; diff --git a/zkevm-circuits/src/evm_circuit/util/common_gadget/tx_2930.rs b/zkevm-circuits/src/evm_circuit/util/common_gadget/tx_eip2930.rs similarity index 100% rename from zkevm-circuits/src/evm_circuit/util/common_gadget/tx_2930.rs rename to zkevm-circuits/src/evm_circuit/util/common_gadget/tx_eip2930.rs