-
Notifications
You must be signed in to change notification settings - Fork 44
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
Add GKR implementation of Grand Product lookups #620
base: dev
Are you sure you want to change the base?
Add GKR implementation of Grand Product lookups #620
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #620 +/- ##
==========================================
+ Coverage 89.84% 92.29% +2.44%
==========================================
Files 75 75
Lines 9588 9872 +284
Branches 9588 9872 +284
==========================================
+ Hits 8614 9111 +497
+ Misses 894 672 -222
- Partials 80 89 +9 ☔ View full report in Codecov by Sentry. |
753aad2
to
fbd5d23
Compare
386d3c8
to
36695ff
Compare
fbd5d23
to
5705279
Compare
36695ff
to
c3b7a95
Compare
5705279
to
38cef08
Compare
c3b7a95
to
162fdcc
Compare
38cef08
to
778d86c
Compare
162fdcc
to
9883b66
Compare
778d86c
to
158add9
Compare
9883b66
to
da2a0e9
Compare
158add9
to
40a1a18
Compare
da2a0e9
to
2a62b8c
Compare
40a1a18
to
8a53b70
Compare
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.
Reviewed 1 of 8 files at r1, all commit messages.
Reviewable status: 1 of 11 files reviewed, 4 unresolved discussions (waiting on @andrewmilson and @shaharsamocha7)
crates/prover/src/core/backend/cpu/lookups/gkr.rs
line 32 at r3 (raw file):
claim: SecureField, ) -> UnivariatePoly<SecureField> { let k = h.n_variables();
n_variables or n_vars
Suggestion:
n_variables
crates/prover/src/core/backend/cpu/lookups/gkr.rs
line 35 at r3 (raw file):
let n_terms = 1 << (k - 1); let eq_evals = h.eq_evals; let y = eq_evals.y();
What's this? Rename or doc.
crates/prover/src/core/backend/cpu/lookups/gkr.rs
line 51 at r3 (raw file):
let rhs0 = input_layer[(n_terms + i) * 2]; let rhs1 = input_layer[(n_terms + i) * 2 + 1];
Suggestion:
// Input polynomial at points (r,0,bits(i),1), ...
let inp_at_r0i0 = input_layer[i * 2];
let inp_at_r0i1 = input_layer[i * 2 + 1];
let inp_at_r1i0 = input_layer[(n_terms + i) * 2];
let inp_at_r1i1 = input_layer[(n_terms + i) * 2 + 1];
let inp_at_r2i0 = (inp_at_r1i0.double() - inp_at_r0i0);
let inp_at_r2i1 = (inp_at_r0i1.double() - inp_at_r0i1);
crates/prover/src/core/backend/cpu/lookups/gkr.rs
line 54 at r3 (raw file):
let product2 = (rhs0.double() - lhs0) * (rhs1.double() - lhs1); let product0 = lhs0 * lhs1;
Suggestion:
// Product polynomial prod(x) = inp(x,0)*inp(x,1)
// at points (r,0,bits(i)), ...
let prod_at_r0i = inp_at_r0i0 * inp_at_r0i1;
let prod_t_r2i = inp_at_r2i0 * inp_at_r2i1;
b375f43
to
ca61e80
Compare
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.
Reviewable status: 1 of 12 files reviewed, 4 unresolved discussions (waiting on @shaharsamocha7 and @spapinistarkware)
crates/prover/src/core/backend/cpu/lookups/gkr.rs
line 32 at r3 (raw file):
Previously, spapinistarkware (Shahar Papini) wrote…
n_variables or n_vars
Done.
crates/prover/src/core/backend/cpu/lookups/gkr.rs
line 35 at r3 (raw file):
Previously, spapinistarkware (Shahar Papini) wrote…
What's this? Rename or doc.
Done.
crates/prover/src/core/backend/cpu/lookups/gkr.rs
line 51 at r3 (raw file):
let rhs0 = input_layer[(n_terms + i) * 2]; let rhs1 = input_layer[(n_terms + i) * 2 + 1];
Done.
crates/prover/src/core/backend/cpu/lookups/gkr.rs
line 54 at r3 (raw file):
let product2 = (rhs0.double() - lhs0) * (rhs1.double() - lhs1); let product0 = lhs0 * lhs1;
Done.
ca61e80
to
789c3c9
Compare
789c3c9
to
9fbd265
Compare
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.
Reviewable status: 1 of 12 files reviewed, 4 unresolved discussions (waiting on @andrewmilson and @shaharsamocha7)
crates/prover/src/core/backend/cpu/lookups/gkr.rs
line 30 at r5 (raw file):
) -> UnivariatePoly<SecureField> { let n_variables = h.n_variables(); let n_terms = 1 << n_variables.saturating_sub(1);
Does this function work when n_variables == 0?
Code quote:
n_variables.saturating_sub(1)
crates/prover/src/core/backend/cpu/lookups/gkr.rs
line 57 at r5 (raw file):
} fn process_grand_product_sum(
Also, I'd like to doc somewhere that the GrandProduct layer poly is. Maybe at the enum definition.
P(x) = Inp(x,0) * Inp(x,1)
Suggestion:
/// Evaluates the sum of a grand product layer poly over a hypercube.
fn eval_grand_product_sum(
crates/prover/src/core/backend/cpu/lookups/gkr.rs
line 58 at r5 (raw file):
fn process_grand_product_sum( eval_at_0: &mut SecureField,
Why get them as mut instead of return them? You are passing zeros.
9fbd265
to
0cc0d79
Compare
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.
Reviewable status: 1 of 12 files reviewed, 4 unresolved discussions (waiting on @shaharsamocha7 and @spapinistarkware)
crates/prover/src/core/backend/cpu/lookups/gkr.rs
line 30 at r5 (raw file):
Previously, spapinistarkware (Shahar Papini) wrote…
Does this function work when n_variables == 0?
It doesn't, thanks. Changed it to panic.
crates/prover/src/core/backend/cpu/lookups/gkr.rs
line 58 at r5 (raw file):
Previously, spapinistarkware (Shahar Papini) wrote…
Why get them as mut instead of return them? You are passing zeros.
Done.
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.
Reviewed 1 of 2 files at r4, all commit messages.
Reviewable status: 2 of 12 files reviewed, 2 unresolved discussions (waiting on @andrewmilson and @shaharsamocha7)
crates/prover/src/core/backend/cpu/lookups/gkr.rs
line 45 at r7 (raw file):
// 1. `sum_x eq(({0}^|r|, 0, x), y) * F(r, t, x)` // 2. `sum_x eq((r, t, x), y) * F(r, t, x)` {
Why is this in a block?
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.
Reviewable status: 2 of 12 files reviewed, 3 unresolved discussions (waiting on @andrewmilson and @shaharsamocha7)
crates/prover/src/core/lookups/gkr_prover.rs
line 391 at r7 (raw file):
/// * `k` is zero or greater than the length of `y`. /// * `z_0` is zero. pub fn correct_sum_as_poly_in_first_variable(
I think this function is kind of convoluted with respect to what it actually needs to do.
Here is my reasoning.
We evaluated f(0) and f(2) - the inputs.
We want to compute r(t) = f(t) * eq(t,z)/eq(0,z) / eq(0, y)
(I think this explicit formulat would also help the docs).
eq(0,y) is a const, call it a.
eq(t,z)/eq(0,z) =
(tz+(1-t)(1-z))/(1-z) =
1-t+tz/(1-z)=
1 - t(1 - z/(1-z))=
1 - t(2 - 1/(1-z))=
1-bt
We get that r(t) = f(t) * (1-bt) / a.
Also,
r(0) = f(0) / a
r(1) = claim - r(0)
r(2) = f(2)(1-2b) / a
r(1/b) = 0
Interpolate these.
This change is![Reviewable](https://camo.githubusercontent.com/23b05f5fb48215c989e92cc44cf6512512d083132bd3daf689867c8d9d386888/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)