@@ -561,7 +561,7 @@ func TestFastVsFullChains(t *testing.T) {
561561 Alloc : GenesisAlloc {address : {Balance : funds }},
562562 }
563563 genesis = gspec .MustCommit (gendb )
564- signer = types .NewEIP155Signer (gspec .Config . ChainId )
564+ signer = types .LatestSigner (gspec .Config )
565565 )
566566 blocks , receipts := GenerateChain (gspec .Config , genesis , ethash .NewFaker (), gendb , 1024 , func (i int , block * BlockGen ) {
567567 block .SetCoinbase (common.Address {0x00 })
@@ -736,7 +736,7 @@ func TestChainTxReorgs(t *testing.T) {
736736 },
737737 }
738738 genesis = gspec .MustCommit (db )
739- signer = types .NewEIP155Signer (gspec .Config . ChainId )
739+ signer = types .LatestSigner (gspec .Config )
740740 )
741741
742742 // Create two transactions shared between the chains:
@@ -842,7 +842,7 @@ func TestLogReorgs(t *testing.T) {
842842 code = common .Hex2Bytes ("60606040525b7f24ec1d3ff24c2f6ff210738839dbc339cd45a5294d85c79361016243157aae7b60405180905060405180910390a15b600a8060416000396000f360606040526008565b00" )
843843 gspec = & Genesis {Config : params .TestChainConfig , Alloc : GenesisAlloc {addr1 : {Balance : big .NewInt (10000000000000 )}}}
844844 genesis = gspec .MustCommit (db )
845- signer = types .NewEIP155Signer (gspec .Config . ChainId )
845+ signer = types .LatestSigner (gspec .Config )
846846 )
847847
848848 blockchain , _ := NewBlockChain (db , nil , gspec .Config , ethash .NewFaker (), vm.Config {})
@@ -889,7 +889,7 @@ func TestLogReorgs(t *testing.T) {
889889// Alloc: GenesisAlloc{addr1: {Balance: big.NewInt(10000000000000)}},
890890// }
891891// genesis = gspec.MustCommit(db)
892- // signer = types.NewEIP155Signer (gspec.Config.ChainId )
892+ // signer = types.LatestSigner (gspec.Config)
893893// )
894894//
895895// blockchain, _ := NewBlockChain(db, nil, gspec.Config, ethash.NewFaker(), vm.Config{})
@@ -1015,7 +1015,7 @@ func TestEIP155Transition(t *testing.T) {
10151015 funds = big .NewInt (1000000000 )
10161016 deleteAddr = common.Address {1 }
10171017 gspec = & Genesis {
1018- Config : & params.ChainConfig {ChainId : big .NewInt (1 ), EIP155Block : big .NewInt (2 ), HomesteadBlock : new (big.Int )},
1018+ Config : & params.ChainConfig {ChainId : big .NewInt (1 ), EIP150Block : big . NewInt ( 0 ), EIP155Block : big .NewInt (2 ), HomesteadBlock : new (big.Int )},
10191019 Alloc : GenesisAlloc {address : {Balance : funds }, deleteAddr : {Balance : new (big.Int )}},
10201020 }
10211021 genesis = gspec .MustCommit (db )
@@ -1046,7 +1046,7 @@ func TestEIP155Transition(t *testing.T) {
10461046 }
10471047 block .AddTx (tx )
10481048
1049- tx , err = basicTx (types .NewEIP155Signer (gspec .Config . ChainId ))
1049+ tx , err = basicTx (types .LatestSigner (gspec .Config ))
10501050 if err != nil {
10511051 t .Fatal (err )
10521052 }
@@ -1058,7 +1058,7 @@ func TestEIP155Transition(t *testing.T) {
10581058 }
10591059 block .AddTx (tx )
10601060
1061- tx , err = basicTx (types .NewEIP155Signer (gspec .Config . ChainId ))
1061+ tx , err = basicTx (types .LatestSigner (gspec .Config ))
10621062 if err != nil {
10631063 t .Fatal (err )
10641064 }
@@ -1086,7 +1086,7 @@ func TestEIP155Transition(t *testing.T) {
10861086 }
10871087
10881088 // generate an invalid chain id transaction
1089- config := & params.ChainConfig {ChainId : big .NewInt (2 ), EIP155Block : big .NewInt (2 ), HomesteadBlock : new (big.Int )}
1089+ config := & params.ChainConfig {ChainId : big .NewInt (2 ), EIP150Block : big . NewInt ( 0 ), EIP155Block : big .NewInt (2 ), HomesteadBlock : new (big.Int )}
10901090 blocks , _ = GenerateChain (config , blocks [len (blocks )- 1 ], ethash .NewFaker (), db , 4 , func (i int , block * BlockGen ) {
10911091 var (
10921092 tx * types.Transaction
@@ -1095,9 +1095,8 @@ func TestEIP155Transition(t *testing.T) {
10951095 return types .SignTx (types .NewTransaction (block .TxNonce (address ), common.Address {}, new (big.Int ), 21000 , new (big.Int ), nil ), signer , key )
10961096 }
10971097 )
1098- switch i {
1099- case 0 :
1100- tx , err = basicTx (types .NewEIP155Signer (big .NewInt (2 )))
1098+ if i == 0 {
1099+ tx , err = basicTx (types .LatestSigner (config ))
11011100 if err != nil {
11021101 t .Fatal (err )
11031102 }
@@ -1136,7 +1135,7 @@ func TestEIP161AccountRemoval(t *testing.T) {
11361135 var (
11371136 tx * types.Transaction
11381137 err error
1139- signer = types .NewEIP155Signer (gspec .Config . ChainId )
1138+ signer = types .LatestSigner (gspec .Config )
11401139 )
11411140 switch i {
11421141 case 0 :
@@ -1412,3 +1411,93 @@ func TestAreTwoBlocksSamePath(t *testing.T) {
14121411 })
14131412
14141413}
1414+
1415+ // TestEIP2718Transition tests that an EIP-2718 transaction will be accepted
1416+ // after the fork block has passed. This is verified by sending an EIP-2930
1417+ // access list transaction, which specifies a single slot access, and then
1418+ // checking that the gas usage of a hot SLOAD and a cold SLOAD are calculated
1419+ // correctly.
1420+ func TestEIP2718Transition (t * testing.T ) {
1421+ var (
1422+ aa = common .HexToAddress ("0x000000000000000000000000000000000000aaaa" )
1423+
1424+ // Generate a canonical chain to act as the main dataset
1425+ engine = ethash .NewFaker ()
1426+ db = rawdb .NewMemoryDatabase ()
1427+
1428+ // A sender who makes transactions, has some funds
1429+ key , _ = crypto .HexToECDSA ("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
1430+ address = crypto .PubkeyToAddress (key .PublicKey )
1431+ funds = big .NewInt (1000000000 )
1432+ gspec = & Genesis {
1433+ Config : & params.ChainConfig {
1434+ ChainId : new (big.Int ).SetBytes ([]byte ("eip1559" )),
1435+ HomesteadBlock : big .NewInt (0 ),
1436+ DAOForkBlock : nil ,
1437+ DAOForkSupport : true ,
1438+ EIP150Block : big .NewInt (0 ),
1439+ EIP155Block : big .NewInt (0 ),
1440+ EIP158Block : big .NewInt (0 ),
1441+ ByzantiumBlock : big .NewInt (0 ),
1442+ ConstantinopleBlock : big .NewInt (0 ),
1443+ PetersburgBlock : big .NewInt (0 ),
1444+ IstanbulBlock : big .NewInt (0 ),
1445+ Eip1559Block : big .NewInt (0 ),
1446+ },
1447+ Alloc : GenesisAlloc {
1448+ address : {Balance : funds },
1449+ // The address 0xAAAA sloads 0x00 and 0x01
1450+ aa : {
1451+ Code : []byte {
1452+ byte (vm .PC ),
1453+ byte (vm .PC ),
1454+ byte (vm .SLOAD ),
1455+ byte (vm .SLOAD ),
1456+ },
1457+ Nonce : 0 ,
1458+ Balance : big .NewInt (0 ),
1459+ },
1460+ },
1461+ }
1462+ genesis = gspec .MustCommit (db )
1463+ )
1464+
1465+ blocks , _ := GenerateChain (gspec .Config , genesis , engine , db , 1 , func (i int , b * BlockGen ) {
1466+ b .SetCoinbase (common.Address {1 })
1467+
1468+ // One transaction to 0xAAAA
1469+ signer := types .LatestSigner (gspec .Config )
1470+ tx , _ := types .SignNewTx (key , signer , & types.AccessListTx {
1471+ ChainID : gspec .Config .ChainId ,
1472+ Nonce : 0 ,
1473+ To : & aa ,
1474+ Gas : 30000 ,
1475+ GasPrice : big .NewInt (1 ),
1476+ AccessList : types.AccessList {{
1477+ Address : aa ,
1478+ StorageKeys : []common.Hash {{0 }},
1479+ }},
1480+ })
1481+ b .AddTx (tx )
1482+ })
1483+
1484+ // Import the canonical chain
1485+ diskdb := rawdb .NewMemoryDatabase ()
1486+ gspec .MustCommit (diskdb )
1487+
1488+ chain , err := NewBlockChain (diskdb , nil , gspec .Config , engine , vm.Config {})
1489+ if err != nil {
1490+ t .Fatalf ("failed to create tester chain: %v" , err )
1491+ }
1492+ if n , err := chain .InsertChain (blocks ); err != nil {
1493+ t .Fatalf ("block %d: failed to insert into chain: %v" , n , err )
1494+ }
1495+
1496+ block := chain .GetBlockByNumber (1 )
1497+
1498+ // Expected gas is intrinsic + 2 * pc + hot load + cold load, since only one load is in the access list
1499+ expected := params .TxGas + params .TxAccessListAddressGas + params .TxAccessListStorageKeyGas + vm .GasQuickStep * 2 + vm .WarmStorageReadCostEIP2929 + vm .ColdSloadCostEIP2929
1500+ if block .GasUsed () != expected {
1501+ t .Fatalf ("incorrect amount of gas spent: expected %d, got %d" , expected , block .GasUsed ())
1502+ }
1503+ }
0 commit comments