pub trait Precompile {
// Required methods
fn precompile_id(&self) -> &PrecompileId;
fn call(&self, input: PrecompileInput<'_>) -> PrecompileResult;
// Provided method
fn is_pure(&self) -> bool { ... }
}Expand description
Trait for implementing precompiled contracts.
Required Methods§
Sourcefn precompile_id(&self) -> &PrecompileId
fn precompile_id(&self) -> &PrecompileId
Returns precompile ID.
Sourcefn call(&self, input: PrecompileInput<'_>) -> PrecompileResult
fn call(&self, input: PrecompileInput<'_>) -> PrecompileResult
Execute the precompile with the given input data, gas limit, and caller address.
Provided Methods§
Sourcefn is_pure(&self) -> bool
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
}
}