1
+ use std:: {
2
+ collections:: HashSet ,
3
+ fmt,
4
+ fs:: File ,
5
+ path:: { Path , PathBuf } ,
6
+ sync:: LazyLock ,
7
+ } ;
8
+
1
9
use crate :: utils:: read_env_var;
2
- use aggregator:: ConfigParams ;
3
- use std:: { collections:: HashSet , fmt, fs:: File , path:: Path , sync:: LazyLock } ;
4
10
11
+ /// Degree (k) used for the inner circuit, i.e.
12
+ /// [`SuperCircuit`][zkevm_circuits::super_circuit::SuperCircuit].
5
13
pub static INNER_DEGREE : LazyLock < u32 > =
6
14
LazyLock :: new ( || read_env_var ( "SCROLL_PROVER_INNER_DEGREE" , 20 ) ) ;
7
15
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" ) ) ) ;
10
19
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 > =
12
23
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 > =
14
28
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 > =
16
33
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 > =
18
38
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 > =
20
43
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 > =
22
48
LazyLock :: new ( || asset_file_path ( "layer6.config" ) ) ;
23
49
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 ) ) ;
30
61
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 ( || {
32
77
Vec :: from_iter ( HashSet :: from ( [
33
78
* INNER_DEGREE ,
34
79
* LAYER1_DEGREE ,
35
80
* LAYER2_DEGREE ,
36
81
] ) )
37
82
} ) ;
38
83
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 ( || {
40
87
Vec :: from_iter ( HashSet :: from ( [
41
88
* LAYER3_DEGREE ,
42
89
* LAYER4_DEGREE ,
@@ -45,6 +92,7 @@ pub static AGG_DEGREES: LazyLock<Vec<u32>> = LazyLock::new(|| {
45
92
] ) )
46
93
} ) ;
47
94
95
+ /// The various proof layers in the proof generation pipeline.
48
96
#[ derive( Clone , Copy , Debug ) ]
49
97
pub enum LayerId {
50
98
/// Super (inner) circuit layer
@@ -70,6 +118,7 @@ impl fmt::Display for LayerId {
70
118
}
71
119
72
120
impl LayerId {
121
+ /// Returns the identifier by layer.
73
122
pub fn id ( & self ) -> & str {
74
123
match self {
75
124
Self :: Inner => "inner" ,
@@ -82,6 +131,7 @@ impl LayerId {
82
131
}
83
132
}
84
133
134
+ /// The degree (k) for the [`Circuit`][halo2_proofs::plonk::Circuit] by layer.
85
135
pub fn degree ( & self ) -> u32 {
86
136
match self {
87
137
Self :: Inner => * INNER_DEGREE ,
@@ -94,43 +144,45 @@ impl LayerId {
94
144
}
95
145
}
96
146
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 {
98
150
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 ( ) ,
105
157
Self :: Inner => unreachable ! ( "No config file for super (inner) circuit" ) ,
106
158
}
107
159
}
108
160
}
109
161
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 {
118
166
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 ( ) ,
125
173
_ => panic ! ( "Wrong id-{id} to get layer config path" ) ,
126
174
}
127
175
}
128
176
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:?}" ) ) ;
131
183
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:? }" ) ) ;
134
186
135
187
params. degree
136
188
}
0 commit comments