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

Remove unnecessary cloning #62

Open
wants to merge 5 commits into
base: brakedown
Choose a base branch
from
Open
Show file tree
Hide file tree
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
20 changes: 9 additions & 11 deletions poly-commit/src/linear_codes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ where
fn poly_to_vec(polynomial: &P) -> Vec<F>;

/// Represent the query point as a vector of Field elements.
fn point_to_vec(point: P::Point) -> Vec<F>;
fn point_to_vec(point: &P::Point) -> &Vec<F>;

/// Arrange the coefficients of the polynomial into a matrix,
/// and apply encoding to each row.
Expand Down Expand Up @@ -162,7 +162,7 @@ where
P: Polynomial<F>,
S: CryptographicSponge,
C: Config + 'static,
Vec<F>: Borrow<<H as CRHScheme>::Input>,
for<'a> &'a Vec<F>: Borrow<<H as CRHScheme>::Input>,
H::Output: Into<C::Leaf> + Send,
C::Leaf: Sized + Clone + Default + Send + AsRef<C::Leaf>,
H: CRHScheme + 'static,
Expand Down Expand Up @@ -192,9 +192,7 @@ where
rng: &mut R,
) -> Result<Self::UniversalParams, Self::Error> {
let leaf_hash_param = <C::LeafHash as CRHScheme>::setup(rng).unwrap();
let two_to_one_hash_param = <C::TwoToOneHash as TwoToOneCRHScheme>::setup(rng)
.unwrap()
.clone();
let two_to_one_hash_param = <C::TwoToOneHash as TwoToOneCRHScheme>::setup(rng).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why there was a clone before?

let col_hash_params = <H as CRHScheme>::setup(rng).unwrap();
let pp = L::setup::<R>(
max_degree,
Expand Down Expand Up @@ -254,7 +252,7 @@ where
let ext_mat_cols = ext_mat.cols();
let leaves: Vec<H::Output> = cfg_into_iter!(ext_mat_cols)
.map(|col| {
H::evaluate(ck.col_hash_params(), col)
H::evaluate(ck.col_hash_params(), &col)
.map_err(|_| Error::HashingError)
.unwrap()
})
Expand Down Expand Up @@ -349,7 +347,7 @@ where
None
};

let point_vec = L::point_to_vec(point.clone());
let point_vec = L::point_to_vec(point);
sponge.absorb(&point_vec);

proof_array.push(LinCodePCProof {
Expand Down Expand Up @@ -415,7 +413,7 @@ where

// 1. Seed the transcript with the point and the recieved vector
// TODO Consider removing the evaluation point from the transcript.
let point_vec = L::point_to_vec(point.clone());
let point_vec = L::point_to_vec(&point);
sponge.absorb(&point_vec);
sponge.absorb(&proof.opening.v);

Expand All @@ -428,7 +426,7 @@ where
.columns
.iter()
.map(|c| {
H::evaluate(vk.col_hash_params(), c.clone())
H::evaluate(vk.col_hash_params(), c)
.map_err(|_| Error::HashingError)
.unwrap()
.into()
Expand All @@ -438,13 +436,13 @@ where
// 4. Verify the paths for each of the leaf hashes - this is only run once,
// 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() {
for (j, (leaf, q_j)) in col_hashes.into_iter().zip(indices.iter()).enumerate() {
let path = &proof.opening.paths[j];
if path.leaf_index != *q_j {
return Err(Error::InvalidCommitment);
}

path.verify(leaf_hash_param, two_to_one_hash_param, root, leaf.clone())
path.verify(leaf_hash_param, two_to_one_hash_param, root, leaf)
.map_err(|_| Error::InvalidCommitment)?;
}

Expand Down
4 changes: 2 additions & 2 deletions poly-commit/src/linear_codes/multilinear_brakedown/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ where
polynomial.to_evaluations()
}

fn point_to_vec(point: <P as Polynomial<F>>::Point) -> Vec<F> {
fn point_to_vec(point: &<P as Polynomial<F>>::Point) -> &Vec<F> {
point
}

Expand All @@ -103,7 +103,7 @@ where
left_len: usize,
_right_len: usize,
) -> (Vec<F>, Vec<F>) {
let point: Vec<F> = Self::point_to_vec(point.clone());
let point: &Vec<F> = Self::point_to_vec(point);

let split = log2(left_len) as usize;
let left = &point[..split];
Expand Down
Loading