@@ -1254,9 +1254,10 @@ mod test {
12541254 use std:: { str:: FromStr , vec} ;
12551255
12561256 use crate :: { evm_circuit:: test:: rand_bytes, test_util:: CircuitTestBuilder } ;
1257- use bus_mapping:: evm:: OpcodeId ;
1257+ use bus_mapping:: { circuit_input_builder :: CircuitsParams , evm:: OpcodeId } ;
12581258 use eth_types:: {
1259- self , address, bytecode, evm_types:: GasCost , word, Address , Bytecode , Hash , Word , U256 ,
1259+ self , address, bytecode, evm_types:: GasCost , word, Address , Bytecode , Error , Hash , Word ,
1260+ U256 ,
12601261 } ;
12611262 use ethers_core:: { types:: Bytes , utils:: get_contract_address} ;
12621263 use mock:: { eth, gwei, MockTransaction , TestContext , MOCK_ACCOUNTS } ;
@@ -1737,4 +1738,79 @@ mod test {
17371738 . block_modifier ( Box :: new ( |block| block. circuits_params . max_txs = 3 ) )
17381739 . run ( ) ;
17391740 }
1741+
1742+ // Note: all pre-eip155 txs here for testing have signature data. don't need to generate signature dynamically
1743+ // because ethers-rs lib's helper `sign_transaction_sync` doesn't support pre-eip155 type.
1744+ #[ test]
1745+ fn test_legacy_tx_pre_eip155 ( ) {
1746+ let mut tx1 = MockTransaction :: default ( ) ;
1747+ // pre-eip155 tx1 downloaded from [etherscan](https://etherscan.io/getRawTx?tx=0x9cd2288e69623b109e25edc46bc518156498b521e5c162d96e1ab392ff1d9dff)
1748+ // tx with signature::v =0x1c (28).
1749+ let sig_data1 = (
1750+ 0x1c_u64 ,
1751+ word ! ( "0x90b751c5870e9bc071c8d6b2bf1ee80f36ee7efd8e6fbabaa25bd3b8b68cfe9b" ) ,
1752+ word ! ( "0x79c25a01f12493a6d35f1330306d4e3c4e782fcbffc64c6809959577f41ff248" ) ,
1753+ ) ;
1754+
1755+ tx1
1756+ . from ( address ! ( "0xcf40d0d2b44f2b66e07cace1372ca42b73cf21a3" ) )
1757+ . nonce ( word ! ( "0x2ea8" ) )
1758+ . gas_price ( word ! ( "0x098bca5a00" ) )
1759+ . gas ( word ! ( "0x0249f0" ) )
1760+ . value ( word ! ( "0x00" ) )
1761+ // Set tx type to pre-eip155.
1762+ . transaction_type ( 0 )
1763+ . input ( hex:: decode ( "606060405260008054600160a060020a0319163317905560f2806100236000396000f3606060405260e060020a6000350463f5537ede8114601c575b6002565b3460025760f06004356024356044356000805433600160a060020a039081169116141560ea5783905080600160a060020a031663a9059cbb84846000604051602001526040518360e060020a0281526004018083600160a060020a0316815260200182815260200192505050602060405180830381600087803b1560025760325a03f1156002575050604080518481529051600160a060020a0386811693508716917fd0ed88a3f042c6bbb1e3ea406079b5f2b4b198afccaa535d837f4c63abbc4de6919081900360200190a35b50505050565b00" )
1764+ . expect ( "hex data can be decoded" ) . into ( ) )
1765+ . sig_data ( sig_data1) ;
1766+
1767+ // pre-eip155 tx2 refers to https://github.com/scroll-tech/go-ethereum/blob/develop/cmd/evm/testdata/3/txs.json.
1768+ let mut tx2 = MockTransaction :: default ( ) ;
1769+ // tx with signature::v =0x1b (27).
1770+ let sig_data2 = (
1771+ 0x1b_u64 ,
1772+ word ! ( "0x88544c93a564b4c28d2ffac2074a0c55fdd4658fe0d215596ed2e32e3ef7f56b" ) ,
1773+ word ! ( "0x7fb4075d54190f825d7c47bb820284757b34fd6293904a93cddb1d3aa961ac28" ) ,
1774+ ) ;
1775+
1776+ tx2. from ( address ! ( "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b" ) )
1777+ . to ( address ! ( "0x095e7baea6a6c7c4c2dfeb977efac326af552d87" ) )
1778+ . nonce ( word ! ( "0x0" ) )
1779+ . gas_price ( word ! ( "0x1" ) )
1780+ . gas ( word ! ( "0x5f5e100" ) )
1781+ . value ( word ! ( "0x186a0" ) )
1782+ // Set tx type to pre-eip155.
1783+ . transaction_type ( 0 )
1784+ . sig_data ( sig_data2) ;
1785+
1786+ for tx in [ tx1, tx2] {
1787+ let ctx = build_legacy_ctx ( gwei ( 8_000_000 ) , & tx) . unwrap ( ) ;
1788+ CircuitTestBuilder :: new_from_test_ctx ( ctx)
1789+ . params ( CircuitsParams {
1790+ max_calldata : 300 ,
1791+ ..Default :: default ( )
1792+ } )
1793+ . run ( )
1794+ }
1795+ }
1796+
1797+ // build pre-eip155 tx
1798+ fn build_legacy_ctx (
1799+ sender_balance : Word ,
1800+ tx : & MockTransaction ,
1801+ ) -> Result < TestContext < 1 , 1 > , Error > {
1802+ TestContext :: new (
1803+ None ,
1804+ |accs| {
1805+ accs[ 0 ]
1806+ . address ( tx. from . address ( ) )
1807+ . balance ( sender_balance)
1808+ . nonce ( tx. nonce ) ;
1809+ } ,
1810+ |mut txs, _accs| {
1811+ txs[ 0 ] . clone_from ( tx) ;
1812+ } ,
1813+ |block, _tx| block. number ( 0xcafeu64 ) ,
1814+ )
1815+ }
17401816}
0 commit comments