/// Combine and normalize a set of commitments
Combine and normalize a set of commitments
Combine and normalize a set of commitments
fn combine_and_normalize<'a, D: Clone + Ord + Sync>(
        commitments: impl IntoIterator<Item = &'a LabeledCommitment<marlin_pc::Commitment<E>>>,
        query_set: &QuerySet<D>,
        evaluations: &Evaluations<D, E::Fr>,
        opening_challenges: &mut ChallengeGenerator<E::Fr, S>,
        vk: Option<&marlin_pc::VerifierKey<E>>,
    ) -> Result<(Vec<kzg10::Commitment<E>>, Vec<D>, Vec<E::Fr>), Error>
    where
        marlin_pc::Commitment<E>: 'a,
    {
        let commitments: BTreeMap<_, _> = commitments.into_iter().map(|c| (c.label(), c)).collect();
        let mut query_to_labels_map = BTreeMap::new();
        for (label, (point_label, point)) in query_set.iter() {
            let labels = query_to_labels_map
                .entry(point_label)
                .or_insert((point, BTreeSet::new()));
            labels.1.insert(label);
        }
        let mut combined_comms = Vec::new();
        let mut combined_queries = Vec::new();
        let mut combined_evals = Vec::new();
        for (_, (point, labels)) in query_to_labels_map.into_iter() {
            let lc_time =
                start_timer!(|| format!("Randomly combining {} commitments", labels.len()));
            let mut comms_to_combine: Vec<&'_ LabeledCommitment<_>> = Vec::new();
            let mut values_to_combine = Vec::new();
            for label in labels.into_iter() {
                let commitment = commitments.get(label).ok_or(Error::MissingPolynomial {
                    label: label.to_string(),
                })?;
                let degree_bound = commitment.degree_bound();
                assert_eq!(
                    degree_bound.is_some(),
                    commitment.commitment().shifted_comm.is_some()
                );
                let v_i = evaluations.get(&(label.clone(), point.clone())).ok_or(
                    Error::MissingEvaluation {
                        label: label.to_string(),
                    },
                )?;
                comms_to_combine.push(commitment);
                values_to_combine.push(*v_i);
            }
            let (c, v) = Self::accumulate_commitments_and_values(
                comms_to_combine,
                values_to_combine,
                opening_challenges,
                vk,
            )?;
            end_timer!(lc_time);
            combined_comms.push(c);
            combined_queries.push(point.clone());
            combined_evals.push(v);
        }
        let norm_time = start_timer!(|| "Normalizing combined commitments");
        E::G1Projective::batch_normalization(&mut combined_comms);
        let combined_comms = combined_comms
            .into_iter()
            .map(|c| kzg10::Commitment(c.into()))
            .collect::<Vec<_>>();
        end_timer!(norm_time);
        Ok((combined_comms, combined_queries, combined_evals))
    }
fn combine_and_normalize < ' a , D : Clone + Ord + Sync > ( commitments : impl IntoIterator < Item = & ' a LabeledCommitment < marlin_pc :: Commitment < E > > > , query_set : & QuerySet < D > , evaluations : & Evaluations < D , E :: Fr > , opening_challenges : & mut ChallengeGenerator < E :: Fr , S > , vk : Option < & marlin_pc :: VerifierKey < E > > , ) -> Result < ( Vec < kzg10 :: Commitment < E > > , Vec < D > , Vec < E :: Fr > ) , Error > where marlin_pc :: Commitment < E > : ' a , { let commitments : BTreeMap < _ , _ > = commitments . into_iter ( ) . map ( | c | ( c . label ( ) , c ) ) . collect ( ) ; let mut query_to_labels_map = BTreeMap :: new ( ) ; for ( label , ( point_label , point ) ) in query_set . iter ( ) { let labels = query_to_labels_map . entry ( point_label ) . or_insert ( ( point , BTreeSet :: new ( ) ) ) ; labels . 1 . insert ( label ) ; } let mut combined_comms = Vec :: new ( ) ; let mut combined_queries = Vec :: new ( ) ; let mut combined_evals = Vec :: new ( ) ; for ( _ , ( point , labels ) ) in query_to_labels_map . into_iter ( ) { let lc_time = start_timer ! ( format ( " " labels len ( ) ) ) ; let mut comms_to_combine : Vec < & ' _ LabeledCommitment < _ > > = Vec :: new ( ) ; let mut values_to_combine = Vec :: new ( ) ; for label in labels . into_iter ( ) { let commitment = commitments . get ( label ) . ok_or ( Error :: MissingPolynomial { label : label . to_string ( ) , } ) ? ; let degree_bound = commitment . degree_bound ( ) ; assert_eq ! ( degree_bound is_some ( ) commitment commitment ( ) shifted_comm is_some ( ) ) ; let v_i = evaluations . get ( & ( label . clone ( ) , point . clone ( ) ) ) . ok_or ( Error :: MissingEvaluation { label : label . to_string ( ) , } , ) ? ; comms_to_combine . push ( commitment ) ; values_to_combine . push ( * v_i ) ; } let ( c , v ) = Self :: accumulate_commitments_and_values ( comms_to_combine , values_to_combine , opening_challenges , vk , ) ? ; end_timer ! ( lc_time ) ; combined_comms . push ( c ) ; combined_queries . push ( point . clone ( ) ) ; combined_evals . push ( v ) ; } let norm_time = start_timer ! ( " " ) ; E :: G1Projective :: batch_normalization ( & mut combined_comms ) ; let combined_comms = combined_comms . into_iter ( ) . map ( | c | kzg10 :: Commitment ( c . into ( ) ) ) . collect :: < Vec < _ > > ( ) ; end_timer ! ( norm_time ) ; Ok ( ( combined_comms , combined_queries , combined_evals ) ) }
Combine and normalize a set of commitments
Combine and normalize a set of commitments
commitments
impl IntoIterator<Item = &'a LabeledCommitment<marlin_pc::Commitment<E>>>
query_set
&QuerySet<D>
evaluations
&Evaluations<D, E::Fr>
opening_challenges
&mut ChallengeGenerator<E::Fr, S>
vk
Option<&marlin_pc::VerifierKey<E>>