openvm_sdk/
config.rs

1use clap::Args;
2use openvm_sdk_config::SdkVmConfig;
3use openvm_stark_backend::SystemParams;
4use openvm_stark_sdk::config::{
5    app_params_with_100_bits_security, internal_params_with_100_bits_security,
6    leaf_params_with_100_bits_security, MAX_APP_LOG_STACKED_HEIGHT,
7};
8pub use openvm_stark_sdk::config::{
9    DEFAULT_APP_LOG_BLOWUP, DEFAULT_APP_L_SKIP, DEFAULT_INTERNAL_LOG_BLOWUP,
10    DEFAULT_LEAF_LOG_BLOWUP, DEFAULT_ROOT_LOG_BLOWUP,
11};
12use serde::{Deserialize, Serialize};
13
14// WARNING: These currently serve as both the DEFAULT and MAXIMUM number of
15// children for the leaf and internal aggregation layers, as the max number
16// of children is a const generic in the recursion circuit. We may change
17// these as needed, but note that a disparity in max and actual number of
18// leaf/internal children will cause a performance loss.
19pub const MAX_NUM_CHILDREN_LEAF: usize = 4;
20pub const MAX_NUM_CHILDREN_INTERNAL: usize = 3;
21
22fn default_system_params() -> SystemParams {
23    app_params_with_100_bits_security(MAX_APP_LOG_STACKED_HEIGHT)
24}
25
26#[derive(Clone, Debug, Serialize, Deserialize, derive_new::new)]
27pub struct AppConfig<VC> {
28    pub app_vm_config: VC,
29    #[serde(default = "default_system_params")]
30    pub system_params: SystemParams,
31}
32
33impl AppConfig<SdkVmConfig> {
34    pub fn standard(params: SystemParams) -> Self {
35        Self::new(SdkVmConfig::standard(), params)
36    }
37
38    pub fn riscv32(params: SystemParams) -> Self {
39        Self::new(SdkVmConfig::riscv32(), params)
40    }
41}
42
43#[derive(Clone, Debug, Default, Serialize, Deserialize)]
44pub struct AggregationConfig {
45    pub params: AggregationSystemParams,
46}
47
48#[derive(Clone, Debug, Serialize, Deserialize)]
49pub struct AggregationSystemParams {
50    pub leaf: SystemParams,
51    pub internal: SystemParams,
52}
53
54impl Default for AggregationSystemParams {
55    fn default() -> Self {
56        Self {
57            leaf: leaf_params_with_100_bits_security(),
58            internal: internal_params_with_100_bits_security(),
59        }
60    }
61}
62
63#[derive(Clone, Copy, Debug, Serialize, Deserialize, Args)]
64pub struct AggregationTreeConfig {
65    /// Each leaf verifier circuit will aggregate this many App VM proofs.
66    #[arg(
67        long,
68        default_value_t = MAX_NUM_CHILDREN_LEAF,
69        help = "Number of children per leaf verifier circuit",
70        help_heading = "Aggregation Tree Options"
71    )]
72    pub num_children_leaf: usize,
73    /// Each internal verifier circuit will aggregate this many proofs,
74    /// where each proof may be of either leaf or internal verifier (self) circuit.
75    #[arg(
76        long,
77        default_value_t = MAX_NUM_CHILDREN_INTERNAL,
78        help = "Number of children per internal verifier circuit",
79        help_heading = "Aggregation Tree Options"
80    )]
81    pub num_children_internal: usize,
82}
83
84impl Default for AggregationTreeConfig {
85    fn default() -> Self {
86        Self {
87            num_children_leaf: MAX_NUM_CHILDREN_LEAF,
88            num_children_internal: MAX_NUM_CHILDREN_INTERNAL,
89        }
90    }
91}
92
93impl AggregationTreeConfig {
94    pub const fn deferral() -> Self {
95        Self {
96            num_children_leaf: 2,
97            num_children_internal: 2,
98        }
99    }
100}
101
102/// Configuration for the Halo2 proving and wrapper keygen.
103#[cfg(feature = "evm-prove")]
104#[derive(Clone, Debug, Serialize, Deserialize)]
105pub struct Halo2Config {
106    /// The degree `k` for the wrapper circuit. If `None`, auto-tune to pick the
107    /// smallest `k` that results in a single advice column. Note: that `k` for
108    /// the verifier circuit is determined by StaticVerifierShape.
109    pub wrapper_k: Option<usize>,
110    /// Whether to collect detailed profiling metrics during proving.
111    pub profiling: bool,
112}