From f83aa02f37b55a5ea0cd625a7c107203152adb93 Mon Sep 17 00:00:00 2001 From: jangko Date: Sun, 8 Jan 2023 14:25:35 +0700 Subject: [PATCH] add EOF test case for t8n tool --- nimbus/common/hardforks.nim | 10 +++++++--- tools/t8n/t8n_test.nim | 10 ++++++++++ tools/t8n/testdata/01-501/alloc.json | 14 ++++++++++++++ tools/t8n/testdata/01-501/env.json | 12 ++++++++++++ tools/t8n/testdata/01-501/txs.json | 1 + tools/t8n/transition.nim | 19 +++++++++++++++++-- 6 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 tools/t8n/testdata/01-501/alloc.json create mode 100644 tools/t8n/testdata/01-501/env.json create mode 100644 tools/t8n/testdata/01-501/txs.json diff --git a/nimbus/common/hardforks.nim b/nimbus/common/hardforks.nim index c81e560ead..38dddd82b2 100644 --- a/nimbus/common/hardforks.nim +++ b/nimbus/common/hardforks.nim @@ -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 diff --git a/tools/t8n/t8n_test.nim b/tools/t8n/t8n_test.nim index 4a86f57018..f3ceb3d5e7 100644 --- a/tools/t8n/t8n_test.nim +++ b/tools/t8n/t8n_test.nim @@ -498,6 +498,7 @@ const expOut: "exp.json", ), TestSpec( +<<<<<<< HEAD name : "EVM tracer nil stack crash bug", base : "testdata/00-519", input : t8nInput( @@ -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() = diff --git a/tools/t8n/testdata/01-501/alloc.json b/tools/t8n/testdata/01-501/alloc.json new file mode 100644 index 0000000000..43024b43d7 --- /dev/null +++ b/tools/t8n/testdata/01-501/alloc.json @@ -0,0 +1,14 @@ +{ + "a94f5374fce5edbc8e2a8697c15331677e6ebf0b": { + "balance": "0x0", + "code": "0xef01", + "nonce": "0x1", + "storage": {} + }, + "a94f5374fce5edbc8e2a8697c15331677e6ebf0c": { + "balance": "0x0", + "code": "0xef0001010008020002000700020300000000000002020100025959b0000250b101b1", + "nonce": "0x1", + "storage": {} + } +} diff --git a/tools/t8n/testdata/01-501/env.json b/tools/t8n/testdata/01-501/env.json new file mode 100644 index 0000000000..05d8ffaaae --- /dev/null +++ b/tools/t8n/testdata/01-501/env.json @@ -0,0 +1,12 @@ +{ + "currentCoinbase": "0xc94f5374fce5edbc8e2a8697c15331677e6ebf0b", + "currentDifficulty": null, + "currentRandom": "0xdeadc0de", + "currentGasLimit": "0x750a163df65e8a", + "parentBaseFee": "0x500", + "parentGasUsed": "0x0", + "parentGasLimit": "0x750a163df65e8a", + "currentNumber": "1", + "currentTimestamp": "1000", + "withdrawals": [] +} diff --git a/tools/t8n/testdata/01-501/txs.json b/tools/t8n/testdata/01-501/txs.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/tools/t8n/testdata/01-501/txs.json @@ -0,0 +1 @@ +[] diff --git a/tools/t8n/transition.nim b/tools/t8n/transition.nim index 2585a4bb25..d9172cd46a 100644 --- a/tools/t8n/transition.nim +++ b/tools/t8n/transition.nim @@ -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], @@ -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")