openvm_sdk/config/
mod.rs
1use openvm_circuit::arch::instructions::program::DEFAULT_MAX_NUM_PUBLIC_VALUES;
2use openvm_continuations::verifier::{
3 common::types::VmVerifierPvs, internal::types::InternalVmVerifierPvs,
4};
5use openvm_native_circuit::NativeConfig;
6use openvm_native_compiler::{conversion::CompilerOptions, ir::DIGEST_SIZE};
7use openvm_stark_sdk::config::FriParameters;
8use serde::{Deserialize, Serialize};
9
10mod global;
11pub use global::*;
12
13pub const DEFAULT_APP_LOG_BLOWUP: usize = 1;
14pub const DEFAULT_LEAF_LOG_BLOWUP: usize = 1;
15pub const DEFAULT_INTERNAL_LOG_BLOWUP: usize = 2;
16pub const DEFAULT_ROOT_LOG_BLOWUP: usize = 3;
17
18#[derive(Clone, Debug, Serialize, Deserialize)]
19pub struct AppConfig<VC> {
20 #[serde(default)]
21 pub app_fri_params: AppFriParams,
22 pub app_vm_config: VC,
23 #[serde(default)]
24 pub leaf_fri_params: LeafFriParams,
25 #[serde(default)]
27 pub compiler_options: CompilerOptions,
28}
29
30#[derive(Clone, Serialize, Deserialize)]
31pub struct AggConfig {
32 pub agg_stark_config: AggStarkConfig,
34 pub halo2_config: Halo2Config,
36}
37
38#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
39pub struct AggStarkConfig {
40 pub max_num_user_public_values: usize,
41 pub leaf_fri_params: FriParameters,
42 pub internal_fri_params: FriParameters,
43 pub root_fri_params: FriParameters,
44 pub profiling: bool,
46 pub compiler_options: CompilerOptions,
48 pub root_max_constraint_degree: usize,
50}
51
52#[derive(Clone, Serialize, Deserialize)]
53pub struct Halo2Config {
54 pub verifier_k: usize,
56 pub wrapper_k: Option<usize>,
58 pub profiling: bool,
60}
61
62impl<VC> AppConfig<VC> {
63 pub fn new(app_fri_params: FriParameters, app_vm_config: VC) -> Self {
64 Self {
65 app_fri_params: AppFriParams::from(app_fri_params),
66 app_vm_config,
67 leaf_fri_params: Default::default(),
68 compiler_options: Default::default(),
69 }
70 }
71
72 pub fn new_with_leaf_fri_params(
73 app_fri_params: FriParameters,
74 app_vm_config: VC,
75 leaf_fri_params: FriParameters,
76 ) -> Self {
77 Self {
78 app_fri_params: AppFriParams::from(app_fri_params),
79 app_vm_config,
80 leaf_fri_params: LeafFriParams::from(leaf_fri_params),
81 compiler_options: Default::default(),
82 }
83 }
84}
85
86impl Default for AggStarkConfig {
87 fn default() -> Self {
88 Self {
89 max_num_user_public_values: DEFAULT_MAX_NUM_PUBLIC_VALUES,
90 leaf_fri_params: FriParameters::standard_with_100_bits_conjectured_security(
91 DEFAULT_LEAF_LOG_BLOWUP,
92 ),
93 internal_fri_params: FriParameters::standard_with_100_bits_conjectured_security(
94 DEFAULT_INTERNAL_LOG_BLOWUP,
95 ),
96 root_fri_params: FriParameters::standard_with_100_bits_conjectured_security(
97 DEFAULT_ROOT_LOG_BLOWUP,
98 ),
99 profiling: false,
100 compiler_options: Default::default(),
101 root_max_constraint_degree: (1 << DEFAULT_ROOT_LOG_BLOWUP) + 1,
102 }
103 }
104}
105
106impl Default for AggConfig {
107 fn default() -> Self {
108 Self {
109 agg_stark_config: AggStarkConfig::default(),
110 halo2_config: Halo2Config {
111 verifier_k: 24,
112 wrapper_k: None,
113 profiling: false,
114 },
115 }
116 }
117}
118
119#[derive(Clone, Debug, Serialize, Deserialize)]
120pub struct AppFriParams {
121 pub fri_params: FriParameters,
122}
123
124impl Default for AppFriParams {
125 fn default() -> Self {
126 Self {
127 fri_params: FriParameters::standard_with_100_bits_conjectured_security(
128 DEFAULT_APP_LOG_BLOWUP,
129 ),
130 }
131 }
132}
133
134impl From<FriParameters> for AppFriParams {
135 fn from(fri_params: FriParameters) -> Self {
136 Self { fri_params }
137 }
138}
139
140#[derive(Clone, Debug, Serialize, Deserialize)]
141pub struct LeafFriParams {
142 pub fri_params: FriParameters,
143}
144
145impl Default for LeafFriParams {
146 fn default() -> Self {
147 Self {
148 fri_params: FriParameters::standard_with_100_bits_conjectured_security(
149 DEFAULT_LEAF_LOG_BLOWUP,
150 ),
151 }
152 }
153}
154
155impl From<FriParameters> for LeafFriParams {
156 fn from(fri_params: FriParameters) -> Self {
157 Self { fri_params }
158 }
159}
160
161const SBOX_SIZE: usize = 7;
162
163impl AggStarkConfig {
164 pub fn leaf_vm_config(&self) -> NativeConfig {
165 let mut config = NativeConfig::aggregation(
166 VmVerifierPvs::<u8>::width(),
167 SBOX_SIZE.min(self.leaf_fri_params.max_constraint_degree()),
168 );
169 config.system.profiling = self.profiling;
170 config
171 }
172 pub fn internal_vm_config(&self) -> NativeConfig {
173 let mut config = NativeConfig::aggregation(
174 InternalVmVerifierPvs::<u8>::width(),
175 SBOX_SIZE.min(self.internal_fri_params.max_constraint_degree()),
176 );
177 config.system.profiling = self.profiling;
178 config
179 }
180 pub fn root_verifier_vm_config(&self) -> NativeConfig {
181 let mut config = NativeConfig::aggregation(
182 DIGEST_SIZE * 2 + self.max_num_user_public_values,
184 SBOX_SIZE.min(self.root_fri_params.max_constraint_degree()),
185 );
186 config.system.profiling = self.profiling;
187 config
188 }
189}