MCPcopy Create free account
hub / github.com/arkworks-rs/poly-commit / accumulate_elems

Method accumulate_elems

poly-commit/src/sonic_pc/mod.rs:39–92  ·  view source on GitHub ↗
(
        combined_comms: &mut BTreeMap<Option<usize>, E::G1>,
        combined_witness: &mut E::G1,
        combined_adjusted_witness: &mut E::G1,
        vk: &VerifierKey<E>,
        commitments: im

Source from the content-addressed store, hash-verified

37 P: DenseUVPolynomial<E::ScalarField>,
38{
39 fn accumulate_elems<'a>(
40 combined_comms: &mut BTreeMap<Option<usize>, E::G1>,
41 combined_witness: &mut E::G1,
42 combined_adjusted_witness: &mut E::G1,
43 vk: &VerifierKey<E>,
44 commitments: impl IntoIterator<Item = &'a LabeledCommitment<Commitment<E>>>,
45 point: P::Point,
46 values: impl IntoIterator<Item = E::ScalarField>,
47 proof: &kzg10::Proof<E>,
48 sponge: &mut impl CryptographicSponge,
49 randomizer: Option<E::ScalarField>,
50 ) {
51 let acc_time = start_timer!(|| "Accumulating elements");
52
53 let mut curr_challenge = sponge.squeeze_field_elements_with_sizes(&[CHALLENGE_SIZE])[0];
54
55 // Keeps track of running combination of values
56 let mut combined_values = E::ScalarField::zero();
57
58 // Iterates through all of the commitments and accumulates common degree_bound elements in a BTreeMap
59 for (labeled_comm, value) in commitments.into_iter().zip(values) {
60 combined_values += &(value * &curr_challenge);
61
62 let comm = labeled_comm.commitment();
63 let degree_bound = labeled_comm.degree_bound();
64
65 // Applying opening challenge and randomness (used in batch_checking)
66 let mut comm_with_challenge: E::G1 = comm.0.mul(curr_challenge);
67
68 if let Some(randomizer) = randomizer {
69 comm_with_challenge = comm_with_challenge.mul(&randomizer);
70 }
71
72 // Accumulate values in the BTreeMap
73 *combined_comms.entry(degree_bound).or_insert(E::G1::zero()) += &comm_with_challenge;
74 curr_challenge = sponge.squeeze_field_elements_with_sizes(&[CHALLENGE_SIZE])[0];
75 }
76
77 // Push expected results into list of elems. Power will be the negative of the expected power
78 let mut witness: E::G1 = proof.w.into_group();
79 let mut adjusted_witness = vk.g.mul(combined_values) - &proof.w.mul(point);
80 if let Some(random_v) = proof.random_v {
81 adjusted_witness += &vk.gamma_g.mul(random_v);
82 }
83
84 if let Some(randomizer) = randomizer {
85 witness = proof.w.mul(randomizer);
86 adjusted_witness = adjusted_witness.mul(&randomizer);
87 }
88
89 *combined_witness += &witness;
90 *combined_adjusted_witness += &adjusted_witness;
91 end_timer!(acc_time);
92 }
93
94 fn check_elems(
95 combined_comms: BTreeMap<Option<usize>, E::G1>,

Callers

nothing calls this directly

Calls 3

commitmentMethod · 0.80
degree_boundMethod · 0.80
entryMethod · 0.80

Tested by

no test coverage detected