diff --git a/crates/precompile/src/bn128.rs b/crates/precompile/src/bn128.rs index fc60d29100..2d6d57c0ef 100644 --- a/crates/precompile/src/bn128.rs +++ b/crates/precompile/src/bn128.rs @@ -1,4 +1,6 @@ -use crate::{primitives::U256, Address, Error, Precompile, PrecompileWithAddress, PrecompileResult}; +use crate::{ + primitives::U256, Address, Error, Precompile, PrecompileResult, PrecompileWithAddress, +}; use alloc::vec::Vec; pub mod add { diff --git a/crates/precompile/src/hash.rs b/crates/precompile/src/hash.rs index 7b678b896b..2e50821fa2 100644 --- a/crates/precompile/src/hash.rs +++ b/crates/precompile/src/hash.rs @@ -1,5 +1,5 @@ use super::calc_linear_cost_u32; -use crate::{Error, Precompile, PrecompileWithAddress, PrecompileResult, StandardPrecompileFn}; +use crate::{Error, Precompile, PrecompileResult, PrecompileWithAddress, StandardPrecompileFn}; use sha2::*; pub const SHA256: PrecompileWithAddress = PrecompileWithAddress( diff --git a/crates/precompile/src/identity.rs b/crates/precompile/src/identity.rs index fc28edd873..5cb28e23a5 100644 --- a/crates/precompile/src/identity.rs +++ b/crates/precompile/src/identity.rs @@ -1,5 +1,5 @@ use super::calc_linear_cost_u32; -use crate::{Error, Precompile, PrecompileWithAddress, PrecompileResult, StandardPrecompileFn}; +use crate::{Error, Precompile, PrecompileResult, PrecompileWithAddress, StandardPrecompileFn}; pub const FUN: PrecompileWithAddress = PrecompileWithAddress( crate::u64_to_address(4), diff --git a/crates/precompile/src/kzg_point_evaluation.rs b/crates/precompile/src/kzg_point_evaluation.rs index 323e80afa5..2feec204f1 100644 --- a/crates/precompile/src/kzg_point_evaluation.rs +++ b/crates/precompile/src/kzg_point_evaluation.rs @@ -1,9 +1,10 @@ -use crate::{Address, Error, Precompile, PrecompileWithAddress, PrecompileResult}; +use crate::{Address, Error, Precompile, PrecompileResult, PrecompileWithAddress}; use c_kzg::{Bytes32, Bytes48, KzgProof, KzgSettings}; use revm_primitives::{hex_literal::hex, Env}; use sha2::{Digest, Sha256}; -pub const POINT_EVALUATION: PrecompileWithAddress = PrecompileWithAddress(ADDRESS, Precompile::Env(run)); +pub const POINT_EVALUATION: PrecompileWithAddress = + PrecompileWithAddress(ADDRESS, Precompile::Env(run)); const ADDRESS: Address = crate::u64_to_address(0x0A); const GAS_COST: u64 = 50_000; diff --git a/crates/precompile/src/lib.rs b/crates/precompile/src/lib.rs index 9ab2aaff52..838d2d7e20 100644 --- a/crates/precompile/src/lib.rs +++ b/crates/precompile/src/lib.rs @@ -274,4 +274,4 @@ const fn u64_to_address(x: u64) -> Address { Address::new([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, x[0], x[1], x[2], x[3], x[4], x[5], x[6], x[7], ]) -} \ No newline at end of file +} diff --git a/crates/precompile/src/modexp.rs b/crates/precompile/src/modexp.rs index e5555fc0e9..015d33d561 100644 --- a/crates/precompile/src/modexp.rs +++ b/crates/precompile/src/modexp.rs @@ -1,7 +1,7 @@ use crate::{ primitives::U256, utilities::{get_right_padded, get_right_padded_vec, left_padding, left_padding_vec}, - Error, Precompile, PrecompileWithAddress, PrecompileResult, StandardPrecompileFn, + Error, Precompile, PrecompileResult, PrecompileWithAddress, StandardPrecompileFn, }; use alloc::vec::Vec; use aurora_engine_modexp::modexp; diff --git a/crates/revm/src/evm_impl.rs b/crates/revm/src/evm_impl.rs index 423254058c..7113c8717e 100644 --- a/crates/revm/src/evm_impl.rs +++ b/crates/revm/src/evm_impl.rs @@ -362,7 +362,14 @@ impl<'a, GSPEC: Spec + 'static, DB: Database> EVMImpl<'a, GSPEC, DB> { inspector: Option<&'a mut dyn Inspector>, precompiles: Precompiles, ) -> Self { - let journaled_state = JournaledState::new(precompiles.len(), GSPEC::SPEC_ID); + let journaled_state = JournaledState::new( + GSPEC::SPEC_ID, + precompiles + .addresses() + .into_iter() + .cloned() + .collect::>(), + ); let instruction_table = if inspector.is_some() { let instruction_table = make_boxed_instruction_table::( make_instruction_table::(), @@ -656,7 +663,6 @@ impl<'a, GSPEC: Spec + 'static, DB: Database> EVMImpl<'a, GSPEC, DB> { mut gas: Gas, ) -> CallResult { let input_data = &inputs.input; - let contract = inputs.contract; let out = match precompile { Precompile::Standard(fun) => fun(input_data, gas.limit()), diff --git a/crates/revm/src/journaled_state.rs b/crates/revm/src/journaled_state.rs index 56540c2e08..59a1895475 100644 --- a/crates/revm/src/journaled_state.rs +++ b/crates/revm/src/journaled_state.rs @@ -6,7 +6,6 @@ use crate::primitives::{ use alloc::vec::Vec; use core::mem; use revm_interpreter::primitives::SpecId; -use revm_precompile::Precompiles; #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -40,11 +39,7 @@ impl JournaledState { /// /// Note: This function will journal state after Spurious Dragon fork. /// And will not take into account if account is not existing or empty. - pub fn new( - num_of_precompiles: usize, - spec: SpecId, - precompile_addresses: Vec
, - ) -> JournaledState { + pub fn new(spec: SpecId, precompile_addresses: Vec
) -> JournaledState { Self { state: HashMap::new(), transient_storage: TransientStorage::default(), @@ -56,11 +51,6 @@ impl JournaledState { } } - /// Is address precompile - pub fn is_precompile(&self, address: &Address) -> bool { - self.precompile_addresses.binary_search(address).is_ok() - } - /// Return reference to state. pub fn state(&mut self) -> &mut State { &mut self.state @@ -211,8 +201,8 @@ impl JournaledState { let last_journal = self.journal.last_mut().unwrap(); // check if it is possible to create this account. - - if Self::check_account_collision(address, account, self.is_precompile(&address)) { + let is_precompile = self.precompile_addresses.binary_search(&address).is_ok(); + if Self::check_account_collision(account, is_precompile) { self.checkpoint_revert(checkpoint); return Err(InstructionResult::CreateCollision); } @@ -266,11 +256,7 @@ impl JournaledState { } #[inline] - pub fn check_account_collision( - address: Address, - account: &Account, - is_precompile: bool, - ) -> bool { + pub fn check_account_collision(account: &Account, is_precompile: bool) -> bool { // Check collision. Bytecode needs to be empty. if account.info.code_hash != KECCAK_EMPTY { return true; @@ -553,7 +539,7 @@ impl JournaledState { .push(JournalEntry::AccountLoaded { address }); // precompiles are warm loaded so we need to take that into account - let is_cold = self.is_precompile(&address); + let is_cold = self.precompile_addresses.binary_search(&address).is_ok(); (vac.insert(account), is_cold) }