-
Notifications
You must be signed in to change notification settings - Fork 119
Reintroduce "Parallelise perm_aggreg" w/ bugfix #3121
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,7 +337,6 @@ impl<F: PrimeField, G: KimchiCurve<ScalarField = F>, OpeningProof: OpenProof<G>> | |
|
||
&bnd1.scale(alpha1) + &bnd2.scale(alpha2) | ||
}; | ||
|
||
Ok((perm, bnd)) | ||
} | ||
|
||
|
@@ -446,8 +445,6 @@ impl<F: PrimeField, G: KimchiCurve<ScalarField = F>, OpeningProof: OpenProof<G>> | |
//~ The first evaluation represents the initial value of the accumulator: | ||
//~ $$z(g^0) = 1$$ | ||
|
||
let mut z = vec![F::one(); n]; | ||
|
||
//~ For $i = 0, \cdot, n - 4$, where $n$ is the size of the domain, | ||
//~ evaluations are computed as: | ||
//~ | ||
|
@@ -481,27 +478,61 @@ impl<F: PrimeField, G: KimchiCurve<ScalarField = F>, OpeningProof: OpenProof<G>> | |
//~ \end{align} | ||
//~ $$ | ||
//~ | ||
for j in 0..n - 1 { | ||
z[j + 1] = witness | ||
.iter() | ||
.zip(self.column_evaluations.permutation_coefficients8.iter()) | ||
.map(|(w, s)| w[j] + (s[8 * j] * beta) + gamma) | ||
.fold(F::one(), |x, y| x * y); | ||
} | ||
|
||
// We compute z such that: | ||
// z[0] = 1 | ||
// z[j+1] = \Prod_{i=0}^{PERMUTS}(wit[i][j] + (s[i][8*j] * beta) + gamma) for j ∈ 0..n-1 | ||
// | ||
// We compute every product batch separately first (one batch | ||
// per i∈[COLUMNS]), and then multiply all batches together. | ||
// | ||
// Note that we zip array of COLUMNS with array of PERMUTS; | ||
// Since PERMUTS < COLUMNS, that's what's actually used. | ||
let mut z: Vec<F> = witness | ||
.par_iter() | ||
.zip(self.column_evaluations.permutation_coefficients8.par_iter()) | ||
.map(|(w_i, perm_coeffs8_i)| { | ||
let mut output_vec: Vec<_> = vec![F::one(); 1]; | ||
for (j, w_i_j) in w_i.iter().enumerate().take(n - 1) { | ||
output_vec.push(*w_i_j + (perm_coeffs8_i[8 * j] * beta) + gamma); | ||
} | ||
output_vec | ||
}) | ||
.reduce_with(|mut l, r| { | ||
for i in 0..n { | ||
l[i] *= &r[i]; | ||
} | ||
l | ||
}) | ||
.unwrap(); | ||
|
||
ark_ff::fields::batch_inversion::<F>(&mut z[1..n]); | ||
|
||
let z_prefolded: Vec<F> = witness | ||
.par_iter() | ||
.zip(self.cs.shift.par_iter()) | ||
.map(|(w_i, shift_i)| { | ||
let mut output_vec: Vec<_> = vec![F::one(); 1]; | ||
for (j, w_i_j) in w_i.iter().enumerate().take(n - 1) { | ||
output_vec.push(*w_i_j + (self.cs.sid[j] * beta * shift_i) + gamma); | ||
} | ||
output_vec | ||
}) | ||
.reduce_with(|mut l, r| { | ||
for i in 0..n { | ||
l[i] *= &r[i]; | ||
} | ||
l | ||
}) | ||
.unwrap(); | ||
Comment on lines
+511
to
+527
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code could probably be unified with the code of |
||
|
||
//~ We randomize the evaluations at `n - zk_rows + 1` and `n - zk_rows + 2` in order to add | ||
//~ zero-knowledge to the protocol. | ||
//~ | ||
for j in 0..n - 1 { | ||
if j != n - zk_rows && j != n - zk_rows + 1 { | ||
let x = z[j]; | ||
z[j + 1] *= witness | ||
.iter() | ||
.zip(self.cs.shift.iter()) | ||
.map(|(w, s)| w[j] + (self.cs.sid[j] * beta * s) + gamma) | ||
.fold(x, |z, y| z * y); | ||
z[j + 1] *= z_prefolded[j + 1] * x; | ||
} else { | ||
z[j + 1] = F::rand(rng); | ||
} | ||
|
@@ -514,6 +545,7 @@ impl<F: PrimeField, G: KimchiCurve<ScalarField = F>, OpeningProof: OpenProof<G>> | |
}; | ||
|
||
let res = Evaluations::<F, D<F>>::from_vec_and_domain(z, self.cs.domain.d1).interpolate(); | ||
|
||
Ok(res) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would keep the name
s
instead ofperm_coeffs
as it is the one in the comment, it’s shorter and it make sense if you know plonkThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to rename for clarity, I was confused by
s
(thought it was shifts), and it's consistent with the general effort to use more self-descriptive variable names...