@@ -3238,3 +3238,118 @@ func TestTransactionCountLimit(t *testing.T) {
3238
3238
t .Fatalf ("error mismatch: have: %v, want: %v" , err , consensus .ErrInvalidTxCount )
3239
3239
}
3240
3240
}
3241
+
3242
+ func TestEIP3651 (t * testing.T ) {
3243
+ var (
3244
+ addraa = common .HexToAddress ("0x000000000000000000000000000000000000aaaa" )
3245
+ addrbb = common .HexToAddress ("0x000000000000000000000000000000000000bbbb" )
3246
+ engine = ethash .NewFaker ()
3247
+ db = rawdb .NewMemoryDatabase ()
3248
+
3249
+ // A sender who makes transactions, has some funds
3250
+ key1 , _ = crypto .HexToECDSA ("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291" )
3251
+ key2 , _ = crypto .HexToECDSA ("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a" )
3252
+ addr1 = crypto .PubkeyToAddress (key1 .PublicKey )
3253
+ addr2 = crypto .PubkeyToAddress (key2 .PublicKey )
3254
+ funds = new (big.Int ).Mul (common .Big1 , big .NewInt (params .Ether ))
3255
+ gspec = & Genesis {
3256
+ Config : params .AllEthashProtocolChanges ,
3257
+ Alloc : GenesisAlloc {
3258
+ addr1 : {Balance : funds },
3259
+ addr2 : {Balance : funds },
3260
+ // The address 0xAAAA sloads 0x00 and 0x01
3261
+ addraa : {
3262
+ Code : []byte {
3263
+ byte (vm .PC ),
3264
+ byte (vm .PC ),
3265
+ byte (vm .SLOAD ),
3266
+ byte (vm .SLOAD ),
3267
+ },
3268
+ Nonce : 0 ,
3269
+ Balance : big .NewInt (0 ),
3270
+ },
3271
+ // The address 0xBBBB calls 0xAAAA
3272
+ addrbb : {
3273
+ Code : []byte {
3274
+ byte (vm .PUSH1 ), 0 , // out size
3275
+ byte (vm .DUP1 ), // out offset
3276
+ byte (vm .DUP1 ), // out insize
3277
+ byte (vm .DUP1 ), // in offset
3278
+ byte (vm .PUSH2 ), // address
3279
+ byte (0xaa ),
3280
+ byte (0xaa ),
3281
+ byte (vm .GAS ), // gas
3282
+ byte (vm .DELEGATECALL ),
3283
+ },
3284
+ Nonce : 0 ,
3285
+ Balance : big .NewInt (0 ),
3286
+ },
3287
+ },
3288
+ }
3289
+ genesis = gspec .MustCommit (db )
3290
+ )
3291
+
3292
+ gspec .Config .BerlinBlock = common .Big0
3293
+ gspec .Config .LondonBlock = common .Big0
3294
+ gspec .Config .ShanghaiBlock = common .Big0
3295
+ signer := types .LatestSigner (gspec .Config )
3296
+
3297
+ blocks , _ := GenerateChain (gspec .Config , genesis , engine , db , 1 , func (i int , b * BlockGen ) {
3298
+ b .SetCoinbase (addraa )
3299
+ // One transaction to Coinbase
3300
+ txdata := & types.DynamicFeeTx {
3301
+ ChainID : gspec .Config .ChainID ,
3302
+ Nonce : 0 ,
3303
+ To : & addrbb ,
3304
+ Gas : 500000 ,
3305
+ GasFeeCap : newGwei (5 ),
3306
+ GasTipCap : big .NewInt (2 ),
3307
+ AccessList : nil ,
3308
+ Data : []byte {},
3309
+ }
3310
+ tx := types .NewTx (txdata )
3311
+ tx , err := types .SignTx (tx , signer , key1 )
3312
+ if err != nil {
3313
+ t .Fatalf ("failed to sign tx: %v" , err )
3314
+ }
3315
+ b .AddTx (tx )
3316
+ })
3317
+ chain , err := NewBlockChain (db , nil , gspec .Config , engine , vm.Config {}, nil , nil )
3318
+ if err != nil {
3319
+ t .Fatalf ("failed to create tester chain: %v" , err )
3320
+ }
3321
+ if n , err := chain .InsertChain (blocks ); err != nil {
3322
+ t .Fatalf ("block %d: failed to insert into chain: %v" , n , err )
3323
+ }
3324
+
3325
+ block := chain .GetBlockByNumber (1 )
3326
+
3327
+ // 1+2: Ensure EIP-1559 access lists are accounted for via gas usage.
3328
+ innerGas := vm .GasQuickStep * 2 + params .ColdSloadCostEIP2929 * 2
3329
+ expectedGas := params .TxGas + 5 * vm .GasFastestStep + vm .GasQuickStep + 100 + innerGas // 100 because 0xaaaa is in access list
3330
+ if block .GasUsed () != expectedGas {
3331
+ t .Fatalf ("incorrect amount of gas spent: expected %d, got %d" , expectedGas , block .GasUsed ())
3332
+ }
3333
+
3334
+ state , err := chain .State ()
3335
+ if err != nil {
3336
+ t .Fatalf ("failed to get new state: %v" , err )
3337
+ }
3338
+
3339
+ // 3: Ensure that miner received only the tx's tip.
3340
+ actual := state .GetBalance (block .Coinbase ())
3341
+ expected := new (big.Int ).Add (
3342
+ new (big.Int ).SetUint64 (block .GasUsed ()* block .Transactions ()[0 ].GasTipCap ().Uint64 ()),
3343
+ ethash .ConstantinopleBlockReward ,
3344
+ )
3345
+ if actual .Cmp (expected ) != 0 {
3346
+ t .Fatalf ("miner balance incorrect: expected %d, got %d" , expected , actual )
3347
+ }
3348
+
3349
+ // 4: Ensure the tx sender paid for the gasUsed * (tip + block baseFee).
3350
+ actual = new (big.Int ).Sub (funds , state .GetBalance (addr1 ))
3351
+ expected = new (big.Int ).SetUint64 (block .GasUsed () * (block .Transactions ()[0 ].GasTipCap ().Uint64 () + block .BaseFee ().Uint64 ()))
3352
+ if actual .Cmp (expected ) != 0 {
3353
+ t .Fatalf ("sender balance incorrect: expected %d, got %d" , expected , actual )
3354
+ }
3355
+ }
0 commit comments