moonproof_runtime/lib.rs
1#![recursion_limit = "256"]
2//! Wasm-friendly Compact contract runtime core — IR walker, IR
3//! executor, contract state, and the runtime value type.
4//!
5//! Pure compute. No network, no disk, no proving. The lifecycle layer
6//! (deploy / call / maintenance / submission / providers) lives in
7//! the [`moonproof_contracts`] crate, which depends on this one.
8//!
9//! # What lives here
10//!
11//! - [`ir`] — descriptor walker, interpreter, witnesses, vm-decode.
12//! - [`walker`] — storage-shape readers (Cell / Map / Set / List /
13//! `MerkleTree` / `HistoricMerkleTree`).
14//! - [`ir_executable`] — IR-driven circuit executor.
15//! - [`cross_contract`] — call trees: circuits that call circuits of
16//! other deployed contracts.
17//! - [`executable`] — executor inputs/outputs (`CircuitCallContext`,
18//! `ConstructorContext`, `ExecuteCircuitResult`, `InitializeResult`).
19//! - [`state`] — [`state::ContractRuntimeState`] struct + accessors.
20//! Indexer-driven fold lives in [`moonproof_contracts::state_fold`].
21//! - [`ledger`] — [`ledger::AtomBuffer`] + Merkle snapshot types +
22//! the descriptor-aware projector. Async readers live in
23//! [`moonproof_contracts::ledger_readers`].
24//! - [`zswap_local`] — `CompactZswapLocalState` + `CompactZswapOutput`,
25//! the per-circuit-execution zswap view consumed by the executor.
26//! - [`compact_types`] — typed wrappers (`CompactMap`, `CompactSet`,
27//! `CompactList`, views, `ContractAddress`, `JubjubPoint`, …) for
28//! codegen-emitted contract bindings.
29
30pub mod compact_types;
31pub mod coverage;
32pub mod cross_contract;
33pub mod error;
34pub mod executable;
35// Re-export `hex` so generated code can reach for `moonproof_runtime::hex`
36// without pulling a parallel dep into every scaffolded project.
37pub use hex;
38
39// Re-export the IR value crate so codegen-emitted Rust code can refer
40// to `::moonproof_runtime::runtime_ir::*` (RuntimeValue, ValueProjectionError,
41// ir::TypeDescriptor, etc.) without forcing every scaffolded dapp to
42// add `moonproof-runtime-ir` to its Cargo.toml.
43pub use moonproof_runtime_ir as runtime_ir;
44pub mod ir;
45pub mod ir_executable;
46pub mod ledger;
47pub mod ledger_read;
48pub mod state;
49pub mod trace;
50pub mod types;
51pub mod walker;
52pub mod zswap_local;
53
54// =====================================================================
55// Crate-root re-exports.
56// =====================================================================
57
58pub use error::{ContractRuntimeError, Result};
59pub use types::{
60 BlockHash, CircuitId, CoinPublicKey, EncPublicKey, PrivateStateId, ProverKey, TransactionHash,
61 TransactionId, VerifierKey, ZkConfig, Zkir,
62};
63
64// Stdlib opaque-projection shapes — codegen targets these for
65// `Opaque<'JubjubPoint'>`, `Opaque<'MerkleTreeDigest'>`, etc.
66pub use compact_types::{Curve25519Point, JubjubPoint, Secp256k1Point, Secp256r1Point};
67
68pub use executable::{
69 CircuitCallContext, ConstructorContext, ExecuteCircuitResult, InitializeResult,
70};
71pub use ir::descriptor::{decode_aligned_value_full, encode_literal};
72pub use ir::error::{IrDriverError, Result as IrResult};
73pub use ir::witnesses::{self, NoWitnesses, ScriptedWitnesses, Witnesses};
74pub use ir_executable::{IrExecutable, LedgerFieldSchema};
75
76pub use cross_contract::{
77 CallTreeOutcome, CallTreeResult, CalleeCall, CalleeContract, CrossContractSession,
78};
79
80pub use coverage::{
81 AssertCoverage, BranchCoverage, BranchKind, CircuitIrCoverage, EmitCoverage,
82 IrCoverageCollector, IrCoverageMap, IrCoverageSnapshot, IrCoverageTotals, LedgerOpCoverage,
83};
84pub use state::{contract_address_to_hex, ContractRuntimeState};
85pub use trace::{ExecutionTrace, TraceEvent, TraceLevel};
86
87pub use zswap_local::{CompactZswapLocalState, CompactZswapOutput};
88
89// Re-export the storage-bound midnight types codegen-emitted code
90// reaches for so generated user crates only need a `moonproof-runtime`
91// dep, not direct deps on midnight crates.
92pub use moonproof_ledger::onchain_runtime::state::ContractState;
93pub use moonproof_ledger::storage::db::InMemoryDB;