openvm_sdk/prover/
stark.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::sync::Arc;

use openvm_circuit::arch::VmConfig;
use openvm_stark_backend::{prover::types::Proof, Chip};

use crate::{
    keygen::{AggStarkProvingKey, AppProvingKey},
    prover::{agg::AggStarkProver, app::AppProver},
    NonRootCommittedExe, RootSC, StdIn, F, SC,
};

pub struct StarkProver<VC> {
    app_prover: AppProver<VC>,
    agg_prover: AggStarkProver,
}
impl<VC> StarkProver<VC> {
    pub fn new(
        app_pk: Arc<AppProvingKey<VC>>,
        app_committed_exe: Arc<NonRootCommittedExe>,
        agg_stark_pk: AggStarkProvingKey,
    ) -> Self
    where
        VC: VmConfig<F>,
    {
        assert_eq!(
            app_pk.leaf_fri_params, agg_stark_pk.leaf_vm_pk.fri_params,
            "App VM is incompatible with Agg VM because of leaf FRI parameters"
        );
        assert_eq!(
            app_pk.app_vm_pk.vm_config.system().num_public_values,
            agg_stark_pk.num_public_values(),
            "App VM is incompatible with Agg VM  because of the number of public values"
        );

        Self {
            app_prover: AppProver::new(app_pk.app_vm_pk.clone(), app_committed_exe),
            agg_prover: AggStarkProver::new(agg_stark_pk, app_pk.leaf_committed_exe.clone()),
        }
    }
    pub fn set_program_name(&mut self, program_name: impl AsRef<str>) -> &mut Self {
        self.app_prover.set_program_name(program_name);
        self
    }
    pub fn generate_proof_for_outer_recursion(&self, input: StdIn) -> Proof<RootSC>
    where
        VC: VmConfig<F>,
        VC::Executor: Chip<SC>,
        VC::Periphery: Chip<SC>,
    {
        let app_proof = self.app_prover.generate_app_proof(input);
        self.agg_prover.generate_agg_proof(app_proof)
    }
}