Precompile

Trait Precompile 

pub trait Precompile {
    // Required methods
    fn precompile_id(&self) -> &PrecompileId;
    fn call(
        &self,
        input: PrecompileInput<'_>,
    ) -> Result<PrecompileOutput, PrecompileError>;

    // Provided method
    fn is_pure(&self) -> bool { ... }
}
Available on crate feature evm only.
Expand description

Trait for implementing precompiled contracts.

Required Methods§

fn precompile_id(&self) -> &PrecompileId

Returns precompile ID.

fn call( &self, input: PrecompileInput<'_>, ) -> Result<PrecompileOutput, PrecompileError>

Execute the precompile with the given input data, gas limit, and caller address.

Provided Methods§

fn is_pure(&self) -> bool

Returns whether the precompile is pure.

A pure precompile has deterministic output based solely on its input. Non-pure precompiles may produce different outputs for the same input based on the current state or other external factors.

§Default

Returns true by default, indicating the precompile is pure and its results should be cached as this is what most of the precompiles are.

§Examples

Override this method to return false for non-deterministic precompiles:

impl Precompile for MyDeterministicPrecompile {
    fn call(&self, input: PrecompileInput<'_>) -> PrecompileResult {
        // non-deterministic computation dependent on state
    }

    fn is_pure(&self) -> bool {
        false // This precompile might produce different output for the same input
    }
}

Implementations on Foreign Types§

§

impl<'a, T> Precompile for &'a T
where T: 'a + Precompile + ?Sized,

§

impl<F> Precompile for (&PrecompileId, F)

§

impl<F> Precompile for (PrecompileId, F)

§

impl<T> Precompile for Arc<T>
where T: Precompile + ?Sized,

Implementors§

§

impl Precompile for Precompile

§

impl Precompile for DynPrecompile

§

impl<A, B> Precompile for Either<A, B>
where A: Precompile, B: Precompile,