Skip to content
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
24 changes: 12 additions & 12 deletions crates/primitives/src/precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ pub type EnvPrecompileFn = fn(&Bytes, u64, env: &Env) -> PrecompileResult;
/// Stateful precompile trait. It is used to create
/// a arc precompile Precompile::Stateful.
pub trait StatefulPrecompile: Sync + Send {
fn call(&self, bytes: &Bytes, gas_price: u64, env: &Env) -> PrecompileResult;
fn call(&self, bytes: &Bytes, gas_limit: u64, env: &Env) -> PrecompileResult;
}

/// Mutable stateful precompile trait. It is used to create
/// a boxed precompile in Precompile::StatefulMut.
pub trait StatefulPrecompileMut: DynClone + Send + Sync {
fn call_mut(&mut self, bytes: &Bytes, gas_price: u64, env: &Env) -> PrecompileResult;
fn call_mut(&mut self, bytes: &Bytes, gas_limit: u64, env: &Env) -> PrecompileResult;
}

dyn_clone::clone_trait_object!(StatefulPrecompileMut);
Expand Down Expand Up @@ -109,23 +109,23 @@ impl Precompile {
}

/// Call the precompile with the given input and gas limit and return the result.
pub fn call(&mut self, bytes: &Bytes, gas_price: u64, env: &Env) -> PrecompileResult {
pub fn call(&mut self, bytes: &Bytes, gas_limit: u64, env: &Env) -> PrecompileResult {
match *self {
Precompile::Standard(p) => p(bytes, gas_price),
Precompile::Env(p) => p(bytes, gas_price, env),
Precompile::Stateful(ref p) => p.call(bytes, gas_price, env),
Precompile::StatefulMut(ref mut p) => p.call_mut(bytes, gas_price, env),
Precompile::Standard(p) => p(bytes, gas_limit),
Precompile::Env(p) => p(bytes, gas_limit, env),
Precompile::Stateful(ref p) => p.call(bytes, gas_limit, env),
Precompile::StatefulMut(ref mut p) => p.call_mut(bytes, gas_limit, env),
}
}

/// Call the precompile with the given input and gas limit and return the result.
///
/// Returns an error if the precompile is mutable.
pub fn call_ref(&self, bytes: &Bytes, gas_price: u64, env: &Env) -> PrecompileResult {
pub fn call_ref(&self, bytes: &Bytes, gas_limit: u64, env: &Env) -> PrecompileResult {
match *self {
Precompile::Standard(p) => p(bytes, gas_price),
Precompile::Env(p) => p(bytes, gas_price, env),
Precompile::Stateful(ref p) => p.call(bytes, gas_price, env),
Precompile::Standard(p) => p(bytes, gas_limit),
Precompile::Env(p) => p(bytes, gas_limit, env),
Precompile::Stateful(ref p) => p.call(bytes, gas_limit, env),
Precompile::StatefulMut(_) => Err(PrecompileErrors::Fatal {
msg: "call_ref on mutable stateful precompile".into(),
}),
Expand Down Expand Up @@ -233,7 +233,7 @@ mod test {
fn call_mut(
&mut self,
_bytes: &Bytes,
_gas_price: u64,
_gas_limit: u64,
_env: &Env,
) -> PrecompileResult {
Err(PrecompileError::OutOfGas.into())
Expand Down
2 changes: 1 addition & 1 deletion crates/revm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ mod test {
fn call(
&self,
_input: &Bytes,
_gas_price: u64,
_gas_limit: u64,
_context: &mut InnerEvmContext<EmptyDB>,
) -> PrecompileResult {
Ok(PrecompileOutput::new(10, Bytes::new()))
Expand Down
14 changes: 7 additions & 7 deletions crates/revm/src/context/context_precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ impl<DB: Database> ContextPrecompiles<DB> {
&mut self,
address: &Address,
bytes: &Bytes,
gas_price: u64,
gas_limit: u64,
evmctx: &mut InnerEvmContext<DB>,
) -> Option<PrecompileResult> {
Some(match self.inner {
PrecompilesCow::StaticRef(p) => p.get(address)?.call_ref(bytes, gas_price, &evmctx.env),
PrecompilesCow::StaticRef(p) => p.get(address)?.call_ref(bytes, gas_limit, &evmctx.env),
PrecompilesCow::Owned(ref mut owned) => match owned.get_mut(address)? {
ContextPrecompile::Ordinary(p) => p.call(bytes, gas_price, &evmctx.env),
ContextPrecompile::ContextStateful(p) => p.call(bytes, gas_price, evmctx),
ContextPrecompile::ContextStatefulMut(p) => p.call_mut(bytes, gas_price, evmctx),
ContextPrecompile::Ordinary(p) => p.call(bytes, gas_limit, &evmctx.env),
ContextPrecompile::ContextStateful(p) => p.call(bytes, gas_limit, evmctx),
ContextPrecompile::ContextStatefulMut(p) => p.call_mut(bytes, gas_limit, evmctx),
},
})
}
Expand Down Expand Up @@ -199,7 +199,7 @@ pub trait ContextStatefulPrecompile<DB: Database>: Sync + Send {
fn call(
&self,
bytes: &Bytes,
gas_price: u64,
gas_limit: u64,
evmctx: &mut InnerEvmContext<DB>,
) -> PrecompileResult;
}
Expand All @@ -210,7 +210,7 @@ pub trait ContextStatefulPrecompileMut<DB: Database>: DynClone + Send + Sync {
fn call_mut(
&mut self,
bytes: &Bytes,
gas_price: u64,
gas_limit: u64,
evmctx: &mut InnerEvmContext<DB>,
) -> PrecompileResult;
}
Expand Down
2 changes: 1 addition & 1 deletion documentation/src/crates/revm/builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl ContextStatefulPrecompile<EvmContext<EmptyDB>, ()> for CustomPrecompile {
fn call(
&self,
_input: &Bytes,
_gas_price: u64,
_gas_limit: u64,
_context: &mut EvmContext<EmptyDB>,
_extctx: &mut (),
) -> PrecompileResult {
Expand Down