@@ -588,173 +588,78 @@ pub trait PolynomialCommitment<F: Field>: Sized {
588588 Ok ( true )
589589 }
590590
591- /// open but with individual challenges
592- /// the non-individual version `open` should call this method with
593- /// `opening_challenges = |pow| opening_challenge.pow(&[pow]);`,
594- /// i.e., the same impl as in MarlinKZG.
595- fn open_individual_opening_challenges < ' a > (
591+ /// batch_open with individual challenges
592+ fn batch_open_individual_opening_challenges < ' a > (
596593 ck : & Self :: CommitterKey ,
597594 labeled_polynomials : impl IntoIterator < Item = & ' a LabeledPolynomial < F > > ,
598595 commitments : impl IntoIterator < Item = & ' a LabeledCommitment < Self :: Commitment > > ,
599- point : F ,
600- opening_challenges : & dyn Fn ( usize ) -> F ,
596+ query_set : & QuerySet < F > ,
597+ opening_challenges : & dyn Fn ( u64 ) -> F ,
601598 rands : impl IntoIterator < Item = & ' a Self :: Randomness > ,
602599 rng : Option < & mut dyn RngCore > ,
603- ) -> Result < Self :: Proof , Self :: Error >
600+ ) -> Result < Self :: BatchProof , Self :: Error >
604601 where
605602 Self :: Randomness : ' a ,
606603 Self :: Commitment : ' a ,
607604 {
608- Self :: open (
609- ck,
610- labeled_polynomials,
611- commitments,
612- point,
613- opening_challenges ( 0 ) ,
614- rands,
615- rng,
616- )
617- }
605+ let rng = & mut crate :: optional_rng:: OptionalRng ( rng) ;
606+ let poly_rand_comm: BTreeMap < _ , _ > = labeled_polynomials
607+ . into_iter ( )
608+ . zip ( rands)
609+ . zip ( commitments. into_iter ( ) )
610+ . map ( |( ( poly, r) , comm) | ( poly. label ( ) , ( poly, r, comm) ) )
611+ . collect ( ) ;
618612
619- /// check but with individual challenges
620- /// The non-individual version `check` should call this method with
621- /// `opening_challenges = |pow| opening_challenge.pow(&[pow]);`,
622- /// i.e., the same impl as in MarlinKZG.
623- fn check_individual_opening_challenges < ' a > (
624- vk : & Self :: VerifierKey ,
625- commitments : impl IntoIterator < Item = & ' a LabeledCommitment < Self :: Commitment > > ,
626- point : F ,
627- values : impl IntoIterator < Item = F > ,
628- proof : & Self :: Proof ,
629- opening_challenges : & dyn Fn ( usize ) -> F ,
630- rng : Option < & mut dyn RngCore > ,
631- ) -> Result < bool , Self :: Error >
632- where
633- Self :: Commitment : ' a ,
634- {
635- Self :: check (
636- vk,
637- commitments,
638- point,
639- values,
640- proof,
641- opening_challenges ( 0 ) ,
642- rng,
643- )
644- }
613+ let open_time = start_timer ! ( || format!(
614+ "Opening {} polynomials at query set of size {}" ,
615+ poly_rand_comm. len( ) ,
616+ query_set. len( ) ,
617+ ) ) ;
645618
646- /// batch_check but with individual challenges
647- /// The non-individual version `batch_check` should call this method with
648- /// `opening_challenges = |pow| opening_challenge.pow(&[pow]);`,
649- /// i.e., the same impl as in MarlinKZG.
650- fn batch_check_individual_opening_challenges < ' a , R : RngCore > (
651- vk : & Self :: VerifierKey ,
652- commitments : impl IntoIterator < Item = & ' a LabeledCommitment < Self :: Commitment > > ,
653- query_set : & QuerySet < F > ,
654- evaluations : & Evaluations < F > ,
655- proof : & Self :: BatchProof ,
656- opening_challenges : & dyn Fn ( usize ) -> F ,
657- rng : & mut R ,
658- ) -> Result < bool , Self :: Error >
659- where
660- Self :: Commitment : ' a ,
661- {
662- Self :: batch_check (
663- vk,
664- commitments,
665- query_set,
666- evaluations,
667- proof,
668- opening_challenges ( 0 ) ,
669- rng,
670- )
671- }
619+ let mut query_to_labels_map = BTreeMap :: new ( ) ;
672620
673- /// open_combinations but with individual challenges
674- /// The non-individual version `open_combinations` should call this method with
675- /// `opening_challenges = |pow| opening_challenge.pow(&[pow]);`,
676- /// i.e., the same impl as in MarlinKZG.
677- fn open_combinations_individual_opening_challenges < ' a > (
678- ck : & Self :: CommitterKey ,
679- lc_s : impl IntoIterator < Item = & ' a LinearCombination < F > > ,
680- polynomials : impl IntoIterator < Item = & ' a LabeledPolynomial < F > > ,
681- commitments : impl IntoIterator < Item = & ' a LabeledCommitment < Self :: Commitment > > ,
682- query_set : & QuerySet < F > ,
683- opening_challenges : & dyn Fn ( usize ) -> F ,
684- rands : impl IntoIterator < Item = & ' a Self :: Randomness > ,
685- rng : Option < & mut dyn RngCore > ,
686- ) -> Result < BatchLCProof < F , Self > , Self :: Error >
687- where
688- Self :: Randomness : ' a ,
689- Self :: Commitment : ' a ,
690- {
691- Self :: open_combinations (
692- ck,
693- lc_s,
694- polynomials,
695- commitments,
696- query_set,
697- opening_challenges ( 0 ) ,
698- rands,
699- rng,
700- )
701- }
621+ for ( label, ( point_label, point) ) in query_set. iter ( ) {
622+ let labels = query_to_labels_map
623+ . entry ( point_label)
624+ . or_insert ( ( point, BTreeSet :: new ( ) ) ) ;
625+ labels. 1 . insert ( label) ;
626+ }
702627
703- /// check_combinations but with individual challenges
704- /// The non-individual version `check_combinations` should call this method with
705- /// `opening_challenges = |pow| opening_challenge.pow(&[pow]);`,
706- /// i.e., the same impl as in MarlinKZG.
707- fn check_combinations_individual_opening_challenges < ' a , R : RngCore > (
708- vk : & Self :: VerifierKey ,
709- lc_s : impl IntoIterator < Item = & ' a LinearCombination < F > > ,
710- commitments : impl IntoIterator < Item = & ' a LabeledCommitment < Self :: Commitment > > ,
711- query_set : & QuerySet < F > ,
712- evaluations : & Evaluations < F > ,
713- proof : & BatchLCProof < F , Self > ,
714- opening_challenges : & dyn Fn ( usize ) -> F ,
715- rng : & mut R ,
716- ) -> Result < bool , Self :: Error >
717- where
718- Self :: Commitment : ' a ,
719- {
720- Self :: check_combinations (
721- vk,
722- lc_s,
723- commitments,
724- query_set,
725- evaluations,
726- proof,
727- opening_challenges ( 0 ) ,
728- rng,
729- )
730- }
628+ let mut proofs = Vec :: new ( ) ;
629+ for ( _point_label, ( point, labels) ) in query_to_labels_map. into_iter ( ) {
630+ let mut query_polys: Vec < & ' a LabeledPolynomial < _ > > = Vec :: new ( ) ;
631+ let mut query_rands: Vec < & ' a Self :: Randomness > = Vec :: new ( ) ;
632+ let mut query_comms: Vec < & ' a LabeledCommitment < Self :: Commitment > > = Vec :: new ( ) ;
731633
732- /// batch_open but with individual challenges
733- /// The non-individual version `batch_open` should call this method with
734- /// `opening_challenges = |pow| opening_challenge.pow(&[pow]);`,
735- /// i.e., the same impl as in MarlinKZG.
736- fn batch_open_individual_opening_challenges < ' a > (
737- ck : & Self :: CommitterKey ,
738- labeled_polynomials : impl IntoIterator < Item = & ' a LabeledPolynomial < F > > ,
739- commitments : impl IntoIterator < Item = & ' a LabeledCommitment < Self :: Commitment > > ,
740- query_set : & QuerySet < F > ,
741- opening_challenges : & dyn Fn ( u64 ) -> F ,
742- rands : impl IntoIterator < Item = & ' a Self :: Randomness > ,
743- rng : Option < & mut dyn RngCore > ,
744- ) -> Result < Self :: BatchProof , Self :: Error >
745- where
746- Self :: Randomness : ' a ,
747- Self :: Commitment : ' a ,
748- {
749- Self :: batch_open (
750- ck,
751- labeled_polynomials,
752- commitments,
753- query_set,
754- opening_challenges ( 0 ) ,
755- rands,
756- rng,
757- )
634+ for label in labels {
635+ let ( polynomial, rand, comm) =
636+ poly_rand_comm. get ( label) . ok_or ( Error :: MissingPolynomial {
637+ label : label. to_string ( ) ,
638+ } ) ?;
639+
640+ query_polys. push ( polynomial) ;
641+ query_rands. push ( rand) ;
642+ query_comms. push ( comm) ;
643+ }
644+
645+ let proof_time = start_timer ! ( || "Creating proof" ) ;
646+ let proof = Self :: open_individual_opening_challenges (
647+ ck,
648+ query_polys,
649+ query_comms,
650+ * point,
651+ opening_challenges,
652+ query_rands,
653+ Some ( rng) ,
654+ ) ?;
655+
656+ end_timer ! ( proof_time) ;
657+
658+ proofs. push ( proof) ;
659+ }
660+ end_timer ! ( open_time) ;
661+
662+ Ok ( proofs. into ( ) )
758663 }
759664}
760665
0 commit comments