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

chore: use keccak256 for blockhash #854

Merged
merged 1 commit into from
Nov 9, 2023
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
4 changes: 2 additions & 2 deletions crates/revm/src/db/emptydb.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use core::{convert::Infallible, fmt, marker::PhantomData};
use revm_interpreter::primitives::{
db::{Database, DatabaseRef},
AccountInfo, Address, Bytecode, B256, U256,
keccak256, AccountInfo, Address, Bytecode, B256, U256,
};

/// An empty database that always returns default values when queried.
Expand Down Expand Up @@ -101,6 +101,6 @@ impl<E> DatabaseRef for EmptyDBTyped<E> {

#[inline]
fn block_hash_ref(&self, number: U256) -> Result<B256, Self::Error> {
Ok(number.to_be_bytes().into())
Ok(keccak256(number.to_be_bytes::<{ U256::BYTES }>()))
}
}
8 changes: 4 additions & 4 deletions crates/revm/src/db/states/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ mod tests {
states::reverts::AccountInfoRevert, AccountRevert, AccountStatus, BundleAccount,
RevertToSlot,
};
use revm_interpreter::primitives::StorageSlot;
use revm_interpreter::primitives::{keccak256, StorageSlot};

#[test]
fn block_hash_cache() {
Expand All @@ -315,9 +315,9 @@ mod tests {

let test_number = BLOCK_HASH_HISTORY as u64 + 2;

let block1_hash = B256::from(U256::from(1).to_be_bytes());
let block2_hash = B256::from(U256::from(2).to_be_bytes());
let block_test_hash = B256::from(U256::from(test_number).to_be_bytes());
let block1_hash = keccak256(&U256::from(1).to_be_bytes::<{ U256::BYTES }>());
let block2_hash = keccak256(&U256::from(2).to_be_bytes::<{ U256::BYTES }>());
let block_test_hash = keccak256(&U256::from(test_number).to_be_bytes::<{ U256::BYTES }>());

assert_eq!(
state.block_hashes,
Expand Down