Skip to content

Commit fbdeff9

Browse files
lightclientholiman
andauthored
cmd/evm: calc base fee if parent data is present (#26051)
Currently, in order to chain together sequential valid t8n transitions the caller must manually calculate the block base fee. This PR adds support for the necessary parent fee market data to calculate the base fee for the current transition. Concretely, env is extended to accept the following: parentBaseFee parentGasUsed parentGasLimit Example usage can be found in ./cmd/evm/testdata/25. Co-authored-by: Martin Holst Swende <[email protected]>
1 parent 60e30a9 commit fbdeff9

File tree

16 files changed

+134
-9
lines changed

16 files changed

+134
-9
lines changed

cmd/evm/internal/t8ntool/execution.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type ExecutionResult struct {
5656
Rejected []*rejectedTx `json:"rejected,omitempty"`
5757
Difficulty *math.HexOrDecimal256 `json:"currentDifficulty" gencodec:"required"`
5858
GasUsed math.HexOrDecimal64 `json:"gasUsed"`
59+
BaseFee *math.HexOrDecimal256 `json:"currentBaseFee,omitempty"`
5960
}
6061

6162
type ommer struct {
@@ -69,6 +70,9 @@ type stEnv struct {
6970
Difficulty *big.Int `json:"currentDifficulty"`
7071
Random *big.Int `json:"currentRandom"`
7172
ParentDifficulty *big.Int `json:"parentDifficulty"`
73+
ParentBaseFee *big.Int `json:"parentBaseFee,omitempty"`
74+
ParentGasUsed uint64 `json:"parentGasUsed,omitempty"`
75+
ParentGasLimit uint64 `json:"parentGasLimit,omitempty"`
7276
GasLimit uint64 `json:"currentGasLimit" gencodec:"required"`
7377
Number uint64 `json:"currentNumber" gencodec:"required"`
7478
Timestamp uint64 `json:"currentTimestamp" gencodec:"required"`
@@ -84,6 +88,9 @@ type stEnvMarshaling struct {
8488
Difficulty *math.HexOrDecimal256
8589
Random *math.HexOrDecimal256
8690
ParentDifficulty *math.HexOrDecimal256
91+
ParentBaseFee *math.HexOrDecimal256
92+
ParentGasUsed math.HexOrDecimal64
93+
ParentGasLimit math.HexOrDecimal64
8794
GasLimit math.HexOrDecimal64
8895
Number math.HexOrDecimal64
8996
Timestamp math.HexOrDecimal64
@@ -263,6 +270,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
263270
Rejected: rejectedTxs,
264271
Difficulty: (*math.HexOrDecimal256)(vmContext.Difficulty),
265272
GasUsed: (math.HexOrDecimal64)(gasUsed),
273+
BaseFee: (*math.HexOrDecimal256)(vmContext.BaseFee),
266274
}
267275
return statedb, execRs, nil
268276
}

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/13/exp2.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
}
3535
],
3636
"currentDifficulty": "0x20000",
37-
"gasUsed": "0x109a0"
37+
"gasUsed": "0x109a0",
38+
"currentBaseFee": "0x36b"
3839
}
3940
}

cmd/evm/testdata/14/exp.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
88
"currentDifficulty": "0x2000020000000",
99
"receipts": [],
10-
"gasUsed": "0x0"
10+
"gasUsed": "0x0",
11+
"currentBaseFee": "0x500"
1112
}
1213
}

cmd/evm/testdata/14/exp2.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
88
"receipts": [],
99
"currentDifficulty": "0x1ff8020000000",
10-
"gasUsed": "0x0"
10+
"gasUsed": "0x0",
11+
"currentBaseFee": "0x500"
1112
}
1213
}

cmd/evm/testdata/14/exp_berlin.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
88
"receipts": [],
99
"currentDifficulty": "0x1ff9000000000",
10-
"gasUsed": "0x0"
10+
"gasUsed": "0x0",
11+
"currentBaseFee": "0x500"
1112
}
1213
}

cmd/evm/testdata/19/exp_arrowglacier.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
88
"currentDifficulty": "0x2000000200000",
99
"receipts": [],
10-
"gasUsed": "0x0"
10+
"gasUsed": "0x0",
11+
"currentBaseFee": "0x500"
1112
}
1213
}

cmd/evm/testdata/19/exp_grayglacier.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
88
"receipts": [],
99
"currentDifficulty": "0x2000000004000",
10-
"gasUsed": "0x0"
10+
"gasUsed": "0x0",
11+
"currentBaseFee": "0x500"
1112
}
1213
}

0 commit comments

Comments
 (0)