Skip to content

Commit d11836f

Browse files
holimanjagdeep sidhu
authored andcommitted
cmd/evm: make evm t8n handle post-merge transitions (ethereum#24546)
This adds the ability to run --state.fork=Merged, and have post-merge rules apply. When doing so, it also requires the input env to contain currentRandom, and enforces the currentDifficulty to be omitted or zero.
1 parent 7106b00 commit d11836f

File tree

9 files changed

+162
-6
lines changed

9 files changed

+162
-6
lines changed

cmd/evm/internal/t8ntool/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ var (
152152
"\n\tSyntax <forkname>(+ExtraEip)",
153153
strings.Join(tests.AvailableForks(), "\n\t "),
154154
strings.Join(vm.ActivateableEips(), ", ")),
155-
Value: "Istanbul",
155+
Value: "ArrowGlacier",
156156
}
157157
VerbosityFlag = cli.IntFlag{
158158
Name: "verbosity",

cmd/evm/internal/t8ntool/transition.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,21 @@ func Transition(ctx *cli.Context) error {
252252
return NewError(ErrorConfig, errors.New("EIP-1559 config but missing 'currentBaseFee' in env section"))
253253
}
254254
}
255-
// Sanity check, to not `panic` in state_transition
256-
if prestate.Env.Random != nil && !chainConfig.IsLondon(big.NewInt(int64(prestate.Env.Number))) {
257-
return NewError(ErrorConfig, errors.New("can only apply RANDOM on top of London chainrules"))
258-
}
259-
if env := prestate.Env; env.Difficulty == nil {
255+
isMerged := chainConfig.TerminalTotalDifficulty != nil && chainConfig.TerminalTotalDifficulty.BitLen() == 0
256+
env := prestate.Env
257+
if isMerged {
258+
// post-merge:
259+
// - random must be supplied
260+
// - difficulty must be zero
261+
switch {
262+
case env.Random == nil:
263+
return NewError(ErrorConfig, errors.New("post-merge requires currentRandom to be defined in env"))
264+
case env.Difficulty != nil && env.Difficulty.BitLen() != 0:
265+
return NewError(ErrorConfig, errors.New("post-merge difficulty must be zero (or omitted) in env"))
266+
}
267+
prestate.Env.Difficulty = nil
268+
} else if env.Difficulty == nil {
269+
// pre-merge:
260270
// If difficulty was not provided by caller, we need to calculate it.
261271
switch {
262272
case env.ParentDifficulty == nil:

cmd/evm/t8n_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,22 @@ func TestT8n(t *testing.T) {
203203
output: t8nOutput{result: true},
204204
expOut: "exp.json",
205205
},
206+
{ // Test post-merge transition
207+
base: "./testdata/24",
208+
input: t8nInput{
209+
"alloc.json", "txs.json", "env.json", "Merged", "",
210+
},
211+
output: t8nOutput{alloc: true, result: true},
212+
expOut: "exp.json",
213+
},
214+
{ // Test post-merge transition where input is missing random
215+
base: "./testdata/24",
216+
input: t8nInput{
217+
"alloc.json", "txs.json", "env-missingrandom.json", "Merged", "",
218+
},
219+
output: t8nOutput{alloc: false, result: false},
220+
expExitCode: 3,
221+
},
206222
} {
207223

208224
args := []string{"t8n"}

cmd/evm/testdata/24/alloc.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
3+
"balance": "0x5ffd4878be161d74",
4+
"code": "0x",
5+
"nonce": "0xac",
6+
"storage": {}
7+
},
8+
"0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192":{
9+
"balance": "0xfeedbead",
10+
"nonce" : "0x00",
11+
"code" : "0x44600055",
12+
"_comment": "The code is 'sstore(0, random)'"
13+
}
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b",
3+
"currentDifficulty": null,
4+
"currentRandom": null,
5+
"currentGasLimit": "0x750a163df65e8a",
6+
"currentBaseFee": "0x500",
7+
"currentNumber": "1",
8+
"currentTimestamp": "1000"
9+
}

cmd/evm/testdata/24/env.json

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

cmd/evm/testdata/24/exp.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"alloc": {
3+
"0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192": {
4+
"code": "0x44600055",
5+
"storage": {
6+
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x00000000000000000000000000000000000000000000000000000000deadc0de"
7+
},
8+
"balance": "0xfeedbeaf"
9+
},
10+
"0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
11+
"balance": "0x5ffd4878b803f972",
12+
"nonce": "0xae"
13+
},
14+
"0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
15+
"balance": "0x1030600"
16+
}
17+
},
18+
"result": {
19+
"stateRoot": "0x9e4224c6bba343d5b0fdbe9200cc66a7ef2068240d901ae516e634c45a043c15",
20+
"txRoot": "0x16cd3a7daa6686ceebadf53b7af2bc6919eccb730907f0e74a95a4423c209593",
21+
"receiptsRoot": "0x22b85cda738345a9880260b2a71e144aab1ca9485f5db4fd251008350fc124c8",
22+
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
23+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
24+
"receipts": [
25+
{
26+
"root": "0x",
27+
"status": "0x1",
28+
"cumulativeGasUsed": "0xa861",
29+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
30+
"logs": null,
31+
"transactionHash": "0x92ea4a28224d033afb20e0cc2b290d4c7c2d61f6a4800a680e4e19ac962ee941",
32+
"contractAddress": "0x0000000000000000000000000000000000000000",
33+
"gasUsed": "0xa861",
34+
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
35+
"transactionIndex": "0x0"
36+
},
37+
{
38+
"root": "0x",
39+
"status": "0x1",
40+
"cumulativeGasUsed": "0x10306",
41+
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
42+
"logs": null,
43+
"transactionHash": "0x16b1d912f1d664f3f60f4e1b5f296f3c82a64a1a253117b4851d18bc03c4f1da",
44+
"contractAddress": "0x0000000000000000000000000000000000000000",
45+
"gasUsed": "0x5aa5",
46+
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
47+
"transactionIndex": "0x1"
48+
}
49+
],
50+
"currentDifficulty": null,
51+
"gasUsed": "0x10306"
52+
}
53+
}

