From 343779415fae4256fe79dae47cfe4b622d68194f Mon Sep 17 00:00:00 2001 From: jangko Date: Tue, 25 Jul 2023 09:59:01 +0700 Subject: [PATCH] EOF suite: rebase master branch --- nimbus/db/accounts_cache.nim | 8 +++--- nimbus/evm/code_stream.nim | 2 +- .../interpreter/op_handlers/oph_envinfo.nim | 2 +- nimbus/evm/interpreter_dispatch.nim | 8 +++--- nimbus/evm/stack_table.nim | 26 ++++++++++++++++--- tests/customgenesis/eof.json | 4 +-- tests/test_eof.nim | 14 ++++++---- tools/t8n/t8n_test.nim | 1 - 8 files changed, 43 insertions(+), 22 deletions(-) diff --git a/nimbus/db/accounts_cache.nim b/nimbus/db/accounts_cache.nim index 49eda117a..5219aadca 100644 --- a/nimbus/db/accounts_cache.nim +++ b/nimbus/db/accounts_cache.nim @@ -11,10 +11,8 @@ import std/[tables, hashes, sets], eth/[common, rlp], - ../constants, ../utils/[utils, eof], storage_types, + ../constants, ../utils/[utils, eof], ../../stateless/multi_keys, - ../constants, - ../utils/utils, ./access_list as ac_access_list, "."/[core_db, distinct_tries, storage_types, transient_storage] @@ -382,9 +380,9 @@ proc loadCode(acc: RefAccount, ac: AccountsCache) = return when defined(geth): - let data = ac.db.get(acc.account.codeHash.data) + let data = ac.kvt.get(acc.account.codeHash.data) else: - let data = ac.db.get(contractHashKey(acc.account.codeHash).toOpenArray) + let data = ac.kvt.get(contractHashKey(acc.account.codeHash).toOpenArray) acc.code = data acc.flags.incl CodeLoaded diff --git a/nimbus/evm/code_stream.nim b/nimbus/evm/code_stream.nim index 5def70be7..cd0bcbd9d 100644 --- a/nimbus/evm/code_stream.nim +++ b/nimbus/evm/code_stream.nim @@ -10,7 +10,7 @@ import chronicles, eth/common, stew/[results, endians2], - stew/ranges/ptr_arith, + stew/ptrops, ../utils/eof, ./interpreter/op_codes diff --git a/nimbus/evm/interpreter/op_handlers/oph_envinfo.nim b/nimbus/evm/interpreter/op_handlers/oph_envinfo.nim index e5cd95c8c..6921536cd 100644 --- a/nimbus/evm/interpreter/op_handlers/oph_envinfo.nim +++ b/nimbus/evm/interpreter/op_handlers/oph_envinfo.nim @@ -145,7 +145,7 @@ const cpt.gasCosts[CodeCopy].m_handler(cpt.memory.len, memPos, len), reason = "CodeCopy fee") - cpt.memory.writePadded(k.cpt.code.legacyCode, memPos, copyPos, len) + cpt.memory.writePadded(cpt.code.legacyCode, memPos, copyPos, len) gasPriceOp: Vm2OpFn = proc (k: var Vm2Ctx) = diff --git a/nimbus/evm/interpreter_dispatch.nim b/nimbus/evm/interpreter_dispatch.nim index 30e160548..c8d0a6063 100644 --- a/nimbus/evm/interpreter_dispatch.nim +++ b/nimbus/evm/interpreter_dispatch.nim @@ -14,12 +14,11 @@ const lowMemoryCompileTime {.used.} = lowmem > 0 import - std/[macros, sets, strformat], - pkg/[chronicles, chronos, stew/byteutils], + std/[macros, strformat], ".."/[constants, db/accounts_cache], "."/[code_stream, computation, validate], "."/[message, precompiles, state, types], - ../utils/[utils, eof], + ../utils/eof, ./interpreter/[op_dispatcher, gas_costs], pkg/[chronicles, chronos, eth/keys, stew/byteutils] @@ -366,6 +365,9 @@ else: # to write the async version of the iterative one, but this one is # a bit shorter and feels cleaner, so if it works just as well I'd # rather use this one. --Adam +import + async/operations + proc asyncExecCallOrCreate*(c: Computation): Future[void] {.async.} = defer: c.dispose() diff --git a/nimbus/evm/stack_table.nim b/nimbus/evm/stack_table.nim index 8b73221bb..bf7a56ebf 100644 --- a/nimbus/evm/stack_table.nim +++ b/nimbus/evm/stack_table.nim @@ -187,21 +187,39 @@ proc mergeStackTable(): StackTable {.compileTime.} = result = londonStackTable() result[PrevRandao] = sp(0, 1) -proc cancunStackTable(): StackTable {.compileTime.} = +proc shanghaiStackTable(): StackTable {.compileTime.} = result = mergeStackTable() + # new opcodes EIP-3855 + result[Push0] = sp(0, 1) + +proc cancunStackTable(): StackTable {.compileTime.} = + result = shanghaiStackTable() + # new opcodes EIP-4844 + result[BlobHash] = sp(1, 1) + + # new opcodes EIP-1153 + result[TLoad] = sp(1, 1) + result[TStore] = sp(2, 0) + + # new opcodes EIP-5656 + result[Mcopy] = sp(3, 0) + # new opcodes EIP-4200 result[Rjump] = sp(0, 0) result[RJumpI] = sp(1, 0) result[RJumpV] = sp(1, 0) + # new opcodes EIP-4750 result[CallF] = sp(0, 0) result[RetF] = sp(0, 0) - # new opcodes EIP-3855 - result[Push0] = sp(0, 1) + + # new opcodes EIP-7516 + result[BlobBaseFee] = sp(1, 1) # disable opcodes EIP-3670 result[CallCode] = StackDesc() result[SelfDestruct] = StackDesc() + # disable opcodes EIP-5450 result[Jump] = StackDesc() result[JumpI] = StackDesc() @@ -220,6 +238,6 @@ const istanbulStackTable(), londonStackTable(), mergeStackTable(), - mergeStackTable(), + shanghaiStackTable(), cancunStackTable(), ] diff --git a/tests/customgenesis/eof.json b/tests/customgenesis/eof.json index 29257bd5d..4922273ed 100644 --- a/tests/customgenesis/eof.json +++ b/tests/customgenesis/eof.json @@ -14,8 +14,8 @@ "berlinBlock": 0, "londonBlock": 0, "mergeForkBlock": 0, - "shanghaiBlock": 0, - "cancunBlock": 0, + "shanghaiTime": 0, + "cancunTime": 0, "terminalTotalDifficulty": 0 }, "genesis": { diff --git a/tests/test_eof.nim b/tests/test_eof.nim index 6f278ca6f..cfcf95b04 100644 --- a/tests/test_eof.nim +++ b/tests/test_eof.nim @@ -1,5 +1,5 @@ import - std/[tables, math, times], + std/[tables, math], eth/[keys], stew/byteutils, unittest2, @@ -230,7 +230,7 @@ proc initEnv(): TestEnv = let com = CommonRef.new( - newMemoryDb(), + newCoreDbRef LegacyDbMemory, conf.pruneMode == PruneMode.Full, conf.networkId, conf.networkParams @@ -278,6 +278,9 @@ proc eofMain*() = txs.add env.makeTx(some(cc), 0.u256, initCode) suite "Test EOF code deployment": + test "is EOF fork?": + check com.forkGTE(EOFFork) + test "add txs to txpool": for tx in txs: let res = xp.addLocal(tx, force = true) @@ -292,14 +295,15 @@ proc eofMain*() = test "generate POS block": com.pos.prevRandao = prevRandao com.pos.feeRecipient = aa - com.pos.timestamp = getTime() + com.pos.timestamp = EthTime.now() let blk = xp.ethBlock() check com.isBlockAfterTtd(blk.header) let body = BlockBody( transactions: blk.txs, - uncles: blk.uncles + uncles: blk.uncles, + withdrawals: some[seq[Withdrawal]](@[]) ) check blk.txs.len == 4 @@ -311,7 +315,7 @@ proc eofMain*() = test "check flags and various deployment mechanisms": var state = AccountsCache.init( - com.db.db, + com.db, stateRoot, com.pruneTrie) diff --git a/tools/t8n/t8n_test.nim b/tools/t8n/t8n_test.nim index f3ceb3d5e..04e3ebd13 100644 --- a/tools/t8n/t8n_test.nim +++ b/tools/t8n/t8n_test.nim @@ -498,7 +498,6 @@ const expOut: "exp.json", ), TestSpec( -<<<<<<< HEAD name : "EVM tracer nil stack crash bug", base : "testdata/00-519", input : t8nInput(