| 740 | >(&mut rng, max_size, None); |
| 741 | |
| 742 | fn check<R: RngCore>( |
| 743 | rng: &mut R, |
| 744 | set_size: u32, |
| 745 | pp: &SetCommitmentSRS<Bls12_381>, |
| 746 | trapdoor: &Fr, |
| 747 | ) { |
| 748 | let set = (0..set_size) |
| 749 | .map(|_| Fr::rand(rng)) |
| 750 | .collect::<BTreeSet<_>>(); |
| 751 | |
| 752 | let start = Instant::now(); |
| 753 | let (comm, o) = SetCommitment::new(rng, set.clone(), pp).unwrap(); |
| 754 | println!( |
| 755 | "Time to commit to set of size {}: {:?}", |
| 756 | set_size, |
| 757 | start.elapsed() |
| 758 | ); |
| 759 | |
| 760 | comm.open_set(&o, set.clone(), pp).unwrap(); |
| 761 | |
| 762 | // Commitment with given randomness |
| 763 | let r = Fr::rand(rng); |
| 764 | let P_r = pp.get_P1().mul(r).into_affine(); |
| 765 | |
| 766 | let start = Instant::now(); |
| 767 | let comm1 = SetCommitment::new_with_given_commitment_to_randomness( |
| 768 | P_r, |
| 769 | trapdoor, |
| 770 | set.clone(), |
| 771 | pp, |
| 772 | ) |
| 773 | .unwrap(); |
| 774 | println!( |
| 775 | "Time to commit to set of size {} when given commitment to randomness: {:?}", |
| 776 | set_size, |
| 777 | start.elapsed() |
| 778 | ); |
| 779 | |
| 780 | let o1 = SetCommitmentOpening::SetWithoutTrapdoor(r); |
| 781 | comm1.open_set(&o1, set.clone(), pp).unwrap(); |
| 782 | |
| 783 | // Randomize commitment and opening |
| 784 | let r = Fr::rand(rng); |
| 785 | let (comm, o) = comm.randomize(o, r); |
| 786 | comm.open_set(&o, set, pp).unwrap(); |
| 787 | |
| 788 | // Create a new set with trapdoor and check opening |
| 789 | let mut new_set = (0..set_size - 1) |
| 790 | .map(|_| Fr::rand(rng)) |
| 791 | .collect::<BTreeSet<_>>(); |
| 792 | new_set.insert(*trapdoor); |
| 793 | let (comm, o) = SetCommitment::new(rng, new_set.clone(), pp).unwrap(); |
| 794 | comm.open_set(&o, new_set.clone(), pp).unwrap(); |
| 795 | |
| 796 | // Randomize commitment and opening |
| 797 | let r = Fr::rand(rng); |
| 798 | let (comm, o) = comm.randomize(o, r); |
| 799 | comm.open_set(&o, new_set, pp).unwrap(); |