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

Optimism: remove clone trait and avoid cloning commitments #1872

Merged
merged 1 commit into from
Feb 29, 2024
Merged
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
13 changes: 7 additions & 6 deletions optimism/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ pub fn fold<
};
let mut fq_sponge = EFqSponge::new(G::other_curve_sponge_params());

for column in commitments.into_iter() {
absorb_commitment(&mut fq_sponge, &column);
}
commitments.into_iter().for_each(|comm| {
absorb_commitment(&mut fq_sponge, &comm);
});

let scaling_challenge = ScalarChallenge(fq_sponge.challenge());
let (_, endo_r) = G::endos();
let scaling_challenge = scaling_challenge.to_field(endo_r);
Expand Down Expand Up @@ -235,9 +236,9 @@ pub fn verify<
} = proof;

let mut fq_sponge = EFqSponge::new(G::other_curve_sponge_params());
for column in commitments.clone().into_iter() {
absorb_commitment(&mut fq_sponge, &column);
}
commitments.into_iter().for_each(|comm| {
absorb_commitment(&mut fq_sponge, comm);
});
let zeta_chal = ScalarChallenge(fq_sponge.challenge());
let (_, endo_r) = G::endos();
let zeta: G::ScalarField = zeta_chal.to_field(endo_r);
Expand Down
13 changes: 12 additions & 1 deletion optimism/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<const N: usize, T: Zero + Clone> Default for Witness<N, T> {

// IMPLEMENTATION OF ITERATORS FOR THE WITNESS STRUCTURE

impl<const N: usize, F: Clone> IntoIterator for Witness<N, F> {
impl<const N: usize, F> IntoIterator for Witness<N, F> {
type Item = F;
type IntoIter = std::vec::IntoIter<F>;

Expand All @@ -32,6 +32,17 @@ impl<const N: usize, F: Clone> IntoIterator for Witness<N, F> {
}
}

impl<'lt, const N: usize, G> IntoIterator for &'lt Witness<N, G> {
type Item = &'lt G;
type IntoIter = std::vec::IntoIter<&'lt G>;

fn into_iter(self) -> Self::IntoIter {
let mut iter_contents = Vec::with_capacity(N);
iter_contents.extend(&self.cols);
iter_contents.into_iter()
}
}

impl<const N: usize, G> IntoParallelIterator for Witness<N, G>
where
Vec<G>: IntoParallelIterator,
Expand Down