Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix t8n tool #1354

Merged
merged 6 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix t8n does not support BLOCKHASH opcode
  • Loading branch information
jangko committed Dec 8, 2022
commit ed518c760fbecb6a99a8dbb8b29a5e1e93c4aa84
22 changes: 18 additions & 4 deletions nimbus/evm/computation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# according to those terms.

import
".."/[db/accounts_cache],
".."/[db/accounts_cache, constants],
"."/[code_stream, memory, message, stack, state],
"."/[transaction_tracer, types],
./interpreter/[gas_meter, gas_costs, op_codes],
Expand Down Expand Up @@ -113,11 +113,25 @@ template getGasPrice*(c: Computation): GasInt =
else:
c.vmState.txGasPrice

template getBlockHash*(c: Computation, blockNumber: UInt256): Hash256 =
proc getBlockHash*(c: Computation, number: UInt256): Hash256 =
when evmc_enabled:
c.host.getBlockHash(blockNumber)
let
blockNumber = c.host.getTxContext().block_number.u256
ancestorDepth = blockNumber - number - 1
if ancestorDepth >= constants.MAX_PREV_HEADER_DEPTH:
return
if number >= blockNumber:
return
c.host.getBlockHash(number)
else:
c.vmState.getAncestorHash(blockNumber.vmWordToBlockNumber)
let
blockNumber = c.vmState.blockNumber
ancestorDepth = blockNumber - number - 1
if ancestorDepth >= constants.MAX_PREV_HEADER_DEPTH:
return
if number >= blockNumber:
return
c.vmState.getAncestorHash(number.vmWordToBlockNumber)

template accountExists*(c: Computation, address: EthAddress): bool =
when evmc_enabled:
Expand Down
7 changes: 0 additions & 7 deletions nimbus/evm/evmc_api.nim
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ proc getTxContext*(ctx: HostContext): nimbus_tx_context {.inline.} =
ctx.host.get_tx_context(ctx.context)

proc getBlockHash*(ctx: HostContext, number: UInt256): Hash256 =
let
blockNumber = ctx.getTxContext().block_number.u256
ancestorDepth = blockNumber - number - 1
if ancestorDepth >= constants.MAX_PREV_HEADER_DEPTH:
return
if number >= blockNumber:
return
ctx.host.get_block_hash(ctx.context, number.truncate(int64))

proc accountExists*(ctx: HostContext, address: EthAddress): bool {.inline.} =
Expand Down
6 changes: 0 additions & 6 deletions nimbus/evm/state.nim
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,6 @@ when defined(geth):
import db/geth_db

method getAncestorHash*(vmState: BaseVMState, blockNumber: BlockNumber): Hash256 {.base, gcsafe, raises: [Defect,CatchableError,Exception].} =
var ancestorDepth = vmState.blockNumber - blockNumber - 1
if ancestorDepth >= MAX_PREV_HEADER_DEPTH:
return
if blockNumber >= vmState.blockNumber:
return

let db = vmState.com.db
when defined(geth):
result = db.headerHash(blockNumber.truncate(uint64))
Expand Down