Skip to main content

Precompile

Trait Precompile 

Source
pub trait Precompile: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn id(&self) -> Felt;
    fn decode(&self, args: [Felt; 3]) -> Option<NodeType>;
    fn evaluate(
        &self,
        args: [Felt; 3],
        payload: &Payload,
        context: &mut DeferredContext<'_>,
    ) -> Result<Node, PrecompileError>;

    // Provided method
    fn init(&self) -> Vec<Node> { ... }
}
Expand description

Semantic module installed in a PrecompileRegistry.

Each precompile owns one stable id and interprets that id’s three local tag felts.

Required Methods§

Source

fn name(&self) -> &'static str

Stable name hashed into the precompile id; renaming changes every tag this precompile owns.

Source

fn id(&self) -> Felt

Stable tag id for this precompile.

The registry validates this against precompile_id and rejects framework-reserved ids, turning id drift into a setup-time failure.

Source

fn decode(&self, args: [Felt; 3]) -> Option<NodeType>

Declares the body shape for recognized local tag arguments.

Returning None rejects the tag. The registry has already matched the precompile id, so this only interprets the tag’s local arguments.

Source

fn evaluate( &self, args: [Felt; 3], payload: &Payload, context: &mut DeferredContext<'_>, ) -> Result<Node, PrecompileError>

Evaluates one owned node to its canonical form.

The registry has already matched the tag id; implementors receive only local args and a payload whose outer shape passed Self::decode. Use DeferredContext to evaluate registered child digests (digests present in the state’s node store) or to register helper nodes referenced by a compound canonical.

Common conventions:

  • canonical values return themselves after validating payload contents;
  • producing ops evaluate structural children and return the resulting canonical node;
  • predicates return Node::TRUE on success and PrecompileError::AssertionFailed on mismatch;
  • multi-chunk data nodes usually evaluate to a single-chunk value.

Provided Methods§

Source

fn init(&self) -> Vec<Node>

Canonical constants this precompile wants registered before execution.

State initialization loads every installed precompile’s init nodes into one bootstrap set, then evaluates each init node to ensure the set resolves under the installed registry. The default contributes no constants.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§