From e607991ec94ae1f48cf3fde3e6bd79ab79c7b4d2 Mon Sep 17 00:00:00 2001 From: minaminao Date: Thu, 9 Nov 2023 05:56:36 +0900 Subject: [PATCH] chore: use keccak256 for blockhash --- crates/revm/src/db/emptydb.rs | 4 ++-- crates/revm/src/db/states/state.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/revm/src/db/emptydb.rs b/crates/revm/src/db/emptydb.rs index d668bfe0da..dbdb630614 100644 --- a/crates/revm/src/db/emptydb.rs +++ b/crates/revm/src/db/emptydb.rs @@ -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. @@ -101,6 +101,6 @@ impl DatabaseRef for EmptyDBTyped { #[inline] fn block_hash_ref(&self, number: U256) -> Result { - Ok(number.to_be_bytes().into()) + Ok(keccak256(number.to_be_bytes::<{ U256::BYTES }>())) } } diff --git a/crates/revm/src/db/states/state.rs b/crates/revm/src/db/states/state.rs index cbfc53f201..617a324adf 100644 --- a/crates/revm/src/db/states/state.rs +++ b/crates/revm/src/db/states/state.rs @@ -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() { @@ -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,