cmd/evm/testdata/24/txs.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
{
16+
"gas": "0x186a0",
17+
"gasPrice": "0x600",
18+
"hash": "0x0557bacce3375c98d806609b8d5043072f0b6a8bae45ae5a67a00d3a1a18d673",
19+
"input": "0x",
20+
"nonce": "0xad",
21+
"to": "0x8a8eafb1cf62bfbeb1741769dae1a9dd47996192",
22+
"value": "0x1",
23+
"v" : "0x0",
24+
"r" : "0x0",
25+
"s" : "0x0",
26+
"secretKey" : "0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
27+
}
28+
]

tests/init.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,23 @@ var Forks = map[string]*params.ChainConfig{
197197
LondonBlock: big.NewInt(0),
198198
ArrowGlacierBlock: big.NewInt(0),
199199
},
200+
"Merged": {
201+
ChainID: big.NewInt(1),
202+
HomesteadBlock: big.NewInt(0),
203+
EIP150Block: big.NewInt(0),
204+
EIP155Block: big.NewInt(0),
205+
EIP158Block: big.NewInt(0),
206+
ByzantiumBlock: big.NewInt(0),
207+
ConstantinopleBlock: big.NewInt(0),
208+
PetersburgBlock: big.NewInt(0),
209+
IstanbulBlock: big.NewInt(0),
210+
MuirGlacierBlock: big.NewInt(0),
211+
BerlinBlock: big.NewInt(0),
212+
LondonBlock: big.NewInt(0),
213+
ArrowGlacierBlock: big.NewInt(0),
214+
MergeForkBlock: big.NewInt(0),
215+
TerminalTotalDifficulty: big.NewInt(0),
216+
},
200217
}
201218

202219
// Returns the set of defined fork names

0 commit comments

Comments
 (0)