Skip to main content

PrecompileProvider

Trait PrecompileProvider 

pub trait PrecompileProvider<CTX>
where CTX: ContextTr,
{ type Output; // Required methods fn set_spec(&mut self, spec: <<CTX as ContextTr>::Cfg as Cfg>::Spec) -> bool; fn run( &mut self, context: &mut CTX, inputs: &CallInputs, ) -> Result<Option<Self::Output>, String>; fn warm_addresses(&self) -> &HashSet<Address, FbBuildHasher<20>>; // Provided method fn contains(&self, address: &Address) -> bool { ... } }
Available on crate feature evm only.
Expand description

Provider for precompiled contracts in the EVM.

Required Associated Types§

type Output

The output type returned by precompile execution.

Required Methods§

fn set_spec(&mut self, spec: <<CTX as ContextTr>::Cfg as Cfg>::Spec) -> bool

Sets the spec id and returns true if the spec id was changed. Initial call to set_spec will always return true.

Returns true if precompile addresses should be injected into the journal.

fn run( &mut self, context: &mut CTX, inputs: &CallInputs, ) -> Result<Option<Self::Output>, String>

Runs the precompile for the given call inputs.

Return values distinguish whether the provider handled the call:

  • Ok(Some(output)) means the call was executed by this provider.
  • Ok(None) means this provider does not contain a precompile for the requested address, so the caller should continue with regular contract execution.
  • Err(error) means execution failed with a provider error that should abort EVM execution. Non-fatal precompile failures, such as reverts, out-of-gas, or invalid input, should be encoded in output instead.

fn warm_addresses(&self) -> &HashSet<Address, FbBuildHasher<20>>

Get the warm addresses.

Provided Methods§

fn contains(&self, address: &Address) -> bool

Check if the address is a precompile.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

§

impl<'a, CTX, T> PrecompileProvider<CTX> for &'a mut T
where CTX: ContextTr, T: 'a + PrecompileProvider<CTX> + ?Sized,

§

type Output = <T as PrecompileProvider<CTX>>::Output

§

fn set_spec(&mut self, spec: <<CTX as ContextTr>::Cfg as Cfg>::Spec) -> bool

§

fn run( &mut self, context: &mut CTX, inputs: &CallInputs, ) -> Result<Option<<&'a mut T as PrecompileProvider<CTX>>::Output>, String>

§

fn warm_addresses(&self) -> &HashSet<Address, FbBuildHasher<20>>

§

fn contains(&self, address: &Address) -> bool

§

impl<CTX, T> PrecompileProvider<CTX> for Box<T>
where CTX: ContextTr, T: PrecompileProvider<CTX> + ?Sized,

§

type Output = <T as PrecompileProvider<CTX>>::Output

§

fn set_spec(&mut self, spec: <<CTX as ContextTr>::Cfg as Cfg>::Spec) -> bool

§

fn run( &mut self, context: &mut CTX, inputs: &CallInputs, ) -> Result<Option<<Box<T> as PrecompileProvider<CTX>>::Output>, String>

§

fn warm_addresses(&self) -> &HashSet<Address, FbBuildHasher<20>>

§

fn contains(&self, address: &Address) -> bool

Implementors§

§

impl<BlockEnv, TxEnv, CfgEnv, DB, Chain> PrecompileProvider<Context<BlockEnv, TxEnv, CfgEnv, DB, Journal<DB>, Chain>> for PrecompilesMap
where BlockEnv: BlockEnvironment, TxEnv: Transaction + 'static, CfgEnv: Cfg, DB: Database,

§

impl<CTX> PrecompileProvider<CTX> for EthPrecompiles
where CTX: ContextTr,