moonproof_runtime/error.rs
1//! Runtime error type — pure-compute side.
2//!
3//! Heavy variants (wallet/proving/indexer wraps + the lifecycle
4//! `ContractsError` enum) live in [`moonproof_contracts::error`]. Runtime
5//! code never returns those variants because it never touches
6//! network / proving / heavy lifecycle paths.
7//!
8//! The host crate has its own `ContractRuntimeError` enum that mirrors
9//! these variants and adds the heavy ones; conversion is via
10//! `From<moonproof_runtime::ContractRuntimeError>` on the host side.
11
12use thiserror::Error;
13
14/// Runtime/infrastructure errors emitted by the wasm-friendly runtime
15/// core (walker / IR executor / state struct / ledger types).
16#[derive(Debug, Error)]
17pub enum ContractRuntimeError {
18 /// A hex-encoded indexer payload failed to decode.
19 #[error("hex decode failed: {0}")]
20 HexDecode(#[from] hex::FromHexError),
21
22 /// A tagged-serialized blob (e.g. `ContractState`) failed to parse.
23 #[error("deserialize failed ({context}): {source}")]
24 Deserialize {
25 context: &'static str,
26 #[source]
27 source: std::io::Error,
28 },
29
30 /// A tagged-serialize call failed.
31 #[error("serialize failed ({context}): {source}")]
32 Serialize {
33 context: &'static str,
34 #[source]
35 source: std::io::Error,
36 },
37
38 /// The indexer returned a contract action for an address that
39 /// doesn't match the runtime state's address.
40 #[error("contract action address {got} does not match expected {expected}")]
41 AddressMismatch { expected: String, got: String },
42
43 /// The indexer's `contractAction` query returned `null` for the
44 /// requested address.
45 #[error("no contract deployed at address {0}")]
46 NotFound(String),
47
48 /// A circuit's `assert` did not hold: the call reverts with the
49 /// assertion's message.
50 #[error("assert failed: {0}")]
51 AssertionFailed(String),
52
53 /// A circuit execution failed inside the IR-driven executor.
54 #[error("circuit execution failed: {0}")]
55 CircuitExecution(String),
56
57 /// A provider call (private-state / public-data / zk-config /
58 /// wallet / midnight / proof) returned an error.
59 #[error("provider error ({provider}): {message}")]
60 Provider {
61 provider: &'static str,
62 message: String,
63 },
64
65 /// I/O error reading a ZK artifact file.
66 #[error("i/o error ({context}): {source}")]
67 Io {
68 context: &'static str,
69 #[source]
70 source: std::io::Error,
71 },
72
73 /// A well-formedness check failed before submission.
74 #[error("well-formedness check failed: {0}")]
75 WellFormed(String),
76}
77
78pub type Result<T> = std::result::Result<T, ContractRuntimeError>;