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+++ #46

Merged
merged 5 commits into from
Nov 14, 2023
Merged
Changes from all commits
Commits
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
59 changes: 17 additions & 42 deletions poly-commit/src/linear_codes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ where
let mut commitments = Vec::new();
let mut states = Vec::new();

for labeled_polynomial in polynomials.into_iter() {
for labeled_polynomial in polynomials {
let polynomial = labeled_polynomial.polynomial();

// 1. Arrange the coefficients of the polynomial into a matrix,
Expand Down Expand Up @@ -301,7 +301,7 @@ where

fn open<'a>(
ck: &Self::CommitterKey,
labeled_polynomials: impl IntoIterator<Item = &'a LabeledPolynomial<F, P>>,
_labeled_polynomials: impl IntoIterator<Item = &'a LabeledPolynomial<F, P>>,
commitments: impl IntoIterator<Item = &'a LabeledCommitment<Self::Commitment>>,
point: &'a P::Point,
_challenge_generator: &mut crate::challenge::ChallengeGenerator<F, S>,
Expand All @@ -314,22 +314,9 @@ where
Self::Commitment: 'a,
{
let mut proof_array = LPCPArray::default();
let labeled_commitments: Vec<&'a LabeledCommitment<Self::Commitment>> =
commitments.into_iter().collect();
let labeled_polynomials: Vec<&'a LabeledPolynomial<F, P>> =
labeled_polynomials.into_iter().collect();
let states: Vec<&'a Self::CommitmentState> = states.into_iter().collect();

if labeled_commitments.len() != labeled_polynomials.len() {
return Err(Error::IncorrectInputLength(format!(
"Mismatched lengths: {} commitments, {} polynomials",
labeled_commitments.len(),
labeled_polynomials.len()
)));
}

for i in 0..labeled_polynomials.len() {
let commitment = labeled_commitments[i].commitment();
for (labeled_commitment, state) in commitments.into_iter().zip(states) {
let commitment = labeled_commitment.commitment();
let n_rows = commitment.metadata.n_rows;
let n_cols = commitment.metadata.n_cols;
let root = &commitment.root;
Expand All @@ -341,7 +328,7 @@ where
mat,
ext_mat,
leaves: col_hashes,
} = states[i];
} = state;
let mut col_hashes: Vec<C::Leaf> =
col_hashes.clone().into_iter().map(|h| h.into()).collect();

Expand Down Expand Up @@ -416,25 +403,13 @@ where
where
Self::Commitment: 'a,
{
let labeled_commitments: Vec<&'a LabeledCommitment<Self::Commitment>> =
commitments.into_iter().collect();
let values: Vec<F> = values.into_iter().collect();

if labeled_commitments.len() != proof_array.len()
|| labeled_commitments.len() != values.len()
{
return Err(Error::IncorrectInputLength(
format!(
"Mismatched lengths: {} proofs were provided for {} commitments with {} claimed values",labeled_commitments.len(), proof_array.len(), values.len()
)
));
}
let leaf_hash_param: &<<C as Config>::LeafHash as CRHScheme>::Parameters =
vk.leaf_hash_param();
let two_to_one_hash_param: &<<C as Config>::TwoToOneHash as TwoToOneCRHScheme>::Parameters =
vk.two_to_one_hash_param();

for (i, labeled_commitment) in labeled_commitments.iter().enumerate() {
for (i, (labeled_commitment, value)) in commitments.into_iter().zip(values).enumerate() {
let proof = &proof_array[i];
let commitment = labeled_commitment.commitment();
let n_rows = commitment.metadata.n_rows;
let n_cols = commitment.metadata.n_cols;
Expand All @@ -448,10 +423,10 @@ where
.map_err(|_| Error::TranscriptError)?;

let out = if vk.check_well_formedness() {
if proof_array[i].well_formedness.is_none() {
if proof.well_formedness.is_none() {
return Err(Error::InvalidCommitment);
}
let tmp = &proof_array[i].well_formedness.as_ref();
let tmp = &proof.well_formedness.as_ref();
let well_formedness = tmp.unwrap();
let mut r = Vec::with_capacity(n_rows);
for _ in 0..n_rows {
Expand Down Expand Up @@ -480,14 +455,14 @@ where
.map_err(|_| Error::TranscriptError)?;
}
transcript
.append_serializable_element(b"v", &proof_array[i].opening.v)
.append_serializable_element(b"v", &proof.opening.v)
.map_err(|_| Error::TranscriptError)?;

// 2. Ask random oracle for the `t` indices where the checks happen.
let indices = get_indices_from_transcript::<F>(n_ext_cols, t, &mut transcript)?;

// 3. Hash the received columns into leaf hashes.
let col_hashes: Vec<C::Leaf> = proof_array[i]
let col_hashes: Vec<C::Leaf> = proof
.opening
.columns
.iter()
Expand All @@ -503,7 +478,7 @@ where
// even if we have a well-formedness check (i.e., we save sending and checking the columns).
// See "Concrete optimizations to the commitment scheme", p.12 of [Brakedown](https://eprint.iacr.org/2021/1043.pdf).
for (j, (leaf, q_j)) in col_hashes.iter().zip(indices.iter()).enumerate() {
let path = &proof_array[i].opening.paths[j];
let path = &proof.opening.paths[j];
if path.leaf_index != *q_j {
return Err(Error::InvalidCommitment);
}
Expand All @@ -522,7 +497,7 @@ where
};

// 5. Compute the encoding w = E(v).
let w = L::encode(&proof_array[i].opening.v, vk)?;
let w = L::encode(&proof.opening.v, vk)?;

// 6. Compute `a`, `b` to right- and left- multiply with the matrix `M`.
let (a, b) = L::tensor(point, n_cols, n_rows);
Expand All @@ -535,26 +510,26 @@ where
for (transcript_index, matrix_index) in indices.iter().enumerate() {
check_inner_product(
&r,
&proof_array[i].opening.columns[transcript_index],
&proof.opening.columns[transcript_index],
w_well_formedness[*matrix_index],
)?;
check_inner_product(
&b,
&proof_array[i].opening.columns[transcript_index],
&proof.opening.columns[transcript_index],
w[*matrix_index],
)?;
}
} else {
for (transcript_index, matrix_index) in indices.iter().enumerate() {
check_inner_product(
&b,
&proof_array[i].opening.columns[transcript_index],
&proof.opening.columns[transcript_index],
w[*matrix_index],
)?;
}
}

if inner_product(&proof_array[i].opening.v, &a) != values[i] {
if inner_product(&proof.opening.v, &a) != value {
eprintln!("Function check: claimed value in position {i} does not match the evaluation of the committed polynomial in the same position");
return Ok(false);
}
Expand Down
Loading