Skip to main content

miden_ace_codegen/
lib.rs

1//! ACE circuit codegen for Plonky3-based Miden AIRs.
2//!
3//! The pipeline is:
4//! 1. Capture AIR constraints via plonky3's `SymbolicAirBuilder`.
5//! 2. Lower symbolic expressions into a DAG that mirrors verifier constraints evaluation.
6//! 3. Emit an ACE circuit plus an `InputLayout` describing the MASM ACE-READ section order.
7//!
8//! The resulting circuit is intended to run inside the recursive verifier. All
9//! input layout decisions (point-major OOD ordering, aux/quotient coords, and
10//! alpha/beta randomness expansion) are centralized in this crate so tests can
11//! validate both layout and evaluation.
12//!
13//! Quick start:
14//! ```ignore
15//! use miden_ace_codegen::{AceConfig, LayoutKind, build_ace_circuit_for_air};
16//! use miden_air::ProcessorAir;
17//! use miden_core::{Felt, field::QuadFelt};
18//!
19//! let config = AceConfig { num_quotient_chunks: 8, num_aux_inputs: 14, layout: LayoutKind::Masm };
20//! let circuit = build_ace_circuit_for_air::<_, Felt, QuadFelt>(&ProcessorAir, config)?;
21//! ```
22//!
23//! Module map (data flow):
24//! - `pipeline`: public entry points that orchestrate layout + DAG + circuit emission.
25//! - `dag`: verifier-style DAG IR and lowering helpers.
26//! - `circuit`: off-VM circuit representation (inputs/constants/ops/root).
27//! - `layout`: READ-section layout and index mapping.
28//! - `encode`: ACE stream encoding + padding rules.
29//! - `randomness`: challenge input planning for layouts + DAG lowering.
30//! - `quotient`: barycentric quotient recomposition helpers (used by DAG + tests).
31
32// Core IR and lowering.
33mod circuit;
34mod dag;
35
36// Input layout and encoding.
37mod encode;
38mod layout;
39mod quotient;
40mod randomness;
41
42// High-level orchestration.
43mod pipeline;
44
45#[cfg(test)]
46mod tests;
47#[cfg(test)]
48mod unit_tests;
49
50/// Extension field degree (quadratic extension for Miden VM).
51pub const EXT_DEGREE: usize = 2;
52
53/// Errors returned by ACE codegen.
54#[derive(Debug, thiserror::Error)]
55pub enum AceError {
56    #[error("invalid input length: expected {expected}, got {got}")]
57    InvalidInputLength { expected: usize, got: usize },
58    #[error("invalid input layout: {message}")]
59    InvalidInputLayout { message: String },
60}
61
62pub use crate::{
63    circuit::AceCircuit,
64    encode::EncodedCircuit,
65    layout::{InputCounts, InputKey, InputLayout},
66    pipeline::{AceConfig, LayoutKind, build_ace_circuit_for_air, build_layout_for_air},
67};