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: Move Precompiles to EVMData so Inspector can access it #504

Merged
merged 1 commit into from
Jun 5, 2023
Merged
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
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 @@ -546,7 +546,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 @@ -804,7 +804,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 @@ -945,7 +946,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