Skip to content

Commit fc880fd

Browse files
committed
wip
1 parent 6f3d3a3 commit fc880fd

File tree

1 file changed

+106
-59
lines changed

1 file changed

+106
-59
lines changed

phase2/src/parameters.rs

Lines changed: 106 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ impl MPCParameters {
441441
) -> [u8; 64]
442442
{
443443
println!("MPCParameters::contribute()");
444-
// Generate a keypair
445444
let (pubkey, privkey) = keypair(rng, self);
446445

447446
println!("MPCParameters::batch_exp1()");
@@ -450,45 +449,56 @@ impl MPCParameters {
450449
let coeff = coeff.into_repr();
451450

452451
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+
492502
for (projective, affine) in projective.iter().zip(bases.iter_mut()) {
493503
*affine = projective.into_affine();
494504
}
@@ -755,128 +765,165 @@ pub fn verify_contribution(
755765
after: &MPCParameters
756766
) -> Result<[u8; 64], ()>
757767
{
768+
println!("verify_contribution::1");
758769
// Transformation involves a single new object
759770
if after.contributions.len() != (before.contributions.len() + 1) {
771+
println!("verify_contribution::1.1");
760772
return Err(());
761773
}
762-
774+
println!("verify_contribution::2");
763775
// None of the previous transformations should change
764776
if &before.contributions[..] != &after.contributions[0..before.contributions.len()] {
777+
println!("verify_contribution::2.1");
765778
return Err(());
766779
}
767-
780+
println!("verify_contribution::3");
768781
// H/L will change, but should have same length
769782
if before.params.h.len() != after.params.h.len() {
783+
println!("verify_contribution::3.1");
770784
return Err(());
771785
}
786+
println!("verify_contribution::4");
772787
if before.params.l.len() != after.params.l.len() {
788+
println!("verify_contribution::4.1");
773789
return Err(());
774790
}
775-
791+
println!("verify_contribution::5");
776792
// A/B_G1/B_G2 doesn't change at all
777793
if before.params.a != after.params.a {
794+
println!("verify_contribution::5.1");
778795
return Err(());
779796
}
797+
println!("verify_contribution:6");
780798
if before.params.b_g1 != after.params.b_g1 {
799+
println!("verify_contribution::6.1");
781800
return Err(());
782801
}
802+
println!("verify_contribution::7");
783803
if before.params.b_g2 != after.params.b_g2 {
804+
println!("verify_contribution::7.1");
784805
return Err(());
785806
}
786-
807+
println!("verify_contribution::8");
787808
// alpha/beta/gamma don't change
788809
if before.params.vk.alpha_g1 != after.params.vk.alpha_g1 {
810+
println!("verify_contribution::8.1");
789811
return Err(());
790812
}
813+
println!("verify_contribution::9");
791814
if before.params.vk.beta_g1 != after.params.vk.beta_g1 {
815+
println!("verify_contribution::9.1");
792816
return Err(());
793817
}
818+
println!("verify_contribution::10");
794819
if before.params.vk.beta_g2 != after.params.vk.beta_g2 {
820+
println!("verify_contribution::10.1");
795821
return Err(());
796822
}
823+
println!("verify_contribution::11");
797824
if before.params.vk.gamma_g2 != after.params.vk.gamma_g2 {
825+
println!("verify_contribution::11.1");
798826
return Err(());
799827
}
800-
828+
println!("verify_contribution::12");
801829
// IC shouldn't change, as gamma doesn't change
802830
if before.params.vk.ic != after.params.vk.ic {
831+
println!("verify_contribution::12.1");
803832
return Err(());
804833
}
805-
834+
println!("verify_contribution::13");
806835
// cs_hash should be the same
807836
if &before.cs_hash[..] != &after.cs_hash[..] {
837+
println!("verify_contribution::13.1");
808838
return Err(());
809839
}
810-
840+
println!("verify_contribution::14");
811841
let sink = io::sink();
842+
println!("verify_contribution::15");
812843
let mut sink = HashWriter::new(sink);
844+
println!("verify_contribution::16");
813845
sink.write_all(&before.cs_hash[..]).unwrap();
814846

815847
for pubkey in &before.contributions {
848+
println!("verify_contribution::17");
816849
pubkey.write(&mut sink).unwrap();
817850
}
818-
851+
println!("verify_contribution::18");
819852
let pubkey = after.contributions.last().unwrap();
853+
println!("verify_contribution::19");
820854
sink.write_all(pubkey.s.into_uncompressed().as_ref()).unwrap();
855+
println!("verify_contribution::20");
821856
sink.write_all(pubkey.s_delta.into_uncompressed().as_ref()).unwrap();
822-
857+
println!("verify_contribution::21");
823858
let h = sink.into_hash();
824-
859+
println!("verify_contribution::22");
825860
// The transcript must be consistent
826861
if &pubkey.transcript[..] != h.as_ref() {
862+
println!("verify_contribution::22.1");
827863
return Err(());
828864
}
829-
865+
println!("verify_contribution::23");
830866
let r = hash_to_g2(h.as_ref()).into_affine();
831-
867+
println!("verify_contribution::24");
832868
// Check the signature of knowledge
833869
if !same_ratio((r, pubkey.r_delta), (pubkey.s, pubkey.s_delta)) {
870+
println!("verify_contribution::24.1");
834871
return Err(());
835872
}
836-
873+
println!("verify_contribution::25");
837874
// Check the change from the old delta is consistent
838875
if !same_ratio(
839876
(before.params.vk.delta_g1, pubkey.delta_after),
840877
(r, pubkey.r_delta)
841878
) {
879+
println!("verify_contribution::25.1");
842880
return Err(());
843881
}
844-
882+
println!("verify_contribution::26");
845883
// Current parameters should have consistent delta in G1
846884
if pubkey.delta_after != after.params.vk.delta_g1 {
885+
println!("verify_contribution::26.1");
847886
return Err(());
848887
}
849-
888+
println!("verify_contribution::27");
850889
// Current parameters should have consistent delta in G2
851890
if !same_ratio(
852891
(G1Affine::one(), pubkey.delta_after),
853892
(G2Affine::one(), after.params.vk.delta_g2)
854893
) {
894+
println!("verify_contribution::27.1");
855895
return Err(());
856896
}
857-
897+
println!("verify_contribution::28");
858898
// H and L queries should be updated with delta^-1
859899
if !same_ratio(
860900
merge_pairs(&before.params.h, &after.params.h),
861901
(after.params.vk.delta_g2, before.params.vk.delta_g2) // reversed for inverse
862902
) {
903+
println!("verify_contribution::28.1");
863904
return Err(());
864905
}
865-
906+
println!("verify_contribution::29");
866907
if !same_ratio(
867908
merge_pairs(&before.params.l, &after.params.l),
868909
(after.params.vk.delta_g2, before.params.vk.delta_g2) // reversed for inverse
869910
) {
911+
println!("verify_contribution::29.1");
870912
return Err(());
871913
}
872-
914+
println!("verify_contribution::30");
873915
let sink = io::sink();
916+
println!("verify_contribution::31");
874917
let mut sink = HashWriter::new(sink);
918+
println!("verify_contribution::32");
875919
pubkey.write(&mut sink).unwrap();
920+
println!("verify_contribution::33");
876921
let h = sink.into_hash();
922+
println!("verify_contribution::34");
877923
let mut response = [0u8; 64];
924+
println!("verify_contribution::35");
878925
response.copy_from_slice(h.as_ref());
879-
926+
println!("verify_contribution::36");
880927
Ok(response)
881928
}
882929

0 commit comments

Comments
 (0)