1+ use std:: {
2+ collections:: HashSet ,
3+ fmt,
4+ fs:: File ,
5+ path:: { Path , PathBuf } ,
6+ sync:: LazyLock ,
7+ } ;
8+
19use crate :: utils:: read_env_var;
2- use aggregator:: ConfigParams ;
3- use std:: { collections:: HashSet , fmt, fs:: File , path:: Path , sync:: LazyLock } ;
410
11+ /// Degree (k) used for the inner circuit, i.e.
12+ /// [`SuperCircuit`][zkevm_circuits::super_circuit::SuperCircuit].
513pub static INNER_DEGREE : LazyLock < u32 > =
614 LazyLock :: new ( || read_env_var ( "SCROLL_PROVER_INNER_DEGREE" , 20 ) ) ;
715
8- pub static ASSETS_DIR : LazyLock < String > =
9- LazyLock :: new ( || read_env_var ( "SCROLL_PROVER_ASSETS_DIR" , "configs" . to_string ( ) ) ) ;
16+ /// Name of the directory to find asset files on disk.
17+ pub static ASSETS_DIR : LazyLock < PathBuf > =
18+ LazyLock :: new ( || read_env_var ( "SCROLL_PROVER_ASSETS_DIR" , PathBuf :: from ( "configs" ) ) ) ;
1019
11- pub static LAYER1_CONFIG_PATH : LazyLock < String > =
20+ /// The path to the [`Config Parameters`][aggregator::ConfigParams] JSON file that define the shape
21+ /// of the [`Layer-1`][LayerId::Layer1] [`Circuit`][halo2_proofs::plonk::Circuit].
22+ pub static LAYER1_CONFIG_PATH : LazyLock < PathBuf > =
1223 LazyLock :: new ( || asset_file_path ( "layer1.config" ) ) ;
13- pub static LAYER2_CONFIG_PATH : LazyLock < String > =
24+
25+ /// The path to the [`Config Parameters`][aggregator::ConfigParams] JSON file that define the shape
26+ /// of the [`Layer-2`][LayerId::Layer2] [`Circuit`][halo2_proofs::plonk::Circuit].
27+ pub static LAYER2_CONFIG_PATH : LazyLock < PathBuf > =
1428 LazyLock :: new ( || asset_file_path ( "layer2.config" ) ) ;
15- pub static LAYER3_CONFIG_PATH : LazyLock < String > =
29+
30+ /// The path to the [`Config Parameters`][aggregator::ConfigParams] JSON file that define the shape
31+ /// of the [`Layer-3`][LayerId::Layer3] [`Circuit`][halo2_proofs::plonk::Circuit].
32+ pub static LAYER3_CONFIG_PATH : LazyLock < PathBuf > =
1633 LazyLock :: new ( || asset_file_path ( "layer3.config" ) ) ;
17- pub static LAYER4_CONFIG_PATH : LazyLock < String > =
34+
35+ /// The path to the [`Config Parameters`][aggregator::ConfigParams] JSON file that define the shape
36+ /// of the [`Layer-4`][LayerId::Layer4] [`Circuit`][halo2_proofs::plonk::Circuit].
37+ pub static LAYER4_CONFIG_PATH : LazyLock < PathBuf > =
1838 LazyLock :: new ( || asset_file_path ( "layer4.config" ) ) ;
19- pub static LAYER5_CONFIG_PATH : LazyLock < String > =
39+
40+ /// The path to the [`Config Parameters`][aggregator::ConfigParams] JSON file that define the shape
41+ /// of the [`Layer-5`][LayerId::Layer5] [`Circuit`][halo2_proofs::plonk::Circuit].
42+ pub static LAYER5_CONFIG_PATH : LazyLock < PathBuf > =
2043 LazyLock :: new ( || asset_file_path ( "layer5.config" ) ) ;
21- pub static LAYER6_CONFIG_PATH : LazyLock < String > =
44+
45+ /// The path to the [`Config Parameters`][aggregator::ConfigParams] JSON file that define the shape
46+ /// of the [`Layer-6`][LayerId::Layer6] [`Circuit`][halo2_proofs::plonk::Circuit].
47+ pub static LAYER6_CONFIG_PATH : LazyLock < PathBuf > =
2248 LazyLock :: new ( || asset_file_path ( "layer6.config" ) ) ;
2349
24- pub static LAYER1_DEGREE : LazyLock < u32 > = LazyLock :: new ( || layer_degree ( & LAYER1_CONFIG_PATH ) ) ;
25- pub static LAYER2_DEGREE : LazyLock < u32 > = LazyLock :: new ( || layer_degree ( & LAYER2_CONFIG_PATH ) ) ;
26- pub static LAYER3_DEGREE : LazyLock < u32 > = LazyLock :: new ( || layer_degree ( & LAYER3_CONFIG_PATH ) ) ;
27- pub static LAYER4_DEGREE : LazyLock < u32 > = LazyLock :: new ( || layer_degree ( & LAYER4_CONFIG_PATH ) ) ;
28- pub static LAYER5_DEGREE : LazyLock < u32 > = LazyLock :: new ( || layer_degree ( & LAYER5_CONFIG_PATH ) ) ;
29- pub static LAYER6_DEGREE : LazyLock < u32 > = LazyLock :: new ( || layer_degree ( & LAYER6_CONFIG_PATH ) ) ;
50+ /// The degree (k) for the halo2 [`Circuit`][halo2_proofs::plonk::Circuit] at
51+ /// [`Layer-1`][LayerId::Layer1].
52+ pub static LAYER1_DEGREE : LazyLock < u32 > = LazyLock :: new ( || layer_degree ( & * LAYER1_CONFIG_PATH ) ) ;
53+
54+ /// The degree (k) for the halo2 [`Circuit`][halo2_proofs::plonk::Circuit] at
55+ /// [`Layer-2`][LayerId::Layer2].
56+ pub static LAYER2_DEGREE : LazyLock < u32 > = LazyLock :: new ( || layer_degree ( & * LAYER2_CONFIG_PATH ) ) ;
57+
58+ /// The degree (k) for the halo2 [`Circuit`][halo2_proofs::plonk::Circuit] at
59+ /// [`Layer-3`][LayerId::Layer3].
60+ pub static LAYER3_DEGREE : LazyLock < u32 > = LazyLock :: new ( || layer_degree ( & * LAYER3_CONFIG_PATH ) ) ;
3061
31- pub static ZKEVM_DEGREES : LazyLock < Vec < u32 > > = LazyLock :: new ( || {
62+ /// The degree (k) for the halo2 [`Circuit`][halo2_proofs::plonk::Circuit] at
63+ /// [`Layer-4`][LayerId::Layer4].
64+ pub static LAYER4_DEGREE : LazyLock < u32 > = LazyLock :: new ( || layer_degree ( & * LAYER4_CONFIG_PATH ) ) ;
65+
66+ /// The degree (k) for the halo2 [`Circuit`][halo2_proofs::plonk::Circuit] at
67+ /// [`Layer-5`][LayerId::Layer5].
68+ pub static LAYER5_DEGREE : LazyLock < u32 > = LazyLock :: new ( || layer_degree ( & * LAYER5_CONFIG_PATH ) ) ;
69+
70+ /// The degree (k) for the halo2 [`Circuit`][halo2_proofs::plonk::Circuit] at
71+ /// [`Layer-6`][LayerId::Layer6].
72+ pub static LAYER6_DEGREE : LazyLock < u32 > = LazyLock :: new ( || layer_degree ( & * LAYER6_CONFIG_PATH ) ) ;
73+
74+ /// The list of degrees for Inner, Layer-1 and Layer-2, i.e. the proof generation [`layers`][LayerId]
75+ /// covered by the [`ChunkProver`][crate::ChunkProver].
76+ pub static CHUNK_PROVER_DEGREES : LazyLock < Vec < u32 > > = LazyLock :: new ( || {
3277 Vec :: from_iter ( HashSet :: from ( [
3378 * INNER_DEGREE ,
3479 * LAYER1_DEGREE ,
3580 * LAYER2_DEGREE ,
3681 ] ) )
3782} ) ;
3883
39- pub static AGG_DEGREES : LazyLock < Vec < u32 > > = LazyLock :: new ( || {
84+ /// The list of degrees for Layer-3, Layer-4, Layer-5 and Layer-6, i.e. the proof generation [`layers`][LayerId]
85+ /// covered by the [`BatchProver`][crate::BatchProver].
86+ pub static BATCH_PROVER_DEGREES : LazyLock < Vec < u32 > > = LazyLock :: new ( || {
4087 Vec :: from_iter ( HashSet :: from ( [
4188 * LAYER3_DEGREE ,
4289 * LAYER4_DEGREE ,
@@ -45,6 +92,7 @@ pub static AGG_DEGREES: LazyLock<Vec<u32>> = LazyLock::new(|| {
4592 ] ) )
4693} ) ;
4794
95+ /// The various proof layers in the proof generation pipeline.
4896#[ derive( Clone , Copy , Debug ) ]
4997pub enum LayerId {
5098 /// Super (inner) circuit layer
@@ -70,6 +118,7 @@ impl fmt::Display for LayerId {
70118}
71119
72120impl LayerId {
121+ /// Returns the identifier by layer.
73122 pub fn id ( & self ) -> & str {
74123 match self {
75124 Self :: Inner => "inner" ,
@@ -82,6 +131,7 @@ impl LayerId {
82131 }
83132 }
84133
134+ /// The degree (k) for the [`Circuit`][halo2_proofs::plonk::Circuit] by layer.
85135 pub fn degree ( & self ) -> u32 {
86136 match self {
87137 Self :: Inner => * INNER_DEGREE ,
@@ -94,43 +144,45 @@ impl LayerId {
94144 }
95145 }
96146
97- pub fn config_path ( & self ) -> & str {
147+ /// The path to the [`Config Parameters`][aggregator::ConfigParams] used to configure the shape
148+ /// of the [`Circuit`][halo2_proofs::plonk::Circuit].
149+ pub fn config_path ( & self ) -> PathBuf {
98150 match self {
99- Self :: Layer1 => & LAYER1_CONFIG_PATH ,
100- Self :: Layer2 => & LAYER2_CONFIG_PATH ,
101- Self :: Layer3 => & LAYER3_CONFIG_PATH ,
102- Self :: Layer4 => & LAYER4_CONFIG_PATH ,
103- Self :: Layer5 => & LAYER5_CONFIG_PATH ,
104- Self :: Layer6 => & LAYER6_CONFIG_PATH ,
151+ Self :: Layer1 => LAYER1_CONFIG_PATH . to_path_buf ( ) ,
152+ Self :: Layer2 => LAYER2_CONFIG_PATH . to_path_buf ( ) ,
153+ Self :: Layer3 => LAYER3_CONFIG_PATH . to_path_buf ( ) ,
154+ Self :: Layer4 => LAYER4_CONFIG_PATH . to_path_buf ( ) ,
155+ Self :: Layer5 => LAYER5_CONFIG_PATH . to_path_buf ( ) ,
156+ Self :: Layer6 => LAYER6_CONFIG_PATH . to_path_buf ( ) ,
105157 Self :: Inner => unreachable ! ( "No config file for super (inner) circuit" ) ,
106158 }
107159 }
108160}
109161
110- pub fn asset_file_path ( filename : & str ) -> String {
111- Path :: new ( & * ASSETS_DIR )
112- . join ( filename)
113- . to_string_lossy ( )
114- . into_owned ( )
115- }
116-
117- pub fn layer_config_path ( id : & str ) -> & str {
162+ /// Returns the path to the [`Config Parameters`][aggregator::ConfigParams] that configure the
163+ /// shape of the [`Circuit`][halo2_proofs::plonk::Circuit] given the [`id`][LayerId::id] of the
164+ /// layer.
165+ pub fn layer_config_path ( id : & str ) -> PathBuf {
118166 match id {
119- "layer1" => & LAYER1_CONFIG_PATH ,
120- "layer2" => & LAYER2_CONFIG_PATH ,
121- "layer3" => & LAYER3_CONFIG_PATH ,
122- "layer4" => & LAYER4_CONFIG_PATH ,
123- "layer5" => & LAYER5_CONFIG_PATH ,
124- "layer6" => & LAYER6_CONFIG_PATH ,
167+ "layer1" => LAYER1_CONFIG_PATH . to_path_buf ( ) ,
168+ "layer2" => LAYER2_CONFIG_PATH . to_path_buf ( ) ,
169+ "layer3" => LAYER3_CONFIG_PATH . to_path_buf ( ) ,
170+ "layer4" => LAYER4_CONFIG_PATH . to_path_buf ( ) ,
171+ "layer5" => LAYER5_CONFIG_PATH . to_path_buf ( ) ,
172+ "layer6" => LAYER6_CONFIG_PATH . to_path_buf ( ) ,
125173 _ => panic ! ( "Wrong id-{id} to get layer config path" ) ,
126174 }
127175}
128176
129- fn layer_degree ( config_file : & str ) -> u32 {
130- let f = File :: open ( config_file) . unwrap_or_else ( |_| panic ! ( "Failed to open {config_file}" ) ) ;
177+ fn asset_file_path ( filename : & str ) -> PathBuf {
178+ ASSETS_DIR . join ( filename)
179+ }
180+
181+ fn layer_degree < P : AsRef < Path > + fmt:: Debug > ( path : P ) -> u32 {
182+ let f = File :: open ( & path) . unwrap_or_else ( |_| panic ! ( "Failed to open {path:?}" ) ) ;
131183
132- let params: ConfigParams =
133- serde_json :: from_reader ( f ) . unwrap_or_else ( |_| panic ! ( "Failed to parse {config_file }" ) ) ;
184+ let params = serde_json :: from_reader :: < _ , aggregator :: ConfigParams > ( f )
185+ . unwrap_or_else ( |_| panic ! ( "Failed to parse {path:? }" ) ) ;
134186
135187 params. degree
136188}
0 commit comments