openvm_continuations/verifier/internal/
vars.rs

1use std::array;
2
3use openvm_native_compiler::{ir::DIGEST_SIZE, prelude::*};
4use openvm_native_recursion::{hints::Hintable, vars::StarkProofVariable};
5use openvm_stark_sdk::openvm_stark_backend::proof::Proof;
6
7use crate::{
8    verifier::{
9        internal::types::{InternalVmVerifierInput, VmStarkProof},
10        utils::write_field_slice,
11    },
12    C, F, SC,
13};
14
15#[derive(DslVariable, Clone)]
16pub struct InternalVmVerifierInputVariable<C: Config> {
17    pub self_program_commit: [Felt<C::F>; DIGEST_SIZE],
18    /// The proofs of the execution segments in the execution order.
19    pub proofs: Array<C, StarkProofVariable<C>>,
20}
21
22#[derive(DslVariable, Clone)]
23pub struct E2eStarkProofVariable<C: Config> {
24    pub proof: StarkProofVariable<C>,
25    pub user_public_values: Array<C, Felt<C::F>>,
26}
27
28impl Hintable<C> for InternalVmVerifierInput<SC> {
29    type HintVariable = InternalVmVerifierInputVariable<C>;
30
31    fn read(builder: &mut Builder<C>) -> Self::HintVariable {
32        let self_program_commit = array::from_fn(|_| builder.hint_felt());
33        let proofs = Vec::<Proof<SC>>::read(builder);
34        Self::HintVariable {
35            self_program_commit,
36            proofs,
37        }
38    }
39
40    fn write(&self) -> Vec<Vec<<C as Config>::N>> {
41        let mut stream = write_field_slice(&self.self_program_commit);
42        stream.extend(self.proofs.write());
43        stream
44    }
45}
46
47impl Hintable<C> for VmStarkProof<SC> {
48    type HintVariable = E2eStarkProofVariable<C>;
49
50    fn read(builder: &mut Builder<C>) -> Self::HintVariable {
51        let proof = Proof::<SC>::read(builder);
52        let user_public_values = Vec::<F>::read(builder);
53        Self::HintVariable {
54            proof,
55            user_public_values,
56        }
57    }
58
59    fn write(&self) -> Vec<Vec<<C as Config>::N>> {
60        let mut stream = self.inner.write();
61        stream.extend(self.user_public_values.write());
62        stream
63    }
64}