miden_ace_codegen/lib.rs
1//! ACE circuit codegen for Plonky3-based Miden AIRs.
2//!
3//! The pipeline is:
4//! 1. Capture AIR constraints into the `miden-constraint-compiler` IR.
5//! 2. Lower the constraint graph 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::ChipletsAir;
17//!
18//! let config = AceConfig { num_quotient_chunks: 8, layout: LayoutKind::Masm, num_airs: 1 };
19//! let circuit = build_ace_circuit_for_air(&ChipletsAir, config)?;
20//! ```
21//!
22//! Module map (data flow):
23//! - `pipeline`: public entry points that orchestrate layout + DAG + circuit emission.
24//! - `dag`: verifier-style DAG IR and lowering helpers.
25//! - `circuit`: off-VM circuit representation (inputs/constants/ops/root).
26//! - `layout`: READ-section layout and index mapping.
27//! - `encode`: ACE stream encoding + padding rules.
28//! - `randomness`: challenge input planning for layouts + DAG lowering.
29//! - `quotient`: barycentric quotient recomposition helpers (used by DAG + tests).
30
31// Core IR and lowering.
32mod circuit;
33mod dag;
34
35// Input layout and encoding.
36mod encode;
37mod layout;
38mod quotient;
39mod randomness;
40
41// High-level orchestration.
42mod pipeline;
43
44#[cfg(test)]
45mod tests;
46#[cfg(test)]
47mod unit_tests;
48
49/// Extension field degree (quadratic extension for Miden VM).
50pub const EXT_DEGREE: usize = 2;
51
52/// Errors returned by ACE codegen.
53#[derive(Debug, thiserror::Error)]
54pub enum AceError {
55 #[error("invalid input length: expected {expected}, got {got}")]
56 InvalidInputLength { expected: usize, got: usize },
57 #[error("invalid input layout: {message}")]
58 InvalidInputLayout { message: String },
59}
60
61#[cfg(any(test, feature = "testing"))]
62pub mod testing;
63
64/// Exposed for the lowering differential tests (`miden-air/tests/ace_codegen.rs`);
65/// production consumes the IR lowering through the pipeline.
66#[cfg(any(test, feature = "testing"))]
67pub use crate::dag::{PeriodicColumnData, build_verifier_dag, build_verifier_dag_from_ir};
68pub use crate::{
69 circuit::{AceCircuit, emit_circuit},
70 dag::{AceDag, DagBuilder, DagSnapshot, NodeId, NodeKind},
71 encode::EncodedCircuit,
72 layout::{InputCounts, InputKey, InputLayout},
73 pipeline::{
74 AceArtifacts, AceConfig, LayoutKind, build_ace_circuit_for_air, build_ace_dag_for_air,
75 build_multi_air_ace_circuit,
76 },
77};