Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brakedown++ #44

Merged
merged 31 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
407acb9
Add the trait bounds
autquis Oct 26, 2023
cb65aef
Add `CommitmentState`
autquis Nov 1, 2023
85c8915
Update benches for the new type
autquis Nov 1, 2023
4ee97d4
Fix the name of local variable
autquis Nov 1, 2023
fb68290
Merge `PCCommitmentState` with `PCRandomness`
autquis Nov 13, 2023
14573b3
Update `README.md`
autquis Nov 13, 2023
5a5993e
Fix a bug
autquis Nov 13, 2023
e1d21cf
Merge with aux-data
autquis Nov 13, 2023
4283396
Complete the merge
autquis Nov 13, 2023
ade7ef2
Simplify `hash_column`
autquis Nov 13, 2023
a6d8044
Delete comments
autquis Nov 13, 2023
875ab60
Add `CommitmentState`
autquis Nov 13, 2023
31643f3
Make `fmt` happy
autquis Nov 13, 2023
80f44ca
Refactor, remove `hash_columns`
autquis Nov 13, 2023
890b4b1
Rename all params
autquis Nov 13, 2023
b00defd
remove cfg(benches) attributes as that feature is no longer used
mmagician Nov 14, 2023
2b403fd
Brakedown+++ (#46)
mmagician Nov 14, 2023
69b5402
Maybe `empty` not return `Self`
autquis Nov 15, 2023
1aa03a9
Make `empty` return `Self`
autquis Nov 15, 2023
c9032c1
Rename `rand` to `state`
autquis Nov 15, 2023
156c9ea
Merge branch 'try-self' into brakedown-pp
autquis Nov 15, 2023
7c5435e
Add the type `Randomness`
autquis Nov 15, 2023
ae5d8f4
Rename nonnative to emulated, as in `r1cs-std` (#137)
autquis Jan 9, 2024
3291693
Substitute `ChallengeGenerator` by the generic sponge (#139)
autquis Jan 14, 2024
36dcf5e
Fix according to breaking changes in `ark-ec` (#141)
autquis Jan 15, 2024
f6a0c13
Auxiliary opening data (#134)
autquis Jan 16, 2024
12f5529
`batch_mul_with_preprocessing` no longer takes `self` as argument (#142)
mmagician Jan 17, 2024
e463fd2
Remove `ChallengeGenerator` for Brakedown (#53)
autquis Jan 17, 2024
b9419a3
Remove the extra loop
autquis Jan 17, 2024
3077290
Merge branch 'master' into brakedown-pp
autquis Jan 17, 2024
1879d1c
Revert the incorrect changes in `bench-tamplates`
autquis Jan 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ let (ck, vk) = PCS::trim(&pp, degree, 2, Some(&[degree])).unwrap();

// 3. PolynomialCommitment::commit
// The prover commits to the polynomial using their committer key `ck`.
let (comms, rands) = PCS::commit(&ck, [&labeled_poly], Some(rng)).unwrap();
let (comms, states) = PCS::commit(&ck, [&labeled_poly], Some(rng)).unwrap();

let challenge_generator: ChallengeGenerator<<Bls12_377 as Pairing>::ScalarField, Sponge_Bls12_377> = ChallengeGenerator::new_univariate(&mut test_sponge);

// 4a. PolynomialCommitment::open
// Opening proof at a single point.
let proof_single = PCS::open(&ck, [&labeled_poly], &comms, &point_1, &mut (challenge_generator.clone()), &rands, None).unwrap();
let proof_single = PCS::open(&ck, [&labeled_poly], &comms, &point_1, &mut (challenge_generator.clone()), &states, None).unwrap();

// 5a. PolynomialCommitment::check
// Verifying the proof at a single point, given the commitment, the point, the claimed evaluation, and the proof.
Expand All @@ -156,7 +156,7 @@ let proof_batched = PCS::batch_open(
&comms,
&query_set,
&mut (challenge_generator.clone()),
&rands,
&states,
Some(rng),
).unwrap();

Expand Down
12 changes: 6 additions & 6 deletions bench-templates/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ where
let labeled_poly =
LabeledPolynomial::new("test".to_string(), rand_poly(num_vars, rng), None, None);

let (coms, randomness) = PCS::commit(&ck, [&labeled_poly], Some(rng)).unwrap();
let (coms, states) = PCS::commit(&ck, [&labeled_poly], Some(rng)).unwrap();
let point = rand_point(num_vars, rng);

let start = Instant::now();
Expand All @@ -141,7 +141,7 @@ where
&coms,
&point,
&mut ChallengeGenerator::new_univariate(&mut test_sponge()),
&randomness,
&states,
Some(rng),
)
.unwrap();
Expand All @@ -165,7 +165,7 @@ where
let labeled_poly =
LabeledPolynomial::new("test".to_string(), rand_poly(num_vars, rng), None, None);

let (coms, randomness) = PCS::commit(&ck, [&labeled_poly], Some(rng)).unwrap();
let (coms, states) = PCS::commit(&ck, [&labeled_poly], Some(rng)).unwrap();
let point = P::Point::rand(rng);

let proofs = PCS::open(
Expand All @@ -174,7 +174,7 @@ where
&coms,
&point,
&mut ChallengeGenerator::new_univariate(&mut test_sponge()),
&randomness,
&states,
Some(rng),
)
.unwrap();
Expand Down Expand Up @@ -202,7 +202,7 @@ where
let labeled_poly =
LabeledPolynomial::new("test".to_string(), rand_poly(num_vars, rng), None, None);

let (coms, randomness) = PCS::commit(&ck, [&labeled_poly], Some(rng)).unwrap();
let (coms, states) = PCS::commit(&ck, [&labeled_poly], Some(rng)).unwrap();
let point = rand_point(num_vars, rng);
let claimed_eval = labeled_poly.evaluate(&point);
let proof = PCS::open(
Expand All @@ -211,7 +211,7 @@ where
&coms,
&point,
&mut ChallengeGenerator::new_univariate(&mut test_sponge()),
&randomness,
&states,
Some(rng),
)
.unwrap();
Expand Down
6 changes: 3 additions & 3 deletions poly-commit/src/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ pub trait PCPreparedCommitment<UNPREPARED: PCCommitment>: Clone {
fn prepare(comm: &UNPREPARED) -> Self;
}

/// Defines the minimal interface of commitment randomness for any polynomial
/// commitment scheme.
pub trait PCRandomness: Clone + CanonicalSerialize + CanonicalDeserialize {
/// Defines the minimal interface of commitment state for any polynomial
/// commitment scheme. It might be randomness etc.
pub trait PCCommitmentState: Clone + CanonicalSerialize + CanonicalDeserialize {
/// Outputs empty randomness that does not hide the commitment.
fn empty() -> Self;

Expand Down
2 changes: 1 addition & 1 deletion poly-commit/src/ipa_pc/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub struct Randomness<G: AffineRepr> {
pub shifted_rand: Option<G::ScalarField>,
}

impl<G: AffineRepr> PCRandomness for Randomness<G> {
impl<G: AffineRepr> PCCommitmentState for Randomness<G> {
fn empty() -> Self {
Self {
rand: G::ScalarField::zero(),
Expand Down
14 changes: 7 additions & 7 deletions poly-commit/src/ipa_pc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{BTreeMap, BTreeSet, String, ToString, Vec, CHALLENGE_SIZE};
use crate::{BatchLCProof, DenseUVPolynomial, Error, Evaluations, QuerySet};
use crate::{LabeledCommitment, LabeledPolynomial, LinearCombination};
use crate::{PCCommitterKey, PCRandomness, PCUniversalParams, PolynomialCommitment};
use crate::{PCCommitmentState, PCCommitterKey, PCUniversalParams, PolynomialCommitment};

use ark_ec::{AffineRepr, CurveGroup, VariableBaseMSM};
use ark_ff::{Field, One, PrimeField, UniformRand, Zero};
Expand Down Expand Up @@ -347,7 +347,7 @@ where
type CommitterKey = CommitterKey<G>;
type VerifierKey = VerifierKey<G>;
type Commitment = Commitment<G>;
type Randomness = Randomness<G>;
type CommitmentState = Randomness<G>;
type Proof = Proof<G>;
type BatchProof = Vec<Self::Proof>;
type Error = Error;
Expand Down Expand Up @@ -418,7 +418,7 @@ where
) -> Result<
(
Vec<LabeledCommitment<Self::Commitment>>,
Vec<Self::Randomness>,
Vec<Self::CommitmentState>,
),
Self::Error,
>
Expand Down Expand Up @@ -489,12 +489,12 @@ where
commitments: impl IntoIterator<Item = &'a LabeledCommitment<Self::Commitment>>,
point: &'a P::Point,
opening_challenges: &mut ChallengeGenerator<G::ScalarField, S>,
rands: impl IntoIterator<Item = &'a Self::Randomness>,
rands: impl IntoIterator<Item = &'a Self::CommitmentState>,
rng: Option<&mut dyn RngCore>,
) -> Result<Self::Proof, Self::Error>
where
Self::Commitment: 'a,
Self::Randomness: 'a,
Self::CommitmentState: 'a,
P: 'a,
{
let mut combined_polynomial = P::zero();
Expand Down Expand Up @@ -877,11 +877,11 @@ where
commitments: impl IntoIterator<Item = &'a LabeledCommitment<Self::Commitment>>,
query_set: &QuerySet<P::Point>,
opening_challenges: &mut ChallengeGenerator<G::ScalarField, S>,
rands: impl IntoIterator<Item = &'a Self::Randomness>,
rands: impl IntoIterator<Item = &'a Self::CommitmentState>,
rng: Option<&mut dyn RngCore>,
) -> Result<BatchLCProof<G::ScalarField, Self::BatchProof>, Self::Error>
where
Self::Randomness: 'a,
Self::CommitmentState: 'a,
Self::Commitment: 'a,
P: 'a,
{
Expand Down
2 changes: 1 addition & 1 deletion poly-commit/src/kzg10/data_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ impl<F: PrimeField, P: DenseUVPolynomial<F>> Randomness<F, P> {
}
}

impl<F: PrimeField, P: DenseUVPolynomial<F>> PCRandomness for Randomness<F, P> {
impl<F: PrimeField, P: DenseUVPolynomial<F>> PCCommitmentState for Randomness<F, P> {
fn empty() -> Self {
Self {
blinding_polynomial: P::zero(),
Expand Down
2 changes: 1 addition & 1 deletion poly-commit/src/kzg10/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! proposed by Kate, Zaverucha, and Goldberg ([KZG10](http://cacr.uwaterloo.ca/techreports/2010/cacr2010-10.pdf)).
//! This construction achieves extractability in the algebraic group model (AGM).

use crate::{BTreeMap, Error, LabeledPolynomial, PCRandomness, ToString, Vec};
use crate::{BTreeMap, Error, LabeledPolynomial, PCCommitmentState, ToString, Vec};
use ark_ec::AffineRepr;
use ark_ec::{pairing::Pairing, CurveGroup};
use ark_ec::{scalar_mul::fixed_base::FixedBase, VariableBaseMSM};
Expand Down
50 changes: 25 additions & 25 deletions poly-commit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ pub trait PolynomialCommitment<F: PrimeField, P: Polynomial<F>, S: Cryptographic
type VerifierKey: PCVerifierKey;
/// The commitment to a polynomial.
type Commitment: PCCommitment + Default;
/// The commitment randomness.
type Randomness: PCRandomness;
/// The state of commitment
type CommitmentState: PCCommitmentState;
/// The evaluation proof for a single point.
type Proof: Clone;
/// The evaluation proof for a query set.
Expand Down Expand Up @@ -212,7 +212,7 @@ pub trait PolynomialCommitment<F: PrimeField, P: Polynomial<F>, S: Cryptographic
) -> Result<
(
Vec<LabeledCommitment<Self::Commitment>>,
Vec<Self::Randomness>,
Vec<Self::CommitmentState>,
),
Self::Error,
>
Expand All @@ -226,12 +226,12 @@ pub trait PolynomialCommitment<F: PrimeField, P: Polynomial<F>, S: Cryptographic
commitments: impl IntoIterator<Item = &'a LabeledCommitment<Self::Commitment>>,
point: &'a P::Point,
challenge_generator: &mut ChallengeGenerator<F, S>,
rands: impl IntoIterator<Item = &'a Self::Randomness>,
states: impl IntoIterator<Item = &'a Self::CommitmentState>,
rng: Option<&mut dyn RngCore>,
) -> Result<Self::Proof, Self::Error>
where
P: 'a,
Self::Randomness: 'a,
Self::CommitmentState: 'a,
Self::Commitment: 'a;

/// check but with individual challenges
Expand Down Expand Up @@ -262,29 +262,29 @@ pub trait PolynomialCommitment<F: PrimeField, P: Polynomial<F>, S: Cryptographic
commitments: impl IntoIterator<Item = &'a LabeledCommitment<Self::Commitment>>,
query_set: &QuerySet<P::Point>,
challenge_generator: &mut ChallengeGenerator<F, S>,
rands: impl IntoIterator<Item = &'a Self::Randomness>,
states: impl IntoIterator<Item = &'a Self::CommitmentState>,
rng: Option<&mut dyn RngCore>,
) -> Result<Self::BatchProof, Self::Error>
where
P: 'a,
Self::Randomness: 'a,
Self::CommitmentState: 'a,
Self::Commitment: 'a,
{
// The default implementation achieves proceeds by rearranging the queries in
// order to gather (i.e. batch) all polynomials that should be queried at
// the same point, then opening their commitments simultaneously with a
// single call to `open` (per point)
let rng = &mut crate::optional_rng::OptionalRng(rng);
let poly_rand_comm: BTreeMap<_, _> = labeled_polynomials
let poly_st_comm: BTreeMap<_, _> = labeled_polynomials
.into_iter()
.zip(rands)
.zip(states)
.zip(commitments.into_iter())
.map(|((poly, r), comm)| (poly.label(), (poly, r, comm)))
.map(|((poly, st), comm)| (poly.label(), (poly, st, comm)))
.collect();

let open_time = start_timer!(|| format!(
"Opening {} polynomials at query set of size {}",
poly_rand_comm.len(),
poly_st_comm.len(),
query_set.len(),
));

Expand All @@ -307,20 +307,20 @@ pub trait PolynomialCommitment<F: PrimeField, P: Polynomial<F>, S: Cryptographic
let mut proofs = Vec::new();
for (_point_label, (point, labels)) in query_to_labels_map.into_iter() {
let mut query_polys: Vec<&'a LabeledPolynomial<_, _>> = Vec::new();
let mut query_rands: Vec<&'a Self::Randomness> = Vec::new();
let mut query_states: Vec<&'a Self::CommitmentState> = Vec::new();
let mut query_comms: Vec<&'a LabeledCommitment<Self::Commitment>> = Vec::new();

// Constructing matching vectors with the polynomial, commitment
// randomness and actual commitment for each polynomial being
// queried at `point`
for label in labels {
let (polynomial, rand, comm) =
poly_rand_comm.get(label).ok_or(Error::MissingPolynomial {
let (polynomial, state, comm) =
poly_st_comm.get(label).ok_or(Error::MissingPolynomial {
label: label.to_string(),
})?;

query_polys.push(polynomial);
query_rands.push(rand);
query_states.push(state);
query_comms.push(comm);
}

Expand All @@ -334,7 +334,7 @@ pub trait PolynomialCommitment<F: PrimeField, P: Polynomial<F>, S: Cryptographic
query_comms,
&point,
challenge_generator,
query_rands,
query_states,
Some(rng),
)?;

Expand Down Expand Up @@ -447,11 +447,11 @@ pub trait PolynomialCommitment<F: PrimeField, P: Polynomial<F>, S: Cryptographic
commitments: impl IntoIterator<Item = &'a LabeledCommitment<Self::Commitment>>,
query_set: &QuerySet<P::Point>,
challenge_generator: &mut ChallengeGenerator<F, S>,
rands: impl IntoIterator<Item = &'a Self::Randomness>,
states: impl IntoIterator<Item = &'a Self::CommitmentState>,
rng: Option<&mut dyn RngCore>,
) -> Result<BatchLCProof<F, Self::BatchProof>, Self::Error>
where
Self::Randomness: 'a,
Self::CommitmentState: 'a,
Self::Commitment: 'a,
P: 'a,
{
Expand All @@ -473,7 +473,7 @@ pub trait PolynomialCommitment<F: PrimeField, P: Polynomial<F>, S: Cryptographic
commitments,
&poly_query_set,
challenge_generator,
rands,
states,
rng,
)?;
Ok(BatchLCProof {
Expand Down Expand Up @@ -724,7 +724,7 @@ pub mod tests {
)?;
println!("Trimmed");

let (comms, rands) = PC::commit(&ck, &polynomials, Some(rng))?;
let (comms, states) = PC::commit(&ck, &polynomials, Some(rng))?;

let mut query_set = QuerySet::new();
let mut values = Evaluations::new();
Expand All @@ -742,7 +742,7 @@ pub mod tests {
&comms,
&query_set,
&mut (challenge_gen.clone()),
&rands,
&states,
Some(rng),
)?;
let result = PC::batch_check(
Expand Down Expand Up @@ -857,7 +857,7 @@ pub mod tests {
)?;
println!("Trimmed");

let (comms, rands) = PC::commit(&ck, &polynomials, Some(rng))?;
let (comms, states) = PC::commit(&ck, &polynomials, Some(rng))?;

// Construct query set
let mut query_set = QuerySet::new();
Expand All @@ -878,7 +878,7 @@ pub mod tests {
&comms,
&query_set,
&mut (challenge_gen.clone()),
&rands,
&states,
Some(rng),
)?;
let result = PC::batch_check(
Expand Down Expand Up @@ -1005,7 +1005,7 @@ pub mod tests {
)?;
println!("Trimmed");

let (comms, rands) = PC::commit(&ck, &polynomials, Some(rng))?;
let (comms, states) = PC::commit(&ck, &polynomials, Some(rng))?;

// Let's construct our equations
let mut linear_combinations = Vec::new();
Expand Down Expand Up @@ -1057,7 +1057,7 @@ pub mod tests {
&comms,
&query_set,
&mut (challenge_gen.clone()),
&rands,
&states,
Some(rng),
)?;
println!("Generated proof");
Expand Down
6 changes: 4 additions & 2 deletions poly-commit/src/linear_codes/brakedown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ where
(self.n, self.m)
}

fn leaf_hash_params(&self) -> &<<C as Config>::LeafHash as CRHScheme>::Parameters {
fn leaf_hash_param(&self) -> &<<C as Config>::LeafHash as CRHScheme>::Parameters {
&self.leaf_hash_params
}

fn two_to_one_params(&self) -> &<<C as Config>::TwoToOneHash as TwoToOneCRHScheme>::Parameters {
fn two_to_one_hash_param(
&self,
) -> &<<C as Config>::TwoToOneHash as TwoToOneCRHScheme>::Parameters {
&self.two_to_one_params
}

Expand Down
Loading
Loading