@@ -18,7 +18,8 @@ use crate::{
18
18
proof:: BundleProof ,
19
19
types:: BundleProvingTask ,
20
20
utils:: { force_to_read, try_to_read} ,
21
- BatchProof , BatchProvingTask , ChunkKind , ChunkProof , ParamsMap ,
21
+ BatchProofV2 , BatchProofV2Metadata , BatchProvingTask , ChunkKind , ChunkProof , ParamsMap ,
22
+ ProverError ,
22
23
} ;
23
24
24
25
/// Prover capable of generating [`BatchProof`] and [`BundleProof`].
@@ -129,15 +130,14 @@ impl<'params> Prover<'params> {
129
130
batch : BatchProvingTask ,
130
131
name : Option < & str > ,
131
132
output_dir : Option < & str > ,
132
- ) -> Result < BatchProof , BatchProverError > {
133
+ ) -> Result < BatchProofV2 , ProverError > {
133
134
// Denotes the identifier for this batch proving task. Eventually a generated proof is
134
135
// cached to disk using this identifier.
135
136
let name = name. map_or_else ( || batch. identifier ( ) , |name| name. to_string ( ) ) ;
136
137
137
138
// Return early if the batch proof was found on disk.
138
139
if let Some ( output_dir) = output_dir {
139
- if let Ok ( batch_proof) = BatchProof :: from_json_file ( output_dir, & name) {
140
- log:: info!( "batch proof found on disk! id={name}, path={output_dir}" ) ;
140
+ if let Ok ( batch_proof) = BatchProofV2 :: from_json ( output_dir, & name) {
141
141
return Ok ( batch_proof) ;
142
142
}
143
143
}
@@ -157,7 +157,7 @@ impl<'params> Prover<'params> {
157
157
layer3_snark,
158
158
output_dir,
159
159
)
160
- . map_err ( |e| e. to_string ( ) ) ?;
160
+ . map_err ( |e| BatchProverError :: Custom ( e. to_string ( ) ) ) ?;
161
161
log:: info!( "Got batch compression thin proof (layer-4): {name}" ) ;
162
162
163
163
// Sanity check on the layer-4 verifying key.
@@ -167,18 +167,13 @@ impl<'params> Prover<'params> {
167
167
let pk = self . prover_impl . pk ( LayerId :: Layer4 . id ( ) ) ;
168
168
169
169
// Build a wrapper around the layer-4 SNARK, aka batch proof.
170
- let batch_proof =
171
- BatchProof :: new ( layer4_snark, pk, batch_hash ) . map_err ( |e| e . to_string ( ) ) ?;
170
+ let batch_proof_metadata = BatchProofV2Metadata :: new ( & layer4_snark , batch_hash ) ? ;
171
+ let batch_proof = BatchProofV2 :: new ( layer4_snark, pk, batch_proof_metadata ) ?;
172
172
173
173
// If an output directory was provided, write the generated batch proof and layer-4
174
174
// verifying key to disk.
175
175
if let Some ( output_dir) = output_dir {
176
- batch_proof
177
- . dump_vk ( output_dir, "agg" )
178
- . map_err ( |e| e. to_string ( ) ) ?;
179
- batch_proof
180
- . dump ( output_dir, & name)
181
- . map_err ( |e| e. to_string ( ) ) ?;
176
+ batch_proof. dump ( output_dir, & name) ?;
182
177
}
183
178
184
179
Ok ( batch_proof)
@@ -196,7 +191,7 @@ impl<'params> Prover<'params> {
196
191
bundle : BundleProvingTask ,
197
192
name : Option < & str > ,
198
193
output_dir : Option < & str > ,
199
- ) -> Result < BundleProof , BatchProverError > {
194
+ ) -> Result < BundleProof , ProverError > {
200
195
// Denotes the identifier for this bundle proving task. Eventually a generated proof is
201
196
// written to disk using this name.
202
197
let name = name. map_or_else ( || bundle. identifier ( ) , |name| name. to_string ( ) ) ;
@@ -218,7 +213,7 @@ impl<'params> Prover<'params> {
218
213
& bundle_snarks,
219
214
output_dir,
220
215
)
221
- . map_err ( |e| e. to_string ( ) ) ?;
216
+ . map_err ( |e| BatchProverError :: Custom ( e. to_string ( ) ) ) ?;
222
217
223
218
// Load from disk or generate a layer-6 Compression Circuit SNARK. Since we use a Keccak
224
219
// hasher for the proof transcript at layer-6, the output proof is EVM-verifiable.
@@ -232,7 +227,7 @@ impl<'params> Prover<'params> {
232
227
layer5_snark,
233
228
output_dir,
234
229
)
235
- . map_err ( |e| e. to_string ( ) ) ?;
230
+ . map_err ( |e| BatchProverError :: Custom ( e. to_string ( ) ) ) ?;
236
231
237
232
// Sanity check for the layer-6 verifying key.
238
233
self . check_bundle_vk ( ) ?;
@@ -244,7 +239,7 @@ impl<'params> Prover<'params> {
244
239
if let Some ( output_dir) = output_dir {
245
240
bundle_proof
246
241
. dump ( output_dir, "recursion" )
247
- . map_err ( |e| e. to_string ( ) ) ?;
242
+ . map_err ( |e| BatchProverError :: Custom ( e. to_string ( ) ) ) ?;
248
243
}
249
244
250
245
Ok ( bundle_proof)
@@ -258,13 +253,14 @@ impl<'params> Prover<'params> {
258
253
batch : BatchProvingTask ,
259
254
name : & str ,
260
255
output_dir : Option < & str > ,
261
- ) -> Result < ( Snark , H256 ) , BatchProverError > {
256
+ ) -> Result < ( Snark , H256 ) , ProverError > {
262
257
// Early return with an error if the number of SNARKs to aggregate is not within limits.
263
258
let num_chunks = batch. chunk_proofs . len ( ) ;
264
259
if !( 1 ..=MAX_AGG_SNARKS ) . contains ( & num_chunks) {
265
260
return Err ( BatchProverError :: Custom ( format ! (
266
261
"1 <= num_chunks <= MAX_AGG_SNARKS, found={num_chunks}"
267
- ) ) ) ;
262
+ ) )
263
+ . into ( ) ) ;
268
264
}
269
265
270
266
// Sanity check on the chunk proof's SNARK protocols.
@@ -311,28 +307,32 @@ impl<'params> Prover<'params> {
311
307
return Err ( BatchProverError :: Custom ( format ! (
312
308
"BatchHeader(sanity) data_hash mismatch! expected={}, got={}" ,
313
309
batch. batch_header. data_hash, batch_header. data_hash
314
- ) ) ) ;
310
+ ) )
311
+ . into ( ) ) ;
315
312
}
316
313
// Batch's random challenge point (z) must match.
317
314
if batch_header. blob_data_proof [ 0 ] != batch. batch_header . blob_data_proof [ 0 ] {
318
315
return Err ( BatchProverError :: Custom ( format ! (
319
316
"BatchHeader(sanity) random challenge (z) mismatch! expected={}, got={}" ,
320
317
batch. batch_header. blob_data_proof[ 0 ] , batch_header. blob_data_proof[ 0 ] ,
321
- ) ) ) ;
318
+ ) )
319
+ . into ( ) ) ;
322
320
}
323
321
// Batch's evaluation at z, i.e. y, must match.
324
322
if batch_header. blob_data_proof [ 1 ] != batch. batch_header . blob_data_proof [ 1 ] {
325
323
return Err ( BatchProverError :: Custom ( format ! (
326
324
"BatchHeader(sanity) evaluation (y) mismatch! expected={}, got={}" ,
327
325
batch. batch_header. blob_data_proof[ 1 ] , batch_header. blob_data_proof[ 1 ] ,
328
- ) ) ) ;
326
+ ) )
327
+ . into ( ) ) ;
329
328
}
330
329
// The versioned hash of the blob that encodes the batch must match.
331
330
if batch_header. blob_versioned_hash != batch. batch_header . blob_versioned_hash {
332
331
return Err ( BatchProverError :: Custom ( format ! (
333
332
"BatchHeader(sanity) blob versioned_hash mismatch! expected={}, got={}" ,
334
333
batch. batch_header. blob_versioned_hash, batch_header. blob_versioned_hash,
335
- ) ) ) ;
334
+ ) )
335
+ . into ( ) ) ;
336
336
}
337
337
338
338
// Build relevant types that are used for batch circuit witness assignments.
@@ -342,13 +342,14 @@ impl<'params> Prover<'params> {
342
342
343
343
// Sanity check: validate that conditionally decoded blob should match batch data.
344
344
let batch_bytes = batch_data. get_batch_data_bytes ( ) ;
345
- let decoded_blob_bytes = decode_blob ( & batch. blob_bytes ) . map_err ( |e| e. to_string ( ) ) ?;
345
+ let decoded_blob_bytes =
346
+ decode_blob ( & batch. blob_bytes ) . map_err ( |e| BatchProverError :: Custom ( e. to_string ( ) ) ) ?;
346
347
if batch_bytes != decoded_blob_bytes {
347
348
return Err ( BatchProverError :: Custom ( format ! (
348
349
"BatchProvingTask(sanity) decoded blob bytes do not match batch bytes! len(expected)={}, len(got)={}" ,
349
350
decoded_blob_bytes. len( ) ,
350
351
batch_bytes. len( ) ,
351
- ) ) ) ;
352
+ ) ) . into ( ) ) ;
352
353
}
353
354
354
355
// Load from disk or generate the layer-3 SNARK using the batch circuit.
@@ -364,18 +365,15 @@ impl<'params> Prover<'params> {
364
365
& layer2_snarks,
365
366
output_dir,
366
367
)
367
- . map_err ( |e| e. to_string ( ) ) ?;
368
+ . map_err ( |e| BatchProverError :: Custom ( e. to_string ( ) ) ) ?;
368
369
369
370
Ok ( ( layer3_snark, batch_hash) )
370
371
}
371
372
372
373
/// Sanity check: validate that the SNARK [`protocol`][snark_verifier::Protocol] for the SNARKs
373
374
/// being aggregated by the [`BatchCircuit`][aggregator::BatchCircuit] match the expected SNARK
374
375
/// protocols conditional to the chunk proof generation route utilised, i.e. halo2 or sp1.
375
- fn check_protocol_of_chunks (
376
- & self ,
377
- chunk_proofs : & [ ChunkProof ] ,
378
- ) -> Result < ( ) , BatchProverError > {
376
+ fn check_protocol_of_chunks ( & self , chunk_proofs : & [ ChunkProof ] ) -> Result < ( ) , ProverError > {
379
377
for ( i, proof) in chunk_proofs. iter ( ) . enumerate ( ) {
380
378
let expected = match proof. chunk_kind {
381
379
ChunkKind :: Halo2 => & self . halo2_protocol ,
@@ -394,7 +392,8 @@ impl<'params> Prover<'params> {
394
392
i,
395
393
expected_digest,
396
394
found_digest,
397
- ) ) ;
395
+ )
396
+ . into ( ) ) ;
398
397
}
399
398
}
400
399
@@ -404,7 +403,7 @@ impl<'params> Prover<'params> {
404
403
/// Sanity check for the [`VerifyinKey`][halo2_proofs::plonk::VerifyingKey] used to generate
405
404
/// Layer-4 SNARK that is wrapped inside the [`BatchProof`]. The prover generated VK is
406
405
/// expected to match the VK used to initialise the prover.
407
- fn check_batch_vk ( & self ) -> Result < ( ) , BatchProverError > {
406
+ fn check_batch_vk ( & self ) -> Result < ( ) , ProverError > {
408
407
let layer = LayerId :: Layer4 ;
409
408
if let Some ( expected_vk) = self . raw_vk_batch . as_ref ( ) {
410
409
let base64_exp_vk = base64:: encode ( expected_vk) ;
@@ -421,10 +420,11 @@ impl<'params> Prover<'params> {
421
420
layer,
422
421
base64_gen_vk,
423
422
base64_exp_vk,
424
- ) ) ;
423
+ )
424
+ . into ( ) ) ;
425
425
}
426
426
} else {
427
- return Err ( BatchProverError :: VerifyingKeyNotFound ( layer, base64_exp_vk) ) ;
427
+ return Err ( BatchProverError :: VerifyingKeyNotFound ( layer, base64_exp_vk) . into ( ) ) ;
428
428
}
429
429
}
430
430
@@ -434,7 +434,7 @@ impl<'params> Prover<'params> {
434
434
/// Sanity check for the [`VerifyinKey`][halo2_proofs::plonk::VerifyingKey] used to generate
435
435
/// Layer-6 SNARK that is wrapped inside the [`BundleProof`]. The prover generated VK is
436
436
/// expected to match the VK used to initialise the prover.
437
- fn check_bundle_vk ( & self ) -> Result < ( ) , BatchProverError > {
437
+ fn check_bundle_vk ( & self ) -> Result < ( ) , ProverError > {
438
438
let layer = LayerId :: Layer6 ;
439
439
if let Some ( expected_vk) = self . raw_vk_bundle . as_ref ( ) {
440
440
let base64_exp_vk = base64:: encode ( expected_vk) ;
@@ -451,10 +451,11 @@ impl<'params> Prover<'params> {
451
451
layer,
452
452
base64_gen_vk,
453
453
base64_exp_vk,
454
- ) ) ;
454
+ )
455
+ . into ( ) ) ;
455
456
}
456
457
} else {
457
- return Err ( BatchProverError :: VerifyingKeyNotFound ( layer, base64_exp_vk) ) ;
458
+ return Err ( BatchProverError :: VerifyingKeyNotFound ( layer, base64_exp_vk) . into ( ) ) ;
458
459
}
459
460
}
460
461
0 commit comments