Skip to content

Commit

Permalink
chore: Move Precompiles to EVMData so Inspector can access it (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
rakita authored Jun 5, 2023
1 parent 0a97b73 commit 65387e4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions crates/revm/src/evm_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ pub struct EVMData<'a, DB: Database> {
pub journaled_state: JournaledState,
pub db: &'a mut DB,
pub error: Option<DB::Error>,
pub precompiles: Precompiles,
}

pub struct EVMImpl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> {
data: EVMData<'a, DB>,
precompiles: Precompiles,
inspector: &'a mut dyn Inspector<DB>,
_phantomdata: PhantomData<GSPEC>,
}
Expand Down Expand Up @@ -307,8 +307,8 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
journaled_state,
db,
error: None,
precompiles,
},
precompiles,
inspector,
_phantomdata: PhantomData {},
}
Expand Down Expand Up @@ -381,7 +381,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
// added to it, we need now to load precompile address from db and add this amount to it so that we
// will have sum.
if self.data.env.cfg.perf_all_precompiles_have_balance {
for address in self.precompiles.addresses() {
for address in self.data.precompiles.addresses() {
let address = B160(*address);
if let Some(precompile) = new_state.get_mut(&address) {
// we found it.
Expand Down Expand Up @@ -554,7 +554,7 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
// Create contract account and check for collision
match self.data.journaled_state.create_account(
created_address,
self.precompiles.contains(&created_address),
self.data.precompiles.contains(&created_address),
self.data.db,
) {
Ok(false) => {
Expand Down Expand Up @@ -812,7 +812,8 @@ impl<'a, GSPEC: Spec, DB: Database, const INSPECT: bool> EVMImpl<'a, GSPEC, DB,
}

// Call precompiles
let (ret, gas, out) = if let Some(precompile) = self.precompiles.get(&inputs.contract) {
let (ret, gas, out) = if let Some(precompile) = self.data.precompiles.get(&inputs.contract)
{
let out = match precompile {
Precompile::Standard(fun) => fun(inputs.input.as_ref(), inputs.gas_limit),
Precompile::Custom(fun) => fun(inputs.input.as_ref(), inputs.gas_limit),
Expand Down Expand Up @@ -953,7 +954,7 @@ impl<'a, GSPEC: Spec, DB: Database + 'a, const INSPECT: bool> Host
.map_err(|e| *error = Some(e))
.ok()?;
//asume that all precompiles have some balance
let is_precompile = self.precompiles.contains(&address);
let is_precompile = self.data.precompiles.contains(&address);
if is_precompile && self.data.env.cfg.perf_all_precompiles_have_balance {
return Some((KECCAK_EMPTY, is_cold));
}
Expand Down

0 comments on commit 65387e4

Please sign in to comment.