Skip to content

Commit f83aa02

Browse files
committed
add EOF test case for t8n tool
1 parent d0a2c5f commit f83aa02

File tree

6 files changed

+61
-5
lines changed

6 files changed

+61
-5
lines changed

nimbus/common/hardforks.nim

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ type
5050
Shanghai
5151
Cancun
5252

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

59+
# Meta Fork
60+
EOFFork* = Cancun
5761

5862
type
5963
CliqueOptions* = object

tools/t8n/t8n_test.nim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ const
498498
expOut: "exp.json",
499499
),
500500
TestSpec(
501+
<<<<<<< HEAD
501502
name : "EVM tracer nil stack crash bug",
502503
base : "testdata/00-519",
503504
input : t8nInput(
@@ -569,6 +570,15 @@ const
569570
output: T8nOutput(trace: true, result: true),
570571
expOut: "istanbul.txt",
571572
),
573+
TestSpec(
574+
name: "Validate pre-allocated EOF code",
575+
base: "testdata/01-501",
576+
input: t8nInput(
577+
"alloc.json", "txs.json", "env.json", "Cancun", "",
578+
),
579+
output: T8nOutput(alloc: true, result: false),
580+
expExitCode: 3,
581+
),
572582
]
573583

574584
proc main() =

tools/t8n/testdata/01-501/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/01-501/env.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
"withdrawals": []
12+
}

tools/t8n/testdata/01-501/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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
import
1212
std/[json, strutils, tables, os, 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],
@@ -429,6 +430,20 @@ proc transitionAction*(ctx: var TransContext, conf: T8NConf) =
429430
else:
430431
raise newError(ErrorConfig, "EIP-1559 config but missing 'currentBaseFee' in env section")
431432
433+
if com.forkGTE(EOFFork):
434+
for address, acc in ctx.alloc:
435+
if not hasEOFByte(acc.code):
436+
continue
437+
438+
var c: Container
439+
var res = c.decode(acc.code)
440+
if res.isOk:
441+
res = c.validateCode()
442+
443+
if res.isErr:
444+
raise newError(ErrorConfig, "code at $1 considered invalid: $2" %
445+
[address.toHex, res.error.toString])
446+
432447
if com.isShanghaiOrLater(ctx.env.currentTimestamp) and ctx.env.withdrawals.isNone:
433448
raise newError(ErrorConfig, "Shanghai config but missing 'withdrawals' in env section")
434449

0 commit comments

Comments
 (0)