moonproof-runtime 0.2.1

Wasm-friendly Compact contract runtime core — IR walker, IR-driven circuit executor, contract state, runtime values
Documentation
//! Runtime error type — pure-compute side.
//!
//! Heavy variants (wallet/proving/indexer wraps + the lifecycle
//! `ContractsError` enum) live in [`moonproof_contracts::error`]. Runtime
//! code never returns those variants because it never touches
//! network / proving / heavy lifecycle paths.
//!
//! The host crate has its own `ContractRuntimeError` enum that mirrors
//! these variants and adds the heavy ones; conversion is via
//! `From<moonproof_runtime::ContractRuntimeError>` on the host side.

use thiserror::Error;

/// Runtime/infrastructure errors emitted by the wasm-friendly runtime
/// core (walker / IR executor / state struct / ledger types).
#[derive(Debug, Error)]
pub enum ContractRuntimeError {
    /// A hex-encoded indexer payload failed to decode.
    #[error("hex decode failed: {0}")]
    HexDecode(#[from] hex::FromHexError),

    /// A tagged-serialized blob (e.g. `ContractState`) failed to parse.
    #[error("deserialize failed ({context}): {source}")]
    Deserialize {
        context: &'static str,
        #[source]
        source: std::io::Error,
    },

    /// A tagged-serialize call failed.
    #[error("serialize failed ({context}): {source}")]
    Serialize {
        context: &'static str,
        #[source]
        source: std::io::Error,
    },

    /// The indexer returned a contract action for an address that
    /// doesn't match the runtime state's address.
    #[error("contract action address {got} does not match expected {expected}")]
    AddressMismatch { expected: String, got: String },

    /// The indexer's `contractAction` query returned `null` for the
    /// requested address.
    #[error("no contract deployed at address {0}")]
    NotFound(String),

    /// A circuit's `assert` did not hold: the call reverts with the
    /// assertion's message.
    #[error("assert failed: {0}")]
    AssertionFailed(String),

    /// A circuit execution failed inside the IR-driven executor.
    #[error("circuit execution failed: {0}")]
    CircuitExecution(String),

    /// A provider call (private-state / public-data / zk-config /
    /// wallet / midnight / proof) returned an error.
    #[error("provider error ({provider}): {message}")]
    Provider {
        provider: &'static str,
        message: String,
    },

    /// I/O error reading a ZK artifact file.
    #[error("i/o error ({context}): {source}")]
    Io {
        context: &'static str,
        #[source]
        source: std::io::Error,
    },

    /// A well-formedness check failed before submission.
    #[error("well-formedness check failed: {0}")]
    WellFormed(String),
}

pub type Result<T> = std::result::Result<T, ContractRuntimeError>;