Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add EOF test case for t8n tool
Browse files Browse the repository at this point in the history
jangko committed Jan 14, 2023
1 parent 15e8fbf commit e35a6ee
Showing 5 changed files with 54 additions and 4 deletions.
11 changes: 10 additions & 1 deletion tools/t8n/t8n_test.nim
Original file line number Diff line number Diff line change
@@ -403,7 +403,16 @@ const
),
output: T8nOutput(alloc: true, result: true),
expOut: "exp.json",
)
),
TestSpec(
name: "Validate pre-allocated EOF code",
base: "testdata/26",
input: t8nInput(
"alloc.json", "txs.json", "env.json", "Cancun", "",
),
output: T8nOutput(alloc: true, result: false),
expExitCode: 3,
),
]

proc main() =
14 changes: 14 additions & 0 deletions tools/t8n/testdata/26/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": {}
}
}
11 changes: 11 additions & 0 deletions tools/t8n/testdata/26/env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b",
"currentDifficulty": null,
"currentRandom": "0xdeadc0de",
"currentGasLimit": "0x750a163df65e8a",
"parentBaseFee": "0x500",
"parentGasUsed": "0x0",
"parentGasLimit": "0x750a163df65e8a",
"currentNumber": "1",
"currentTimestamp": "1000"
}
1 change: 1 addition & 0 deletions tools/t8n/testdata/26/txs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
21 changes: 18 additions & 3 deletions tools/t8n/transition.nim
Original file line number Diff line number Diff line change
@@ -11,18 +11,18 @@
import
std/[json, strutils, times, tables, os, sets],
eth/[rlp, trie, eip1559],
stint, chronicles, stew/results,
stint, chronicles, 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]

import stew/byteutils
const
wrapExceptionEnabled* {.booldefine.} = true
stdinSelector = "stdin"
@@ -372,6 +372,21 @@ proc transitionAction*(ctx: var TransContext, conf: T8NConf) =
else:
raise newError(ErrorConfig, "EIP-1559 config but missing 'currentBaseFee' in env section")

# Sanity check pre-allocated EOF code to not panic in state transition.
if com.forkGTE(HardFork.Cancun):
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.forkGTE(MergeFork):
if ctx.env.currentRandom.isNone:
raise newError(ErrorConfig, "post-merge requires currentRandom to be defined in env")

0 comments on commit e35a6ee

Please sign in to comment.