openvm_verify_stark_host/
pvs.rs

1use openvm_circuit_primitives::{StructReflection, StructReflectionHelper};
2use openvm_recursion_circuit_derive::AlignedBorrow;
3use openvm_stark_sdk::config::baby_bear_poseidon2::DIGEST_SIZE;
4use serde::{Deserialize, Serialize};
5
6pub const VERIFIER_PVS_AIR_ID: usize = 0;
7pub const VM_PVS_AIR_ID: usize = 1;
8pub const DEF_PVS_AIR_ID: usize = 2;
9pub const CONSTRAINT_EVAL_AIR_ID: usize = 3;
10
11pub const CONSTRAINT_EVAL_CACHED_INDEX: usize = 0;
12
13pub const LOG_MAX_RECURSION_DEPTH: u8 = 8;
14pub const MAX_RECURSION_DEPTH: u32 = 1 << LOG_MAX_RECURSION_DEPTH;
15
16#[repr(C)]
17#[derive(
18    AlignedBorrow, StructReflection, Clone, Copy, Debug, Serialize, Deserialize, PartialEq,
19)]
20pub struct VkCommit<F> {
21    /// Cached trace commit of this verifier circuit's SymbolicExpressionAir, which is derived
22    /// from its child_vk.
23    pub cached_commit: [F; DIGEST_SIZE],
24    /// Field pre_hash of the child MultiStarkVerifyingKey.
25    pub vk_pre_hash: [F; DIGEST_SIZE],
26}
27
28#[repr(C)]
29#[derive(AlignedBorrow, StructReflection, Clone, Copy)]
30pub struct VerifierBasePvs<F> {
31    //////////////////////////////////////////////////////////////////////
32    /// VERIFIER-SPECIFIC PVS
33    //////////////////////////////////////////////////////////////////////
34    /// Ternary flag to indicate which continuations layer this Proof is for. Should be 0 for
35    /// the leaf verifier, 1 for the internal-for-leaf verifier, and 2 for the internal-
36    /// recursive verifier.
37    pub internal_flag: F,
38    /// Commit to the app_vk's DAG and its pre-hash, first exposed by the leaf verifier.
39    pub app_vk_commit: VkCommit<F>,
40    /// Commit to the leaf_vk's DAG and its pre-hash, first exposed by the internal-for-leaf
41    /// verifier.
42    pub leaf_vk_commit: VkCommit<F>,
43    /// Commit to the internal_for_leaf_vk's DAG and its pre-hash, first exposed by the first
44    /// (i.e. index 0) internal-recursive layer verifier.
45    pub internal_for_leaf_vk_commit: VkCommit<F>,
46
47    //////////////////////////////////////////////////////////////////////
48    /// VERIFIER-SPECIFIC RECURSION PVS
49    //////////////////////////////////////////////////////////////////////
50    /// Depth of the internal-recursive layer this Proof is for: 0 for non-internal-recursive
51    /// layers, 1 for the first (i.e. index 0) internal-recursive layer, 2 for the second (i.e.
52    /// index 1) internal-recursive layer, and so on.
53    pub recursion_depth: F,
54    /// Commit to the internal_recursive_vk's DAG and its pre-hash, exposed by subsequent (i.e.
55    /// index > 0) internal-recursive layer verifiers.
56    pub internal_recursive_vk_commit: VkCommit<F>,
57}
58
59#[repr(C)]
60#[derive(AlignedBorrow, StructReflection, Clone, Copy)]
61pub struct VerifierDefPvs<F> {
62    //////////////////////////////////////////////////////////////////////
63    /// DEFERRAL-SPECIFIC PVS
64    //////////////////////////////////////////////////////////////////////
65    /// Ternary flag to indicate which public values this Proof contains. Should be 0 if it
66    /// has only VM public values defined, 1 if only deferral public values, and 2 if both.
67    pub deferral_flag: F,
68    /// Commit to the deferral hook verifying key, computed by hashing the cached_commit and
69    /// vk_pre_hash components of the app-or-deferral, leaf, and internal-for-leaf vk commits
70    /// when deferral_flag == 1. It is propagated unchanged once set.
71    pub def_hook_commit: [F; DIGEST_SIZE],
72}
73
74#[repr(C)]
75#[derive(AlignedBorrow, StructReflection, Clone, Copy)]
76pub struct VmPvs<F> {
77    //////////////////////////////////////////////////////////////////////
78    /// PROGRAM COMMIT PVS
79    //////////////////////////////////////////////////////////////////////
80    /// Cached trace commit of the app verifier circuit's ProgramAir.
81    pub program_commit: [F; DIGEST_SIZE],
82
83    //////////////////////////////////////////////////////////////////////
84    /// CONNECTOR PVS
85    //////////////////////////////////////////////////////////////////////
86    /// Starting PC value of the program (or segment) run.
87    pub initial_pc: F,
88    /// Final PC value of the program (or segment) run.
89    pub final_pc: F,
90    /// Exit code of the program run.
91    pub exit_code: F,
92    /// Boolean flag to determine whether or not this segment terminated the program.
93    pub is_terminate: F,
94
95    //////////////////////////////////////////////////////////////////////
96    /// MEMORY MERKLE PVS
97    //////////////////////////////////////////////////////////////////////
98    /// Merkle root commit of the starting memory state for this program (or segment).
99    pub initial_root: [F; DIGEST_SIZE],
100    /// Merkle root commit of the final memory state for this program (or segment).
101    pub final_root: [F; DIGEST_SIZE],
102}
103
104#[repr(C)]
105#[derive(AlignedBorrow, StructReflection, Clone, Copy)]
106pub struct DeferralPvs<F> {
107    /// Merkle root of all the initial hash accumulators for deferral circuit proofs that
108    /// have been aggregated up to this point.
109    pub initial_acc_hash: [F; DIGEST_SIZE],
110    /// Merkle root of all the final hash accumulators for deferral circuit proofs that
111    /// have been aggregated up to this point.
112    pub final_acc_hash: [F; DIGEST_SIZE],
113    /// Depth of the Merkle subtrees above.
114    pub depth: F,
115    /// Node index at the current depth of the deferral accumulator Merkle tree. Hook
116    /// proofs start at their def_idx; combined proofs end at node_idx 0.
117    pub node_idx: F,
118}