Skip to main content

miden_precompiles_prover/
lib.rs

1#![no_std]
2#![allow(
3    dead_code,
4    unused_imports,
5    reason = "the imported prover stack is intentionally retained behind a narrow crate API"
6)]
7
8extern crate alloc;
9#[cfg(any(test, feature = "std"))]
10extern crate std;
11
12use alloc::vec::Vec;
13
14pub use deferred::session::{SessionInputError, WitnessLocation};
15use miden_core::deferred::PrecompileWitness;
16pub use miden_core::proof::{HashFunction, PrecompileProof, StarkProof};
17
18pub(crate) mod ec;
19pub(crate) mod hash;
20pub(crate) mod logup;
21pub(crate) mod math;
22pub(crate) mod primitives;
23pub(crate) mod relations;
24pub(crate) mod session;
25pub(crate) mod stark_config;
26pub(crate) mod transcript;
27pub(crate) mod uint;
28pub(crate) mod utils;
29
30/// Proves an owned batch of singleton execution obligations in one STARK.
31///
32/// The returned roots preserve input order and repetitions. Empty batches are rejected. The
33/// importer validates portable semantics and enforces batch-wide input and lowering limits.
34pub fn prove_precompiles(
35    witnesses: Vec<PrecompileWitness>,
36    hash_fn: HashFunction,
37) -> Result<PrecompileProof, PrecompileProvingError> {
38    deferred::session::prove(witnesses, hash_fn)
39}
40
41/// Errors produced while importing and proving portable precompile claims.
42#[derive(Debug, thiserror::Error)]
43pub enum PrecompileProvingError {
44    #[error(transparent)]
45    Input(#[from] SessionInputError),
46    #[error(transparent)]
47    Prove(#[from] ProveError),
48}
49
50/// Errors produced by serialized precompile STARK proof generation.
51#[derive(Debug, thiserror::Error)]
52pub enum ProveError {
53    /// The chiplet stack declares preprocessed columns, but no preprocessed
54    /// bundle was produced. This should not happen for the full session AIR set.
55    #[error("chiplet stack declares preprocessed columns, but no preprocessed bundle was built")]
56    MissingPreprocessed,
57    /// The preprocessed bundle did not match the declared AIR columns/config.
58    #[error(transparent)]
59    Preprocessed(#[from] miden_lifted_stark::PreprocessedValidationError),
60    /// The lifted STARK prover rejected the instance.
61    #[error(transparent)]
62    Prover(#[from] miden_lifted_stark::ProverError),
63    /// Failed to serialize the STARK proof data into the core proof envelope.
64    #[error("failed to serialize STARK proof: {0}")]
65    Serialization(#[from] wincode::error::WriteError),
66}
67
68pub(crate) mod deferred;
69
70#[cfg(test)]
71mod tests;