Skip to content

Commit e35a6ee

Browse files
committed
add EOF test case for t8n tool
1 parent 15e8fbf commit e35a6ee

File tree

5 files changed

+54
-4
lines changed

5 files changed

+54
-4
lines changed

tools/t8n/t8n_test.nim

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,16 @@ const
403403
),
404404
output: T8nOutput(alloc: true, result: true),
405405
expOut: "exp.json",
406-
)
406+
),
407+
TestSpec(
408+
name: "Validate pre-allocated EOF code",
409+
base: "testdata/26",
410+
input: t8nInput(
411+
"alloc.json", "txs.json", "env.json", "Cancun", "",
412+
),
413+
output: T8nOutput(alloc: true, result: false),
414+
expExitCode: 3,
415+
),
407416
]
408417

409418
proc main() =

tools/t8n/testdata/26/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/26/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/26/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: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
import
1212
std/[json, strutils, times, tables, os, sets],
1313
eth/[rlp, trie, eip1559],
14-
stint, chronicles, stew/results,
14+
stint, chronicles, 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

25-
import stew/byteutils
2626
const
2727
wrapExceptionEnabled* {.booldefine.} = true
2828
stdinSelector = "stdin"
@@ -372,6 +372,21 @@ proc transitionAction*(ctx: var TransContext, conf: T8NConf) =
372372
else:
373373
raise newError(ErrorConfig, "EIP-1559 config but missing 'currentBaseFee' in env section")
374374
375+
# Sanity check pre-allocated EOF code to not panic in state transition.
376+
if com.forkGTE(HardFork.Cancun):
377+
for address, acc in ctx.alloc:
378+
if not hasEOFByte(acc.code):
379+
continue
380+
381+
var c: Container
382+
var res = c.decode(acc.code)
383+
if res.isOk:
384+
res = c.validateCode()
385+
386+
if res.isErr:
387+
raise newError(ErrorConfig, "code at $1 considered invalid: $2" %
388+
[address.toHex, res.error.toString])
389+
375390
if com.forkGTE(MergeFork):
376391
if ctx.env.currentRandom.isNone:
377392
raise newError(ErrorConfig, "post-merge requires currentRandom to be defined in env")

0 commit comments

Comments
 (0)