From 9e19f97363477764e7c2a46b4320d4b9d0249f39 Mon Sep 17 00:00:00 2001 From: rakita Date: Mon, 27 May 2024 10:37:03 +0200 Subject: [PATCH] fix(Interpreter): wrong block number used --- crates/interpreter/src/instructions/host.rs | 3 +-- crates/revm/src/db/states/state.rs | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/interpreter/src/instructions/host.rs b/crates/interpreter/src/instructions/host.rs index 20a2bcfe6c..0bc777c341 100644 --- a/crates/interpreter/src/instructions/host.rs +++ b/crates/interpreter/src/instructions/host.rs @@ -106,8 +106,7 @@ pub fn blockhash(interpreter: &mut Interpreter, ho gas!(interpreter, gas::BLOCKHASH); pop_top!(interpreter, number); - let block_number = host.env().block.number; - let Some(hash) = host.block_hash(block_number) else { + let Some(hash) = host.block_hash(*number) else { interpreter.instruction_result = InstructionResult::FatalExternalError; return; }; diff --git a/crates/revm/src/db/states/state.rs b/crates/revm/src/db/states/state.rs index 22a937c5b8..4ca380d838 100644 --- a/crates/revm/src/db/states/state.rs +++ b/crates/revm/src/db/states/state.rs @@ -277,8 +277,9 @@ impl Database for State { let ret = *entry.insert(self.database.block_hash(number)?); // prune all hashes that are older then BLOCK_HASH_HISTORY + let last_block = u64num.saturating_sub(BLOCK_HASH_HISTORY as u64); while let Some(entry) = self.block_hashes.first_entry() { - if *entry.key() < u64num.saturating_sub(BLOCK_HASH_HISTORY as u64) { + if *entry.key() < last_block { entry.remove(); } else { break;