@@ -251,12 +251,6 @@ pub fn create_naive_threshold_sig_proof(
251
251
//Compute b as v-t and convert it to field element
252
252
let b = read_field_element_from_u64 ( valid_signatures - threshold) ;
253
253
254
- //Compute wcert_sysdata_hash
255
- let wcert_sysdata_hash = compute_wcert_sysdata_hash ( valid_signatures, & mr_bt, & prev_end_epoch_mc_b_hash, & end_epoch_mc_b_hash) ?;
256
-
257
- //Compute pks_threshold_hash
258
- let pks_threshold_hash = compute_pks_threshold_hash ( pks, threshold) ?;
259
-
260
254
//Convert affine pks to projective
261
255
let pks = pks. iter ( ) . map ( |& pk| pk. into_projective ( ) ) . collect :: < Vec < _ > > ( ) ;
262
256
@@ -265,8 +259,7 @@ pub fn create_naive_threshold_sig_proof(
265
259
266
260
let c = NaiveTresholdSignature :: < FieldElement > :: new (
267
261
pks, sigs, threshold, b, end_epoch_mc_b_hash,
268
- prev_end_epoch_mc_b_hash, mr_bt, pks_threshold_hash,
269
- wcert_sysdata_hash, max_pks,
262
+ prev_end_epoch_mc_b_hash, mr_bt, max_pks,
270
263
) ;
271
264
272
265
//Read proving key
@@ -278,48 +271,27 @@ pub fn create_naive_threshold_sig_proof(
278
271
Ok ( ( proof, valid_signatures) )
279
272
}
280
273
281
- //Return (wcert_sysdata_hash, pk_threshold_hash)
282
- pub fn get_public_inputs_for_naive_threshold_sig_proof (
283
- pks : & [ SchnorrPk ] ,
284
- threshold : u64 ,
274
+ pub fn verify_naive_threshold_sig_proof (
275
+ constant : & FieldElement ,
285
276
end_epoch_mc_b_hash : & [ u8 ; 32 ] ,
286
277
prev_end_epoch_mc_b_hash : & [ u8 ; 32 ] ,
287
278
bt_list : & [ BackwardTransfer ] ,
288
279
valid_sigs : u64 ,
289
- ) -> Result < ( FieldElement , FieldElement ) , Error > {
290
-
280
+ proof : & SCProof ,
281
+ vk_path : & str ,
282
+ ) -> Result < bool , Error >
283
+ {
284
+ //Compute wcert_sysdata_hash
291
285
let end_epoch_mc_b_hash = read_field_element_from_buffer_with_padding ( & end_epoch_mc_b_hash[ ..] ) ?;
292
286
let prev_end_epoch_mc_b_hash = read_field_element_from_buffer_with_padding ( & prev_end_epoch_mc_b_hash[ ..] ) ?;
293
287
let ( mr_bt, _) = compute_msg_to_sign ( & end_epoch_mc_b_hash, & prev_end_epoch_mc_b_hash, bt_list) ?;
294
288
let wcert_sysdata_hash = compute_wcert_sysdata_hash ( valid_sigs, & mr_bt, & prev_end_epoch_mc_b_hash, & end_epoch_mc_b_hash) ?;
295
- let pks_threshold_hash = compute_pks_threshold_hash ( pks , threshold ) ?;
289
+ let aggregated_input = compute_poseidon_hash ( & [ * constant , wcert_sysdata_hash ] ) ?;
296
290
297
- Ok ( ( wcert_sysdata_hash, pks_threshold_hash) )
298
- }
299
-
300
- pub fn verify_naive_threshold_sig_proof (
301
- pks : & [ SchnorrPk ] ,
302
- threshold : u64 ,
303
- end_epoch_mc_b_hash : & [ u8 ; 32 ] ,
304
- prev_end_epoch_mc_b_hash : & [ u8 ; 32 ] ,
305
- bt_list : & [ BackwardTransfer ] ,
306
- valid_sigs : u64 ,
307
- proof : SCProof ,
308
- vk_path : & str ,
309
- ) -> Result < bool , Error >
310
- {
311
291
//Verify proof
312
- let ( wcert_sysdata_hash, pks_threshold_hash) = get_public_inputs_for_naive_threshold_sig_proof (
313
- & pks,
314
- threshold,
315
- & end_epoch_mc_b_hash,
316
- & prev_end_epoch_mc_b_hash,
317
- bt_list,
318
- valid_sigs
319
- ) ?;
320
292
let vk = read_from_file ( vk_path) ?;
321
293
let pvk = prepare_verifying_key ( & vk) ; //Get verifying key
322
- let is_verified = verify_proof ( & pvk, & proof, & [ pks_threshold_hash , wcert_sysdata_hash ] ) ?;
294
+ let is_verified = verify_proof ( & pvk, & proof, & [ aggregated_input ] ) ?;
323
295
324
296
Ok ( is_verified)
325
297
}
@@ -387,7 +359,7 @@ pub fn vrf_proof_to_hash(msg: &FieldElement, pk: &VRFPk, proof: &VRFProof) -> Re
387
359
pub struct FieldBasedMerkleTreeParams ;
388
360
389
361
impl FieldBasedMerkleTreeConfig for FieldBasedMerkleTreeParams {
390
- const HEIGHT : usize = 9 ;
362
+ const HEIGHT : usize = 13 ;
391
363
type H = MNT4PoseidonHash ;
392
364
}
393
365
@@ -429,6 +401,21 @@ mod test {
429
401
Ok ( ( ) )
430
402
}
431
403
404
+ #[ allow( dead_code) ]
405
+ fn into_i8 ( v : Vec < u8 > ) -> Vec < i8 > {
406
+ // first, make sure v's destructor doesn't free the data
407
+ // it thinks it owns when it goes out of scope
408
+ let mut v = std:: mem:: ManuallyDrop :: new ( v) ;
409
+
410
+ // then, pick apart the existing Vec
411
+ let p = v. as_mut_ptr ( ) ;
412
+ let len = v. len ( ) ;
413
+ let cap = v. capacity ( ) ;
414
+
415
+ // finally, adopt the data into a new Vec
416
+ unsafe { Vec :: from_raw_parts ( p as * mut i8 , len, cap) }
417
+ }
418
+
432
419
#[ test]
433
420
fn create_sample_naive_threshold_sig_circuit ( ) {
434
421
//assume to have 3 pks, threshold = 2
@@ -478,6 +465,8 @@ mod test {
478
465
sigs. push ( None ) ;
479
466
sigs. push ( Some ( schnorr_sign ( & msg, & sks[ 2 ] , & pks[ 2 ] ) . unwrap ( ) ) ) ;
480
467
468
+ let constant = compute_pks_threshold_hash ( pks. as_slice ( ) , threshold) . unwrap ( ) ;
469
+
481
470
//Create and serialize proof
482
471
let ( proof, quality) = create_naive_threshold_sig_proof (
483
472
pks. as_slice ( ) ,
@@ -492,27 +481,27 @@ mod test {
492
481
write_to_file ( & proof, proof_path) . unwrap ( ) ;
493
482
494
483
//Verify proof
495
- let ( wcert_sysdata_hash, pks_threshold_hash) = get_public_inputs_for_naive_threshold_sig_proof (
496
- & pks,
497
- threshold,
484
+ assert ! ( verify_naive_threshold_sig_proof(
485
+ & constant,
498
486
& end_epoch_mc_b_hash,
499
487
& prev_end_epoch_mc_b_hash,
500
488
bt_list. as_slice( ) ,
501
- quality
502
- ) . unwrap ( ) ;
503
- let pvk = prepare_verifying_key ( & params . vk ) ; //Get verifying key
504
- assert ! ( verify_proof ( & pvk , & proof , & [ pks_threshold_hash , wcert_sysdata_hash ] ) . unwrap( ) ) ; //Assert proof verification passes
489
+ quality,
490
+ & proof ,
491
+ "./sample_vk" ,
492
+ ) . unwrap( ) ) ;
505
493
506
- //Generate wrong public inputs by changing threshold and valid sigs and assert proof verification doesn't pass
507
- let ( wrong_wcert_sysdata_hash , wrong_pks_threshold_hash ) = get_public_inputs_for_naive_threshold_sig_proof (
508
- & pks ,
509
- 1 ,
494
+
495
+ //Generate wrong public inputs by changing quality and assert proof verification doesn't pass
496
+ assert ! ( !verify_naive_threshold_sig_proof (
497
+ & constant ,
510
498
& end_epoch_mc_b_hash,
511
499
& prev_end_epoch_mc_b_hash,
512
500
bt_list. as_slice( ) ,
513
- quality - 1
514
- ) . unwrap ( ) ;
515
- assert ! ( !verify_proof( & pvk, & proof, & [ wrong_pks_threshold_hash, wrong_wcert_sysdata_hash] ) . unwrap( ) ) ; //Assert proof verification passes
501
+ quality - 1 ,
502
+ & proof,
503
+ "./sample_vk" ,
504
+ ) . unwrap( ) ) ;
516
505
}
517
506
518
507
#[ test]
0 commit comments