|
|
@ -4187,3 +4187,111 @@ func TestTransientStorageReset(t *testing.T) { |
|
|
|
t.Fatalf("Unexpected dirty storage slot") |
|
|
|
t.Fatalf("Unexpected dirty storage slot") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func TestEIP3651(t *testing.T) { |
|
|
|
|
|
|
|
var ( |
|
|
|
|
|
|
|
aa = common.HexToAddress("0x000000000000000000000000000000000000aaaa") |
|
|
|
|
|
|
|
bb = common.HexToAddress("0x000000000000000000000000000000000000bbbb") |
|
|
|
|
|
|
|
engine = ethash.NewFaker() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// A sender who makes transactions, has some funds
|
|
|
|
|
|
|
|
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") |
|
|
|
|
|
|
|
key2, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a") |
|
|
|
|
|
|
|
addr1 = crypto.PubkeyToAddress(key1.PublicKey) |
|
|
|
|
|
|
|
addr2 = crypto.PubkeyToAddress(key2.PublicKey) |
|
|
|
|
|
|
|
funds = new(big.Int).Mul(common.Big1, big.NewInt(params.Ether)) |
|
|
|
|
|
|
|
gspec = &Genesis{ |
|
|
|
|
|
|
|
Config: params.AllEthashProtocolChanges, |
|
|
|
|
|
|
|
Alloc: GenesisAlloc{ |
|
|
|
|
|
|
|
addr1: {Balance: funds}, |
|
|
|
|
|
|
|
addr2: {Balance: funds}, |
|
|
|
|
|
|
|
// The address 0xAAAA sloads 0x00 and 0x01
|
|
|
|
|
|
|
|
aa: { |
|
|
|
|
|
|
|
Code: []byte{ |
|
|
|
|
|
|
|
byte(vm.PC), |
|
|
|
|
|
|
|
byte(vm.PC), |
|
|
|
|
|
|
|
byte(vm.SLOAD), |
|
|
|
|
|
|
|
byte(vm.SLOAD), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
Nonce: 0, |
|
|
|
|
|
|
|
Balance: big.NewInt(0), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
// The address 0xBBBB calls 0xAAAA
|
|
|
|
|
|
|
|
bb: { |
|
|
|
|
|
|
|
Code: []byte{ |
|
|
|
|
|
|
|
byte(vm.PUSH1), 0, // out size
|
|
|
|
|
|
|
|
byte(vm.DUP1), // out offset
|
|
|
|
|
|
|
|
byte(vm.DUP1), // out insize
|
|
|
|
|
|
|
|
byte(vm.DUP1), // in offset
|
|
|
|
|
|
|
|
byte(vm.PUSH2), // address
|
|
|
|
|
|
|
|
byte(0xaa), |
|
|
|
|
|
|
|
byte(0xaa), |
|
|
|
|
|
|
|
byte(vm.GAS), // gas
|
|
|
|
|
|
|
|
byte(vm.DELEGATECALL), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
Nonce: 0, |
|
|
|
|
|
|
|
Balance: big.NewInt(0), |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gspec.Config.BerlinBlock = common.Big0 |
|
|
|
|
|
|
|
gspec.Config.LondonBlock = common.Big0 |
|
|
|
|
|
|
|
gspec.Config.ShanghaiBlock = common.Big0 |
|
|
|
|
|
|
|
signer := types.LatestSigner(gspec.Config) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_, blocks, _ := GenerateChainWithGenesis(gspec, engine, 1, func(i int, b *BlockGen) { |
|
|
|
|
|
|
|
b.SetCoinbase(aa) |
|
|
|
|
|
|
|
// One transaction to Coinbase
|
|
|
|
|
|
|
|
txdata := &types.DynamicFeeTx{ |
|
|
|
|
|
|
|
ChainID: gspec.Config.ChainID, |
|
|
|
|
|
|
|
Nonce: 0, |
|
|
|
|
|
|
|
To: &bb, |
|
|
|
|
|
|
|
Gas: 500000, |
|
|
|
|
|
|
|
GasFeeCap: newGwei(5), |
|
|
|
|
|
|
|
GasTipCap: big.NewInt(2), |
|
|
|
|
|
|
|
AccessList: nil, |
|
|
|
|
|
|
|
Data: []byte{}, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tx := types.NewTx(txdata) |
|
|
|
|
|
|
|
tx, _ = types.SignTx(tx, signer, key1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
b.AddTx(tx) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
chain, err := NewBlockChain(rawdb.NewMemoryDatabase(), nil, gspec, nil, engine, vm.Config{Tracer: logger.NewMarkdownLogger(&logger.Config{}, os.Stderr)}, nil, nil) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Fatalf("failed to create tester chain: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if n, err := chain.InsertChain(blocks); err != nil { |
|
|
|
|
|
|
|
t.Fatalf("block %d: failed to insert into chain: %v", n, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
block := chain.GetBlockByNumber(1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 1+2: Ensure EIP-1559 access lists are accounted for via gas usage.
|
|
|
|
|
|
|
|
innerGas := vm.GasQuickStep*2 + params.ColdSloadCostEIP2929*2 |
|
|
|
|
|
|
|
expectedGas := params.TxGas + 5*vm.GasFastestStep + vm.GasQuickStep + 100 + innerGas // 100 because 0xaaaa is in access list
|
|
|
|
|
|
|
|
if block.GasUsed() != expectedGas { |
|
|
|
|
|
|
|
t.Fatalf("incorrect amount of gas spent: expected %d, got %d", expectedGas, block.GasUsed()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state, _ := chain.State() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 3: Ensure that miner received only the tx's tip.
|
|
|
|
|
|
|
|
actual := state.GetBalance(block.Coinbase()) |
|
|
|
|
|
|
|
expected := new(big.Int).Add( |
|
|
|
|
|
|
|
new(big.Int).SetUint64(block.GasUsed()*block.Transactions()[0].GasTipCap().Uint64()), |
|
|
|
|
|
|
|
ethash.ConstantinopleBlockReward, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
if actual.Cmp(expected) != 0 { |
|
|
|
|
|
|
|
t.Fatalf("miner balance incorrect: expected %d, got %d", expected, actual) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 4: Ensure the tx sender paid for the gasUsed * (tip + block baseFee).
|
|
|
|
|
|
|
|
actual = new(big.Int).Sub(funds, state.GetBalance(addr1)) |
|
|
|
|
|
|
|
expected = new(big.Int).SetUint64(block.GasUsed() * (block.Transactions()[0].GasTipCap().Uint64() + block.BaseFee().Uint64())) |
|
|
|
|
|
|
|
if actual.Cmp(expected) != 0 { |
|
|
|
|
|
|
|
t.Fatalf("sender balance incorrect: expected %d, got %d", expected, actual) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|