Skip to content

Commit 1f10a5a

Browse files
committed
cmd/evm: calc base fee if parent data is present
1 parent c4a6621 commit 1f10a5a

File tree

8 files changed

+115
-1
lines changed

8 files changed

+115
-1
lines changed

cmd/evm/internal/t8ntool/execution.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ type stEnv struct {
6969
Difficulty *big.Int `json:"currentDifficulty"`
7070
Random *big.Int `json:"currentRandom"`
7171
ParentDifficulty *big.Int `json:"parentDifficulty"`
72+
ParentBaseFee *big.Int `json:"parentBaseFee,omitempty"`
73+
ParentGasUsed uint64 `json:"parentGasUsed,omitempty"`
74+
ParentGasLimit uint64 `json:"parentGasLimit,omitempty"`
7275
GasLimit uint64 `json:"currentGasLimit" gencodec:"required"`
7376
Number uint64 `json:"currentNumber" gencodec:"required"`
7477
Timestamp uint64 `json:"currentTimestamp" gencodec:"required"`
@@ -84,6 +87,9 @@ type stEnvMarshaling struct {
8487
Difficulty *math.HexOrDecimal256
8588
Random *math.HexOrDecimal256
8689
ParentDifficulty *math.HexOrDecimal256
90+
ParentBaseFee *math.HexOrDecimal256
91+
ParentGasUsed math.HexOrDecimal64
92+
ParentGasLimit math.HexOrDecimal64
8793
GasLimit math.HexOrDecimal64
8894
Number math.HexOrDecimal64
8995
Timestamp math.HexOrDecimal64

cmd/evm/internal/t8ntool/gen_stenv.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/evm/internal/t8ntool/transition.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"github.com/ethereum/go-ethereum/common"
3030
"github.com/ethereum/go-ethereum/common/hexutil"
31+
"github.com/ethereum/go-ethereum/consensus/misc"
3132
"github.com/ethereum/go-ethereum/core"
3233
"github.com/ethereum/go-ethereum/core/state"
3334
"github.com/ethereum/go-ethereum/core/types"
@@ -247,7 +248,17 @@ func Transition(ctx *cli.Context) error {
247248
}
248249
// Sanity check, to not `panic` in state_transition
249250
if chainConfig.IsLondon(big.NewInt(int64(prestate.Env.Number))) {
250-
if prestate.Env.BaseFee == nil {
251+
if prestate.Env.BaseFee != nil {
252+
// Already set, base fee has precedent over parent base fee.
253+
} else if prestate.Env.ParentBaseFee != nil {
254+
parent := &types.Header{
255+
Number: new(big.Int).SetUint64(prestate.Env.Number),
256+
BaseFee: prestate.Env.ParentBaseFee,
257+
GasUsed: prestate.Env.ParentGasUsed,
258+
GasLimit: prestate.Env.ParentGasLimit,
259+
}
260+
prestate.Env.BaseFee = misc.CalcBaseFee(chainConfig, parent)
261+
} else {
251262
return NewError(ErrorConfig, errors.New("EIP-1559 config but missing 'currentBaseFee' in env section"))
252263
}
253264
}

cmd/evm/t8n_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ func TestT8n(t *testing.T) {
243243
output: t8nOutput{alloc: false, result: false},
244244
expExitCode: 3,
245245
},
246+
{ // Test base fee calculation
247+
base: "./testdata/25",
248+
input: t8nInput{
249+
"alloc.json", "txs.json", "env.json", "Merged", "",
250+
},
251+
output: t8nOutput{alloc: true, result: true},
252+
expOut: "exp.json",
253+
},
246254
} {
247255
args := []string{"t8n"}
248256
args = append(args, tc.output.get()...)

cmd/evm/testdata/25/alloc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
3+
"balance": "0x5ffd4878be161d74",
4+
"code": "0x",
5+
"nonce": "0xac",
6+
"storage": {}
7+
}
8+
}

cmd/evm/testdata/25/env.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b",
3+
"currentDifficulty": null,
4+
"currentRandom": "0xdeadc0de",
5+
"currentGasLimit": "0x750a163df65e8a",
6+
"parentBaseFee": "0x500",
7+
"parentGasUsed": "0x0",
8+
"parentGasLimit": "0x750a163df65e8a",
9+
"currentNumber": "1",
10+
"currentTimestamp": "1000"
11+
}

cmd/evm/testdata/25/exp.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"alloc": {
3+
"0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192": {
4+
"balance": "0x1"
5+
},
6+
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
7+
"balance": "0x5ffd4878bc29ed73",
8+
"nonce": "0xad"
9+
},
10+
"0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
11+
"balance": "0x520800"
12+
}
13+
},
14+
"result": {
15+
"stateRoot": "0x36612be4ad9b2b2894cbf6ede6a7d27da8adaabdbb7f2cfe4d00a2bac72c7bd7",
16+
"txRoot": "0x572690baf4898c2972446e56ecf0aa2a027c08a863927d2dce34472f0c5496fe",
17+
"receiptsRoot": "0x056b23fbba480696b65fe5a59b8f2148a1299103c4f57df839233af2cf4ca2d2",
18+
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
19+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
20+
"receipts": [
21+
{
22+
"root": "0x",
23+
"status": "0x1",
24+
"cumulativeGasUsed": "0x5208",
25+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
26+
"logs": null,
27+
"transactionHash": "0x92ea4a28224d033afb20e0cc2b290d4c7c2d61f6a4800a680e4e19ac962ee941",
28+
"contractAddress": "0x0000000000000000000000000000000000000000",
29+
"gasUsed": "0x5208",
30+
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
31+
"transactionIndex": "0x0"
32+
}
33+
],
34+
"currentDifficulty": null,
35+
"gasUsed": "0x5208"
36+
}
37+
}

cmd/evm/testdata/25/txs.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"gas": "0x186a0",
4+
"gasPrice": "0x600",
5+
"hash": "0x0557bacce3375c98d806609b8d5043072f0b6a8bae45ae5a67a00d3a1a18d673",
6+
"input": "0x",
7+
"nonce": "0xac",
8+
"to": "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192",
9+
"value": "0x1",
10+
"v" : "0x0",
11+
"r" : "0x0",
12+
"s" : "0x0",
13+
"secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
14+
}
15+
]

0 commit comments

Comments
 (0)