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 Aug 5, 2023
1 parent a533710 commit 7bc4f99
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 17 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 @@ -384,9 +382,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 @@ -169,7 +169,7 @@ const
cpt.gasCosts[CodeCopy].m_handler(cpt.memory.len, memPos, len),
reason = "CodeCopy fee")

cpt.memory.writePaddedResult(k.cpt.code.legacyCode, memPos, copyPos, len)
cpt.memory.writePaddedResult(cpt.code.legacyCode, memPos, copyPos, len)

gasPriceOp: Vm2OpFn = proc (k: var Vm2Ctx) =
## 0x3A, Get price of gas in current environment.
Expand Down
3 changes: 3 additions & 0 deletions nimbus/evm/interpreter_dispatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,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
23 changes: 19 additions & 4 deletions nimbus/evm/stack_table.nim
Original file line number Diff line number Diff line change
Expand Up @@ -187,21 +187,36 @@ 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)

# disable opcodes EIP-3670
result[CallCode] = StackDesc()
result[SelfDestruct] = StackDesc()

# disable opcodes EIP-5450
result[Jump] = StackDesc()
result[JumpI] = StackDesc()
Expand All @@ -220,6 +235,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
10 changes: 7 additions & 3 deletions tests/test_eof.nim
Original file line number Diff line number Diff line change
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 @@ -299,7 +302,8 @@ proc eofMain*() =

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
3 changes: 2 additions & 1 deletion tools/t8n/testdata/28/env.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"parentGasUsed": "0x0",
"parentGasLimit": "0x750a163df65e8a",
"currentNumber": "1",
"currentTimestamp": "1000"
"currentTimestamp": "1000",
"withdrawals": []
}

0 comments on commit 7bc4f99

Please sign in to comment.