@@ -441,7 +441,6 @@ impl MPCParameters {
441
441
) -> [ u8 ; 64 ]
442
442
{
443
443
println ! ( "MPCParameters::contribute()" ) ;
444
- // Generate a keypair
445
444
let ( pubkey, privkey) = keypair ( rng, self ) ;
446
445
447
446
println ! ( "MPCParameters::batch_exp1()" ) ;
@@ -450,45 +449,56 @@ impl MPCParameters {
450
449
let coeff = coeff. into_repr ( ) ;
451
450
452
451
let mut projective = vec ! [ C :: Projective :: zero( ) ; bases. len( ) ] ;
453
- let cpus = num_cpus:: get ( ) ;
454
- let chunk_size = if bases. len ( ) < cpus {
455
- 1
456
- } else {
457
- bases. len ( ) / cpus
458
- } ;
459
-
460
- // Perform wNAF over multiple cores, placing results into `projective`.
461
- crossbeam:: scope ( |scope| {
462
- for ( bases, projective) in bases. chunks_mut ( chunk_size)
463
- . zip ( projective. chunks_mut ( chunk_size) )
464
- {
465
- scope. spawn ( move |_| {
466
- let mut wnaf = Wnaf :: new ( ) ;
467
- let mut count = 0 ;
468
- for ( base, projective) in bases. iter_mut ( )
469
- . zip ( projective. iter_mut ( ) )
470
- {
471
- * projective = wnaf. base ( base. into_projective ( ) , 1 ) . scalar ( coeff) ;
472
- count = count + 1 ;
473
- if * progress_update_interval > 0 && count % * progress_update_interval == 0 {
474
- println ! ( "progress {} {}" , * progress_update_interval, * total_exps)
475
- }
476
- }
477
- } ) ;
478
- }
479
- } ) . unwrap ( ) ;
480
-
481
- // Perform batch normalization
482
- crossbeam:: scope ( |scope| {
483
- for projective in projective. chunks_mut ( chunk_size)
484
- {
485
- scope. spawn ( move |_| {
486
- C :: Projective :: batch_normalization ( projective) ;
487
- } ) ;
488
- }
489
- } ) . unwrap ( ) ;
490
-
491
- // Turn it all back into affine points
452
+ // let cpus = num_cpus::get();
453
+ // let chunk_size = if bases.len() < cpus {
454
+ // 1
455
+ // } else {
456
+ // bases.len() / cpus
457
+ // };
458
+
459
+ // // Perform wNAF over multiple cores, placing results into `projective`.
460
+ // crossbeam::scope(|scope| {
461
+ // for (bases, projective) in bases.chunks_mut(chunk_size)
462
+ // .zip(projective.chunks_mut(chunk_size))
463
+ // {
464
+ // scope.spawn(move |_| {
465
+ // let mut wnaf = Wnaf::new();
466
+ // let mut count = 0;
467
+ // for (base, projective) in bases.iter_mut()
468
+ // .zip(projective.iter_mut())
469
+ // {
470
+ // *projective = wnaf.base(base.into_projective(), 1).scalar(coeff);
471
+ // count = count + 1;
472
+ // if *progress_update_interval > 0 && count % *progress_update_interval == 0 {
473
+ // println!("progress {} {}", *progress_update_interval, *total_exps)
474
+ // }
475
+ // }
476
+ // });
477
+ // }
478
+ // }).unwrap();
479
+
480
+ // // Perform batch normalization
481
+ // crossbeam::scope(|scope| {
482
+ // for projective in projective.chunks_mut(chunk_size)
483
+ // {
484
+ // scope.spawn(move |_| {
485
+ // C::Projective::batch_normalization(projective);
486
+ // });
487
+ // }
488
+ // }).unwrap();
489
+
490
+ let mut wnaf = Wnaf :: new ( ) ;
491
+ let mut count = 0 ;
492
+ for ( base, projective) in bases. iter_mut ( ) . zip ( projective. iter_mut ( ) ) {
493
+ * projective = wnaf. base ( base. into_projective ( ) , 1 ) . scalar ( coeff) ;
494
+ count += 1 ;
495
+ if * progress_update_interval > 0 && count % * progress_update_interval == 0 {
496
+ println ! ( "progress {} {}" , * progress_update_interval, * total_exps)
497
+ }
498
+ }
499
+
500
+ C :: Projective :: batch_normalization ( & mut projective) ;
501
+
492
502
for ( projective, affine) in projective. iter ( ) . zip ( bases. iter_mut ( ) ) {
493
503
* affine = projective. into_affine ( ) ;
494
504
}
@@ -755,128 +765,165 @@ pub fn verify_contribution(
755
765
after : & MPCParameters
756
766
) -> Result < [ u8 ; 64 ] , ( ) >
757
767
{
768
+ println ! ( "verify_contribution::1" ) ;
758
769
// Transformation involves a single new object
759
770
if after. contributions . len ( ) != ( before. contributions . len ( ) + 1 ) {
771
+ println ! ( "verify_contribution::1.1" ) ;
760
772
return Err ( ( ) ) ;
761
773
}
762
-
774
+ println ! ( "verify_contribution::2" ) ;
763
775
// None of the previous transformations should change
764
776
if & before. contributions [ ..] != & after. contributions [ 0 ..before. contributions . len ( ) ] {
777
+ println ! ( "verify_contribution::2.1" ) ;
765
778
return Err ( ( ) ) ;
766
779
}
767
-
780
+ println ! ( "verify_contribution::3" ) ;
768
781
// H/L will change, but should have same length
769
782
if before. params . h . len ( ) != after. params . h . len ( ) {
783
+ println ! ( "verify_contribution::3.1" ) ;
770
784
return Err ( ( ) ) ;
771
785
}
786
+ println ! ( "verify_contribution::4" ) ;
772
787
if before. params . l . len ( ) != after. params . l . len ( ) {
788
+ println ! ( "verify_contribution::4.1" ) ;
773
789
return Err ( ( ) ) ;
774
790
}
775
-
791
+ println ! ( "verify_contribution::5" ) ;
776
792
// A/B_G1/B_G2 doesn't change at all
777
793
if before. params . a != after. params . a {
794
+ println ! ( "verify_contribution::5.1" ) ;
778
795
return Err ( ( ) ) ;
779
796
}
797
+ println ! ( "verify_contribution:6" ) ;
780
798
if before. params . b_g1 != after. params . b_g1 {
799
+ println ! ( "verify_contribution::6.1" ) ;
781
800
return Err ( ( ) ) ;
782
801
}
802
+ println ! ( "verify_contribution::7" ) ;
783
803
if before. params . b_g2 != after. params . b_g2 {
804
+ println ! ( "verify_contribution::7.1" ) ;
784
805
return Err ( ( ) ) ;
785
806
}
786
-
807
+ println ! ( "verify_contribution::8" ) ;
787
808
// alpha/beta/gamma don't change
788
809
if before. params . vk . alpha_g1 != after. params . vk . alpha_g1 {
810
+ println ! ( "verify_contribution::8.1" ) ;
789
811
return Err ( ( ) ) ;
790
812
}
813
+ println ! ( "verify_contribution::9" ) ;
791
814
if before. params . vk . beta_g1 != after. params . vk . beta_g1 {
815
+ println ! ( "verify_contribution::9.1" ) ;
792
816
return Err ( ( ) ) ;
793
817
}
818
+ println ! ( "verify_contribution::10" ) ;
794
819
if before. params . vk . beta_g2 != after. params . vk . beta_g2 {
820
+ println ! ( "verify_contribution::10.1" ) ;
795
821
return Err ( ( ) ) ;
796
822
}
823
+ println ! ( "verify_contribution::11" ) ;
797
824
if before. params . vk . gamma_g2 != after. params . vk . gamma_g2 {
825
+ println ! ( "verify_contribution::11.1" ) ;
798
826
return Err ( ( ) ) ;
799
827
}
800
-
828
+ println ! ( "verify_contribution::12" ) ;
801
829
// IC shouldn't change, as gamma doesn't change
802
830
if before. params . vk . ic != after. params . vk . ic {
831
+ println ! ( "verify_contribution::12.1" ) ;
803
832
return Err ( ( ) ) ;
804
833
}
805
-
834
+ println ! ( "verify_contribution::13" ) ;
806
835
// cs_hash should be the same
807
836
if & before. cs_hash [ ..] != & after. cs_hash [ ..] {
837
+ println ! ( "verify_contribution::13.1" ) ;
808
838
return Err ( ( ) ) ;
809
839
}
810
-
840
+ println ! ( "verify_contribution::14" ) ;
811
841
let sink = io:: sink ( ) ;
842
+ println ! ( "verify_contribution::15" ) ;
812
843
let mut sink = HashWriter :: new ( sink) ;
844
+ println ! ( "verify_contribution::16" ) ;
813
845
sink. write_all ( & before. cs_hash [ ..] ) . unwrap ( ) ;
814
846
815
847
for pubkey in & before. contributions {
848
+ println ! ( "verify_contribution::17" ) ;
816
849
pubkey. write ( & mut sink) . unwrap ( ) ;
817
850
}
818
-
851
+ println ! ( "verify_contribution::18" ) ;
819
852
let pubkey = after. contributions . last ( ) . unwrap ( ) ;
853
+ println ! ( "verify_contribution::19" ) ;
820
854
sink. write_all ( pubkey. s . into_uncompressed ( ) . as_ref ( ) ) . unwrap ( ) ;
855
+ println ! ( "verify_contribution::20" ) ;
821
856
sink. write_all ( pubkey. s_delta . into_uncompressed ( ) . as_ref ( ) ) . unwrap ( ) ;
822
-
857
+ println ! ( "verify_contribution::21" ) ;
823
858
let h = sink. into_hash ( ) ;
824
-
859
+ println ! ( "verify_contribution::22" ) ;
825
860
// The transcript must be consistent
826
861
if & pubkey. transcript [ ..] != h. as_ref ( ) {
862
+ println ! ( "verify_contribution::22.1" ) ;
827
863
return Err ( ( ) ) ;
828
864
}
829
-
865
+ println ! ( "verify_contribution::23" ) ;
830
866
let r = hash_to_g2 ( h. as_ref ( ) ) . into_affine ( ) ;
831
-
867
+ println ! ( "verify_contribution::24" ) ;
832
868
// Check the signature of knowledge
833
869
if !same_ratio ( ( r, pubkey. r_delta ) , ( pubkey. s , pubkey. s_delta ) ) {
870
+ println ! ( "verify_contribution::24.1" ) ;
834
871
return Err ( ( ) ) ;
835
872
}
836
-
873
+ println ! ( "verify_contribution::25" ) ;
837
874
// Check the change from the old delta is consistent
838
875
if !same_ratio (
839
876
( before. params . vk . delta_g1 , pubkey. delta_after ) ,
840
877
( r, pubkey. r_delta )
841
878
) {
879
+ println ! ( "verify_contribution::25.1" ) ;
842
880
return Err ( ( ) ) ;
843
881
}
844
-
882
+ println ! ( "verify_contribution::26" ) ;
845
883
// Current parameters should have consistent delta in G1
846
884
if pubkey. delta_after != after. params . vk . delta_g1 {
885
+ println ! ( "verify_contribution::26.1" ) ;
847
886
return Err ( ( ) ) ;
848
887
}
849
-
888
+ println ! ( "verify_contribution::27" ) ;
850
889
// Current parameters should have consistent delta in G2
851
890
if !same_ratio (
852
891
( G1Affine :: one ( ) , pubkey. delta_after ) ,
853
892
( G2Affine :: one ( ) , after. params . vk . delta_g2 )
854
893
) {
894
+ println ! ( "verify_contribution::27.1" ) ;
855
895
return Err ( ( ) ) ;
856
896
}
857
-
897
+ println ! ( "verify_contribution::28" ) ;
858
898
// H and L queries should be updated with delta^-1
859
899
if !same_ratio (
860
900
merge_pairs ( & before. params . h , & after. params . h ) ,
861
901
( after. params . vk . delta_g2 , before. params . vk . delta_g2 ) // reversed for inverse
862
902
) {
903
+ println ! ( "verify_contribution::28.1" ) ;
863
904
return Err ( ( ) ) ;
864
905
}
865
-
906
+ println ! ( "verify_contribution::29" ) ;
866
907
if !same_ratio (
867
908
merge_pairs ( & before. params . l , & after. params . l ) ,
868
909
( after. params . vk . delta_g2 , before. params . vk . delta_g2 ) // reversed for inverse
869
910
) {
911
+ println ! ( "verify_contribution::29.1" ) ;
870
912
return Err ( ( ) ) ;
871
913
}
872
-
914
+ println ! ( "verify_contribution::30" ) ;
873
915
let sink = io:: sink ( ) ;
916
+ println ! ( "verify_contribution::31" ) ;
874
917
let mut sink = HashWriter :: new ( sink) ;
918
+ println ! ( "verify_contribution::32" ) ;
875
919
pubkey. write ( & mut sink) . unwrap ( ) ;
920
+ println ! ( "verify_contribution::33" ) ;
876
921
let h = sink. into_hash ( ) ;
922
+ println ! ( "verify_contribution::34" ) ;
877
923
let mut response = [ 0u8 ; 64 ] ;
924
+ println ! ( "verify_contribution::35" ) ;
878
925
response. copy_from_slice ( h. as_ref ( ) ) ;
879
-
926
+ println ! ( "verify_contribution::36" ) ;
880
927
Ok ( response)
881
928
}
882
929
0 commit comments