openvm_continuations/circuit/root/
mod.rs1use std::sync::Arc;
2
3use itertools::Itertools;
4use openvm_circuit::system::memory::dimensions::MemoryDimensions;
5use openvm_recursion_circuit::{prelude::F, system::AggregationSubCircuit};
6use openvm_recursion_circuit_derive::AlignedBorrow;
7use openvm_stark_backend::{AirRef, StarkProtocolConfig};
8use openvm_stark_sdk::config::baby_bear_poseidon2::DIGEST_SIZE;
9
10use crate::{
11 circuit::{
12 root::bus::{DeferralAccPathBus, DeferralMerkleRootsBus},
13 subair::{HashSliceSubAir, MerkleRootBus, MerkleTreeInternalBus},
14 Circuit,
15 },
16 CommitBytes, VkCommitBytes,
17};
18
19pub mod bus;
20pub mod commit;
21pub mod def_paths;
22pub mod memory;
23pub mod verifier;
24
25#[cfg(feature = "root-prover")]
26mod trace;
27#[cfg(feature = "root-prover")]
28pub use trace::*;
29
30pub const USER_PVS_COMMIT_AIR_ID: usize = 1;
31pub const NUM_DIGESTS_IN_VM_COMMIT: usize = 6;
32
33#[derive(derive_new::new, Clone)]
34pub struct RootCircuit<S: AggregationSubCircuit> {
35 pub verifier_circuit: Arc<S>,
36 pub(crate) internal_recursive_vk_commit: VkCommitBytes,
37 pub(crate) def_hook_commit: Option<CommitBytes>,
38 pub(crate) memory_dimensions: MemoryDimensions,
39 pub(crate) num_user_pvs: usize,
40}
41
42impl<SC: StarkProtocolConfig<F = F>, S: AggregationSubCircuit> Circuit<SC> for RootCircuit<S> {
43 fn airs(&self) -> Vec<AirRef<SC>> {
44 let bus_inventory = self.verifier_circuit.bus_inventory();
45 let next_bus_idx = self.verifier_circuit.next_bus_idx();
46
47 let merkle_root_bus = MerkleRootBus::new(next_bus_idx);
48 let merkle_tree_internal_bus = MerkleTreeInternalBus::new(next_bus_idx + 1);
49 let memory_merkle_commit_bus = bus::MemoryMerkleCommitBus::new(next_bus_idx + 2);
50 let def_acc_paths_bus = DeferralAccPathBus::new(next_bus_idx + 3);
51 let memory_merkle_roots_bus = DeferralMerkleRootsBus::new(next_bus_idx + 4);
52
53 let verifier_pvs_air = verifier::RootVerifierPvsAir {
54 public_values_bus: bus_inventory.public_values_bus,
55 cached_commit_bus: bus_inventory.cached_commit_bus,
56 pre_hash_bus: bus_inventory.pre_hash_bus,
57 range_bus: bus_inventory.range_checker_bus,
58 poseidon2_compress_bus: bus_inventory.poseidon2_compress_bus,
59 memory_merkle_commit_bus,
60 def_acc_paths_bus,
61 def_merkle_roots_bus: memory_merkle_roots_bus,
62 hash_slice_subair: HashSliceSubAir {
63 compress_bus: bus_inventory.poseidon2_compress_bus,
64 permute_bus: bus_inventory.poseidon2_permute_bus,
65 },
66 expected_internal_recursive_vk_commit: self.internal_recursive_vk_commit,
67 expected_def_hook_commit: self.def_hook_commit,
68 };
69 let user_pvs_commit_air = commit::UserPvsCommitAir::new(
70 bus_inventory.poseidon2_compress_bus,
71 merkle_root_bus,
72 merkle_tree_internal_bus,
73 self.num_user_pvs,
74 );
75 let user_pvs_memory_air = memory::UserPvsInMemoryAir::new(
76 bus_inventory.poseidon2_compress_bus,
77 merkle_root_bus,
78 memory_merkle_commit_bus,
79 self.memory_dimensions,
80 self.num_user_pvs,
81 );
82 let acc_paths_air = self.def_hook_commit.map(|_| {
83 Arc::new(def_paths::DeferralAccMerklePathsAir::new(
84 bus_inventory.poseidon2_compress_bus,
85 def_acc_paths_bus,
86 memory_merkle_roots_bus,
87 self.memory_dimensions,
88 )) as AirRef<SC>
89 });
90
91 [Arc::new(verifier_pvs_air) as AirRef<SC>]
92 .into_iter()
93 .chain([Arc::new(user_pvs_commit_air) as AirRef<SC>])
94 .chain([Arc::new(user_pvs_memory_air) as AirRef<SC>])
95 .chain(self.verifier_circuit.airs())
96 .chain(acc_paths_air)
97 .collect_vec()
98 }
99}
100
101#[repr(C)]
102#[derive(AlignedBorrow, Debug)]
103pub struct RootVerifierPvs<F> {
104 pub app_exe_commit: [F; DIGEST_SIZE],
108 pub app_vm_commit: [F; DIGEST_SIZE],
111}