@@ -4187,3 +4187,111 @@ func TestTransientStorageReset(t *testing.T) {
4187
4187
t .Fatalf ("Unexpected dirty storage slot" )
4188
4188
}
4189
4189
}
4190
+
4191
+ func TestEIP3651 (t * testing.T ) {
4192
+ var (
4193
+ aa = common .HexToAddress ("0x000000000000000000000000000000000000aaaa" )
4194
+ bb = common .HexToAddress ("0x000000000000000000000000000000000000bbbb" )
4195
+ engine = ethash .NewFaker ()
4196
+
4197
+ // A sender who makes transactions, has some funds
4198
+ key1 , _ = crypto .HexToECDSA ("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
4199
+ key2 , _ = crypto .HexToECDSA ("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a" )
4200
+ addr1 = crypto .PubkeyToAddress (key1 .PublicKey )
4201
+ addr2 = crypto .PubkeyToAddress (key2 .PublicKey )
4202
+ funds = new (big.Int ).Mul (common .Big1 , big .NewInt (params .Ether ))
4203
+ gspec = & Genesis {
4204
+ Config : params .AllEthashProtocolChanges ,
4205
+ Alloc : GenesisAlloc {
4206
+ addr1 : {Balance : funds },
4207
+ addr2 : {Balance : funds },
4208
+ // The address 0xAAAA sloads 0x00 and 0x01
4209
+ aa : {
4210
+ Code : []byte {
4211
+ byte (vm .PC ),
4212
+ byte (vm .PC ),
4213
+ byte (vm .SLOAD ),
4214
+ byte (vm .SLOAD ),
4215
+ },
4216
+ Nonce : 0 ,
4217
+ Balance : big .NewInt (0 ),
4218
+ },
4219
+ // The address 0xBBBB calls 0xAAAA
4220
+ bb : {
4221
+ Code : []byte {
4222
+ byte (vm .PUSH1 ), 0 , // out size
4223
+ byte (vm .DUP1 ), // out offset
4224
+ byte (vm .DUP1 ), // out insize
4225
+ byte (vm .DUP1 ), // in offset
4226
+ byte (vm .PUSH2 ), // address
4227
+ byte (0xaa ),
4228
+ byte (0xaa ),
4229
+ byte (vm .GAS ), // gas
4230
+ byte (vm .DELEGATECALL ),
4231
+ },
4232
+ Nonce : 0 ,
4233
+ Balance : big .NewInt (0 ),
4234
+ },
4235
+ },
4236
+ }
4237
+ )
4238
+
4239
+ gspec .Config .BerlinBlock = common .Big0
4240
+ gspec .Config .LondonBlock = common .Big0
4241
+ gspec .Config .ShanghaiBlock = common .Big0
4242
+ signer := types .LatestSigner (gspec .Config )
4243
+
4244
+ _ , blocks , _ := GenerateChainWithGenesis (gspec , engine , 1 , func (i int , b * BlockGen ) {
4245
+ b .SetCoinbase (aa )
4246
+ // One transaction to Coinbase
4247
+ txdata := & types.DynamicFeeTx {
4248
+ ChainID : gspec .Config .ChainID ,
4249
+ Nonce : 0 ,
4250
+ To : & bb ,
4251
+ Gas : 500000 ,
4252
+ GasFeeCap : newGwei (5 ),
4253
+ GasTipCap : big .NewInt (2 ),
4254
+ AccessList : nil ,
4255
+ Data : []byte {},
4256
+ }
4257
+ tx := types .NewTx (txdata )
4258
+ tx , _ = types .SignTx (tx , signer , key1 )
4259
+
4260
+ b .AddTx (tx )
4261
+ })
4262
+ chain , err := NewBlockChain (rawdb .NewMemoryDatabase (), nil , gspec , nil , engine , vm.Config {Tracer : logger .NewMarkdownLogger (& logger.Config {}, os .Stderr )}, nil , nil )
4263
+ if err != nil {
4264
+ t .Fatalf ("failed to create tester chain: %v" , err )
4265
+ }
4266
+ if n , err := chain .InsertChain (blocks ); err != nil {
4267
+ t .Fatalf ("block %d: failed to insert into chain: %v" , n , err )
4268
+ }
4269
+
4270
+ block := chain .GetBlockByNumber (1 )
4271
+
4272
+ // 1+2: Ensure EIP-1559 access lists are accounted for via gas usage.
4273
+ innerGas := vm .GasQuickStep * 2 + params .ColdSloadCostEIP2929 * 2
4274
+ expectedGas := params .TxGas + 5 * vm .GasFastestStep + vm .GasQuickStep + 100 + innerGas // 100 because 0xaaaa is in access list
4275
+ if block .GasUsed () != expectedGas {
4276
+ t .Fatalf ("incorrect amount of gas spent: expected %d, got %d" , expectedGas , block .GasUsed ())
4277
+ }
4278
+
4279
+ state , _ := chain .State ()
4280
+
4281
+ // 3: Ensure that miner received only the tx's tip.
4282
+ actual := state .GetBalance (block .Coinbase ())
4283
+ expected := new (big.Int ).Add (
4284
+ new (big.Int ).SetUint64 (block .GasUsed ()* block .Transactions ()[0 ].GasTipCap ().Uint64 ()),
4285
+ ethash .ConstantinopleBlockReward ,
4286
+ )
4287
+ if actual .Cmp (expected ) != 0 {
4288
+ t .Fatalf ("miner balance incorrect: expected %d, got %d" , expected , actual )
4289
+ }
4290
+
4291
+ // 4: Ensure the tx sender paid for the gasUsed * (tip + block baseFee).
4292
+ actual = new (big.Int ).Sub (funds , state .GetBalance (addr1 ))
4293
+ expected = new (big.Int ).SetUint64 (block .GasUsed () * (block .Transactions ()[0 ].GasTipCap ().Uint64 () + block .BaseFee ().Uint64 ()))
4294
+ if actual .Cmp (expected ) != 0 {
4295
+ t .Fatalf ("sender balance incorrect: expected %d, got %d" , expected , actual )
4296
+ }
4297
+ }
0 commit comments