MCPcopy Create free account
hub / github.com/docknetwork/crypto / commit_and_open_full

Function commit_and_open_full

delegatable_credentials/src/set_commitment.rs:734–807  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

732
733 #[test]
734 fn commit_and_open_full() {
735 let mut rng = StdRng::seed_from_u64(0u64);
736 let max_size = 10;
737 let (srs, td) = SetCommitmentSRS::<Bls12_381>::generate_with_random_trapdoor::<
738 StdRng,
739 Blake2b512,
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<_>>();

Callers

nothing calls this directly

Calls 1

checkFunction · 0.70

Tested by

no test coverage detected