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(Interpreter): wrong block number used #1458

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions crates/interpreter/src/instructions/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ pub fn blockhash<H: Host + ?Sized, SPEC: Spec>(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;
};
Expand Down
3 changes: 2 additions & 1 deletion crates/revm/src/db/states/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ impl<DB: Database> Database for State<DB> {
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;
Expand Down
Loading