Skip to content

Commit

Permalink
EOF suite: rebase master branch
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Oct 31, 2023
1 parent 1720af4 commit 3437794
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 22 deletions.
8 changes: 3 additions & 5 deletions nimbus/db/accounts_cache.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion nimbus/evm/code_stream.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import
chronicles,
eth/common,
stew/[results, endians2],
stew/ranges/ptr_arith,
stew/ptrops,
../utils/eof,
./interpreter/op_codes

Expand Down
2 changes: 1 addition & 1 deletion nimbus/evm/interpreter/op_handlers/oph_envinfo.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down
8 changes: 5 additions & 3 deletions nimbus/evm/interpreter_dispatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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()

Expand Down
26 changes: 22 additions & 4 deletions nimbus/evm/stack_table.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -220,6 +238,6 @@ const
istanbulStackTable(),
londonStackTable(),
mergeStackTable(),
mergeStackTable(),
shanghaiStackTable(),
cancunStackTable(),
]
4 changes: 2 additions & 2 deletions tests/customgenesis/eof.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"berlinBlock": 0,
"londonBlock": 0,
"mergeForkBlock": 0,
"shanghaiBlock": 0,
"cancunBlock": 0,
"shanghaiTime": 0,
"cancunTime": 0,
"terminalTotalDifficulty": 0
},
"genesis": {
Expand Down
14 changes: 9 additions & 5 deletions tests/test_eof.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import
std/[tables, math, times],
std/[tables, math],
eth/[keys],
stew/byteutils,
unittest2,
Expand Down Expand Up @@ -230,7 +230,7 @@ proc initEnv(): TestEnv =

let
com = CommonRef.new(
newMemoryDb(),
newCoreDbRef LegacyDbMemory,
conf.pruneMode == PruneMode.Full,
conf.networkId,
conf.networkParams
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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)

Expand Down
1 change: 0 additions & 1 deletion tools/t8n/t8n_test.nim
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ const
expOut: "exp.json",
),
TestSpec(
<<<<<<< HEAD
name : "EVM tracer nil stack crash bug",
base : "testdata/00-519",
input : t8nInput(
Expand Down

0 comments on commit 3437794

Please sign in to comment.