moonproof-runtime 0.2.1

Wasm-friendly Compact contract runtime core — IR walker, IR-driven circuit executor, contract state, runtime values
Documentation
use thiserror::Error;

#[derive(Debug, Error)]
pub enum IrDriverError {
    #[error("IR loader error: {0}")]
    IrLoader(#[from] moonproof_runtime_ir::IrError),

    #[error("unimplemented IR construct: {what}")]
    Unimplemented { what: String },

    #[error("circuit '{0}' not found in IR")]
    UnknownCircuit(String),

    #[error("witness '{0}' not found in IR")]
    UnknownWitness(String),

    #[error("type mismatch: {0}")]
    TypeMismatch(String),

    #[error("unbound variable '{0}' in circuit body")]
    UnboundVariable(String),

    #[error("descriptor '{0}' not found in IR descriptor table")]
    UnknownDescriptor(String),

    #[error("argument count mismatch for {context}: expected {expected}, got {got}")]
    ArgCount {
        context: String,
        expected: usize,
        got: usize,
    },

    #[error("witness invocation failed: {0}")]
    Witness(String),

    #[error("VM op execution failed: {0}")]
    VmOp(String),

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

    #[error("invalid IR shape: {0}")]
    InvalidIr(String),

    #[error("cross-contract call failed: {0}")]
    CrossContract(String),
}

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

impl IrDriverError {
    #[must_use]
    pub fn unimplemented(what: impl Into<String>) -> Self {
        Self::Unimplemented { what: what.into() }
    }
}