Skip to content

Commit 8f17d50

Browse files
fixes
1 parent d04a9e9 commit 8f17d50

File tree

4 files changed

+73
-163
lines changed

4 files changed

+73
-163
lines changed

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ ark-relations = { git = "https://github.com/arkworks-rs/snark", default-features
3232

3333
ark-r1cs-std = { git = "https://github.com/arkworks-rs/r1cs-std" }
3434

35+
ark-nonnative-field = { git = "https://github.com/arkworks-rs/nonnative" }
36+
3537
bench-utils = { git = "https://github.com/arkworks-rs/utils", default-features = false }
3638

3739
rand_core = { version = "0.5", default-features = false }

src/lib.rs

+58-153
Original file line numberDiff line numberDiff line change
@@ -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

src/marlin_pc/constraints.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ where
13481348
let mut combined_queries = Vec::new();
13491349
let mut combined_comms = Vec::new();
13501350
let mut combined_evals = Vec::new();
1351-
for (_point_label, (point, labels)) in query_to_labels_map.into_iter() {
1351+
for (point_label, (point, labels)) in query_to_labels_map.into_iter() {
13521352
let mut comms_to_combine = Vec::<
13531353
Vec<(
13541354
Option<
@@ -1366,7 +1366,10 @@ where
13661366
for label in labels.into_iter() {
13671367
let commitment_lc = commitment_lcs.get(label).unwrap().clone();
13681368

1369-
let v_i = evaluations.0.get(&(label.clone(), point.clone())).unwrap();
1369+
let v_i = evaluations
1370+
.0
1371+
.get(&(label.clone(), point_label.clone()))
1372+
.unwrap();
13701373

13711374
comms_to_combine.push(commitment_lc.1.clone());
13721375
values_to_combine.push(v_i.clone());
@@ -1659,7 +1662,7 @@ where
16591662
let mut combined_queries = Vec::new();
16601663
let mut combined_comms = Vec::new();
16611664
let mut combined_evals = Vec::new();
1662-
for (_point_label, (point, labels)) in query_to_labels_map.into_iter() {
1665+
for (point_label, (point, labels)) in query_to_labels_map.into_iter() {
16631666
let mut comms_to_combine: Vec<Self::LabeledCommitmentVar> = Vec::new();
16641667
let mut values_to_combine = Vec::new();
16651668
for label in labels.into_iter() {
@@ -1670,7 +1673,10 @@ where
16701673
commitment.commitment.shifted_comm.is_some()
16711674
);
16721675

1673-
let v_i = evaluations.0.get(&(label.clone(), point.clone())).unwrap();
1676+
let v_i = evaluations
1677+
.0
1678+
.get(&(label.clone(), point_label.clone()))
1679+
.unwrap();
16741680

16751681
comms_to_combine.push(commitment.clone());
16761682
values_to_combine.push(v_i.clone());

src/pc_constraints.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,17 @@ pub struct QuerySetVar<TargetField: PrimeField, BaseField: PrimeField>(
166166
/// An allocated version of `Evaluations`.
167167
#[derive(Clone)]
168168
pub struct EvaluationsVar<TargetField: PrimeField, BaseField: PrimeField>(
169-
pub BTreeMap<
170-
(String, NonNativeFieldVar<TargetField, BaseField>),
171-
NonNativeFieldVar<TargetField, BaseField>,
172-
>,
169+
pub BTreeMap<(String, String), NonNativeFieldVar<TargetField, BaseField>>,
173170
);
174171

175172
impl<TargetField: PrimeField, BaseField: PrimeField> EvaluationsVar<TargetField, BaseField> {
176173
/// find the evaluation result
177174
pub fn get_lc_eval(
178175
&self,
179176
lc_string: &String,
180-
point: &NonNativeFieldVar<TargetField, BaseField>,
177+
point_label: &String,
181178
) -> Result<NonNativeFieldVar<TargetField, BaseField>, SynthesisError> {
182-
let key = (lc_string.clone(), point.clone());
179+
let key = (lc_string.clone(), point_label.clone());
183180
Ok(self.0.get(&key).map(|v| (*v).clone()).unwrap())
184181
}
185182
}

0 commit comments

Comments
 (0)