Skip to content

Commit

Permalink
add EOF test case for t8n tool
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Oct 31, 2023
1 parent d0a2c5f commit f83aa02
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
10 changes: 7 additions & 3 deletions nimbus/common/hardforks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ type
Shanghai
Cancun

const lastPurelyBlockNumberBasedFork* = GrayGlacier
# MergeFork is special because of TTD.
const firstTimeBasedFork* = Shanghai
const
lastPurelyBlockNumberBasedFork* = GrayGlacier

# MergeFork is special because of TTD.
firstTimeBasedFork* = Shanghai

# Meta Fork
EOFFork* = Cancun

type
CliqueOptions* = object
Expand Down
10 changes: 10 additions & 0 deletions tools/t8n/t8n_test.nim
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ const
expOut: "exp.json",
),
TestSpec(
<<<<<<< HEAD
name : "EVM tracer nil stack crash bug",
base : "testdata/00-519",
input : t8nInput(
Expand Down Expand Up @@ -569,6 +570,15 @@ const
output: T8nOutput(trace: true, result: true),
expOut: "istanbul.txt",
),
TestSpec(
name: "Validate pre-allocated EOF code",
base: "testdata/01-501",
input: t8nInput(
"alloc.json", "txs.json", "env.json", "Cancun", "",
),
output: T8nOutput(alloc: true, result: false),
expExitCode: 3,
),
]

proc main() =
Expand Down
14 changes: 14 additions & 0 deletions tools/t8n/testdata/01-501/alloc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
"balance": "0x0",
"code": "0xef01",
"nonce": "0x1",
"storage": {}
},
"a94f5374fce5edbc8e2a8697c15331677e6ebf0c": {
"balance": "0x0",
"code": "0xef0001010008020002000700020300000000000002020100025959b0000250b101b1",
"nonce": "0x1",
"storage": {}
}
}
12 changes: 12 additions & 0 deletions tools/t8n/testdata/01-501/env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"currentDifficulty": null,
"currentRandom": "0xdeadc0de",
"currentGasLimit": "0x750a163df65e8a",
"parentBaseFee": "0x500",
"parentGasUsed": "0x0",
"parentGasLimit": "0x750a163df65e8a",
"currentNumber": "1",
"currentTimestamp": "1000",
"withdrawals": []
}
1 change: 1 addition & 0 deletions tools/t8n/testdata/01-501/txs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
19 changes: 17 additions & 2 deletions tools/t8n/transition.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
import
std/[json, strutils, tables, os, streams],
eth/[rlp, trie, eip1559],
stint, stew/results,
stint, stew/[results, byteutils],
"."/[config, types, helpers],
../common/state_clearing,
../../nimbus/[vm_types, vm_state, transaction],
../../nimbus/common/common,
../../nimbus/db/accounts_cache,
../../nimbus/utils/utils,
../../nimbus/evm/validate,
../../nimbus/utils/[utils, eof],
../../nimbus/core/pow/difficulty,
../../nimbus/core/dao,
../../nimbus/core/executor/[process_transaction, executor_helpers],
Expand Down Expand Up @@ -429,6 +430,20 @@ proc transitionAction*(ctx: var TransContext, conf: T8NConf) =
else:
raise newError(ErrorConfig, "EIP-1559 config but missing 'currentBaseFee' in env section")

if com.forkGTE(EOFFork):
for address, acc in ctx.alloc:
if not hasEOFByte(acc.code):
continue

var c: Container
var res = c.decode(acc.code)
if res.isOk:
res = c.validateCode()

if res.isErr:
raise newError(ErrorConfig, "code at $1 considered invalid: $2" %
[address.toHex, res.error.toString])

if com.isShanghaiOrLater(ctx.env.currentTimestamp) and ctx.env.withdrawals.isNone:
raise newError(ErrorConfig, "Shanghai config but missing 'withdrawals' in env section")

Expand Down

0 comments on commit f83aa02

Please sign in to comment.