@@ -11,10 +11,11 @@ use crate::{
11
11
circuit:: { calculate_row_usage_of_witness_block, chunk_trace_to_witness_block} ,
12
12
ChunkProverError , RowUsage ,
13
13
} ,
14
- ChunkProof ,
14
+ ChunkKind , ChunkProof ,
15
15
} ;
16
16
use aggregator:: ChunkInfo ;
17
17
use halo2_proofs:: { halo2curves:: bn256:: Bn256 , poly:: kzg:: commitment:: ParamsKZG } ;
18
+ use snark_verifier_sdk:: Snark ;
18
19
19
20
#[ derive( Debug ) ]
20
21
pub struct Prover < ' params > {
@@ -71,7 +72,7 @@ impl<'params> Prover<'params> {
71
72
/// If it is not set, default value(first block number of this chuk) will be used.
72
73
/// id:
73
74
/// TODO(zzhang). clean this. I think it can only be None or Some(0)...
74
- pub fn gen_chunk_proof (
75
+ pub fn gen_halo2_chunk_proof (
75
76
& mut self ,
76
77
chunk : ChunkProvingTask ,
77
78
chunk_id : Option < & str > ,
@@ -114,7 +115,7 @@ impl<'params> Prover<'params> {
114
115
snark,
115
116
self . prover_impl . pk ( LayerId :: Layer2 . id ( ) ) ,
116
117
chunk_info,
117
- chunk . chunk_kind ,
118
+ ChunkKind :: Halo2 ,
118
119
sub_circuit_row_usages,
119
120
) ;
120
121
@@ -128,7 +129,72 @@ impl<'params> Prover<'params> {
128
129
} ) ;
129
130
130
131
if let Some ( verifier) = & self . verifier {
131
- if !verifier. verify_chunk_proof ( chunk_proof. clone ( ) ) {
132
+ if !verifier. verify_chunk_proof ( & chunk_proof) {
133
+ return Err ( String :: from ( "chunk proof verification failed" ) . into ( ) ) ;
134
+ }
135
+ log:: info!( "chunk proof verified OK" ) ;
136
+ }
137
+
138
+ Ok ( chunk_proof)
139
+ }
140
+
141
+ /// Generates a chunk proof by compressing the provided SNARK. The generated proof uses the
142
+ /// [`CompressionCircuit`][aggregator::CompressionCircuit] to compress the supplied
143
+ /// [`SNARK`][snark_verifier_sdk::Snark] only once using thin-compression parameters.
144
+ ///
145
+ /// The [`ChunkProof`] represents the Layer-2 proof in Scroll's proving pipeline and the
146
+ /// generated SNARK can then be used as inputs to the [`BatchCircuit`][aggregator::BatchCircuit].
147
+ ///
148
+ /// This method should be used iff the input SNARK was generated from a halo2-backend for Sp1.
149
+ /// In order to construct a chunk proof via the halo2-based
150
+ /// [`SuperCircuit`][zkevm_circuits::super_circuit::SuperCircuit], please use [`gen_chunk_proof`][Self::gen_chunk_proof].
151
+ pub fn gen_sp1_chunk_proof (
152
+ & mut self ,
153
+ inner_snark : Snark ,
154
+ chunk : ChunkProvingTask ,
155
+ chunk_id : Option < & str > ,
156
+ output_dir : Option < & str > ,
157
+ ) -> Result < ChunkProof , ChunkProverError > {
158
+ assert ! ( !chunk. is_empty( ) ) ;
159
+
160
+ let chunk_id = chunk_id. map_or_else ( || chunk. identifier ( ) , |name| name. to_string ( ) ) ;
161
+
162
+ let snark = self
163
+ . prover_impl
164
+ . load_or_gen_comp_snark (
165
+ & chunk_id,
166
+ LayerId :: Layer2 . id ( ) ,
167
+ true ,
168
+ LayerId :: Layer2 . degree ( ) ,
169
+ inner_snark,
170
+ output_dir,
171
+ )
172
+ . map_err ( |e| ChunkProverError :: Custom ( e. to_string ( ) ) ) ?;
173
+
174
+ self . check_vk ( ) ;
175
+
176
+ let chunk_info = chunk. chunk_info . unwrap_or ( {
177
+ let witness_block = chunk_trace_to_witness_block ( chunk. block_traces ) ?;
178
+ ChunkInfo :: from_witness_block ( & witness_block, false )
179
+ } ) ;
180
+
181
+ let chunk_proof = ChunkProof :: new (
182
+ snark,
183
+ self . prover_impl . pk ( LayerId :: Layer2 . id ( ) ) ,
184
+ chunk_info,
185
+ ChunkKind :: Sp1 ,
186
+ vec ! [ ] , // no row usages for ChunkKind::Sp1
187
+ )
188
+ . map_err ( |e| ChunkProverError :: Custom ( e. to_string ( ) ) ) ?;
189
+
190
+ if let Some ( output_dir) = output_dir {
191
+ chunk_proof
192
+ . dump ( output_dir, & chunk_id)
193
+ . map_err ( |e| ChunkProverError :: Custom ( e. to_string ( ) ) ) ?;
194
+ }
195
+
196
+ if let Some ( verifier) = & self . verifier {
197
+ if !verifier. verify_chunk_proof ( & chunk_proof) {
132
198
return Err ( String :: from ( "chunk proof verification failed" ) . into ( ) ) ;
133
199
}
134
200
log:: info!( "chunk proof verified OK" ) ;
0 commit comments