openvm_sdk/prover/
mod.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
use std::sync::Arc;

use openvm_circuit::arch::VmConfig;
use openvm_native_recursion::halo2::EvmProof;
use openvm_stark_sdk::openvm_stark_backend::Chip;

use crate::{keygen::AppProvingKey, stdin::StdIn, NonRootCommittedExe, F, SC};

mod agg;
pub use agg::*;
mod app;
pub use app::*;
use openvm_native_recursion::halo2::utils::Halo2ParamsReader;

mod halo2;
#[allow(unused_imports)]
pub use halo2::*;
mod root;
pub use root::*;
mod stark;
pub mod vm;

#[allow(unused_imports)]
pub use stark::*;

use crate::{
    keygen::AggProvingKey,
    prover::{halo2::Halo2Prover, stark::StarkProver},
};

pub struct ContinuationProver<VC> {
    stark_prover: StarkProver<VC>,
    halo2_prover: Halo2Prover,
}

impl<VC> ContinuationProver<VC> {
    pub fn new(
        reader: &impl Halo2ParamsReader,
        app_pk: Arc<AppProvingKey<VC>>,
        app_committed_exe: Arc<NonRootCommittedExe>,
        agg_pk: AggProvingKey,
    ) -> Self
    where
        VC: VmConfig<F>,
    {
        let AggProvingKey {
            agg_stark_pk,
            halo2_pk,
        } = agg_pk;
        let stark_prover = StarkProver::new(app_pk, app_committed_exe, agg_stark_pk);
        Self {
            stark_prover,
            halo2_prover: Halo2Prover::new(reader, halo2_pk),
        }
    }

    /// Flag for enabling/disabling profiling.
    pub fn set_profile(&mut self, profile: bool) -> &mut Self {
        self.stark_prover.set_profile(profile);
        // halo2 profiling is set in CompilerConfig when creating Halo2ProvingKey
        self
    }

    pub fn with_profiling(mut self) -> Self {
        self.set_profile(true);
        self
    }

    pub fn set_program_name(&mut self, program_name: impl AsRef<str>) -> &mut Self {
        self.stark_prover.set_program_name(program_name);
        self
    }

    pub fn generate_proof_for_evm(&self, input: StdIn) -> EvmProof
    where
        VC: VmConfig<F>,
        VC::Executor: Chip<SC>,
        VC::Periphery: Chip<SC>,
    {
        let root_proof = self.stark_prover.generate_proof_for_outer_recursion(input);
        self.halo2_prover.prove_for_evm(&root_proof)
    }
}