Skip to content

Commit b339288

Browse files
committed
add EOF test case for t8n tool
1 parent 3da8861 commit b339288

File tree

7 files changed

+61
-8
lines changed

7 files changed

+61
-8
lines changed

nimbus/common/hardforks.nim

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ type
4949
Shanghai
5050
Cancun
5151

52-
const lastPurelyBlockNumberBasedFork* = GrayGlacier
53-
# MergeFork is special because of TTD.
54-
const firstTimeBasedFork* = Shanghai
52+
const
53+
lastPurelyBlockNumberBasedFork* = GrayGlacier
54+
55+
# MergeFork is special because of TTD.
56+
firstTimeBasedFork* = Shanghai
5557

58+
# Meta Fork
59+
EOFFork* = Cancun
5660

5761
type
5862
CliqueOptions* = object
@@ -258,7 +262,7 @@ proc populateFromForkTransitionTable*(conf: ChainConfig, t: ForkTransitionTable)
258262

259263
conf.mergeForkBlock = t.mergeForkTransitionThreshold.blockNumber
260264
conf.terminalTotalDifficulty = t.mergeForkTransitionThreshold.ttd
261-
265+
262266
conf.shanghaiTime = t.timeThresholds[HardFork.Shanghai]
263267
conf.cancunTime = t.timeThresholds[HardFork.Cancun]
264268

tools/t8n/t8n_test.nim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,15 @@ const
484484
output: T8nOutput(alloc: true, result: true),
485485
expOut: "exp.json",
486486
),
487+
TestSpec(
488+
name: "Validate pre-allocated EOF code",
489+
base: "testdata/28",
490+
input: t8nInput(
491+
"alloc.json", "txs.json", "env.json", "Cancun", "",
492+
),
493+
output: T8nOutput(alloc: true, result: false),
494+
expExitCode: 3,
495+
),
487496
]
488497

489498
proc main() =

tools/t8n/testdata/26/alloc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
"nonce": "0xac",
66
"storage": {}
77
}
8-
}
8+
}

tools/t8n/testdata/28/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": "0x0",
4+
"code": "0xef01",
5+
"nonce": "0x1",
6+
"storage": {}
7+
},
8+
"a94f5374fce5edbc8e2a8697c15331677e6ebf0c": {
9+
"balance": "0x0",
10+
"code": "0xef0001010008020002000700020300000000000002020100025959b0000250b101b1",
11+
"nonce": "0x1",
12+
"storage": {}
13+
}
14+
}

tools/t8n/testdata/28/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+
}

tools/t8n/testdata/28/txs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

tools/t8n/transition.nim

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
import
1212
std/[json, strutils, times, tables, os, math, streams],
1313
eth/[rlp, trie, eip1559],
14-
stint, stew/results,
14+
stint, stew/[results, byteutils],
1515
"."/[config, types, helpers],
1616
../common/state_clearing,
1717
../../nimbus/[vm_types, vm_state, transaction],
1818
../../nimbus/common/common,
1919
../../nimbus/db/accounts_cache,
20-
../../nimbus/utils/utils,
20+
../../nimbus/evm/validate,
21+
../../nimbus/utils/[utils, eof],
2122
../../nimbus/core/pow/difficulty,
2223
../../nimbus/core/dao,
2324
../../nimbus/core/executor/[process_transaction, executor_helpers],
2425
../../nimbus/core/eip4844,
2526
../../nimbus/evm/tracer/json_tracer
2627

27-
import stew/byteutils
2828
const
2929
wrapExceptionEnabled* {.booldefine.} = true
3030
stdinSelector = "stdin"
@@ -424,6 +424,20 @@ proc transitionAction*(ctx: var TransContext, conf: T8NConf) =
424424
else:
425425
raise newError(ErrorConfig, "EIP-1559 config but missing 'currentBaseFee' in env section")
426426
427+
if com.forkGTE(EOFFork):
428+
for address, acc in ctx.alloc:
429+
if not hasEOFByte(acc.code):
430+
continue
431+
432+
var c: Container
433+
var res = c.decode(acc.code)
434+
if res.isOk:
435+
res = c.validateCode()
436+
437+
if res.isErr:
438+
raise newError(ErrorConfig, "code at $1 considered invalid: $2" %
439+
[address.toHex, res.error.toString])
440+
427441
if com.isShanghaiOrLater(ctx.env.currentTimestamp) and ctx.env.withdrawals.isNone:
428442
raise newError(ErrorConfig, "Shanghai config but missing 'withdrawals' in env section")
429443

0 commit comments

Comments
 (0)