-
Notifications
You must be signed in to change notification settings - Fork 162
Refactor compute_deep_composition_poly function #200
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
48 commits
Select commit
Hold shift + click to select a range
0718670
[WIP] Deep FRI
jrchatruc fd7f3a4
Finish implementation
jrchatruc 11ff81a
Document code
jrchatruc 13d950e
Merge branch 'main' into deep-fri
jrchatruc 27ec171
Fix vulnerability tests and add more
jrchatruc aa3332e
Define basic traits and structs for Air
entropidelic e6ea1a9
Write basic skeleton of ConstraintEvaluator
entropidelic ffaf881
Save evaluator progress
entropidelic 1a443c3
Complete evaluator basic methods
entropidelic bc78949
Fix some compilation errors
jrchatruc f3cb147
Finish method for computing composition poly from Evaluation Table
entropidelic 60d36e0
More fixes
jrchatruc 437c446
More progress
jrchatruc ae494de
Comment out tests
jrchatruc 7f70d78
Merge branch 'main' into air-impl
jrchatruc 57e8f36
[WIP] Implement verifier
jrchatruc 98fbf8b
Debugging stuff
jrchatruc 4711f36
Remove debugging stuff as the boundary ood evaluation was correct
jrchatruc 706e09c
Uncomment important line
jrchatruc 69a4877
Start compute_deep_composition_poly refactor
entropidelic 7c10e42
Finish compute_deep_composition_poly refactor
entropidelic 91396d7
Refactor trace function to take the length as a parameter
jrchatruc 26b96f3
Fix hardcoded boundary poly degree on verifier
jrchatruc ace4b1e
Some fixes
jrchatruc 4b1edfd
Fix transition_divisors implementation
jrchatruc a90fd0b
Fix transition_divisor once more
jrchatruc 8881e77
Fix calculation of trace primitive root on the verifier
jrchatruc eafa2a9
Test finally working
jrchatruc 267aaee
Remove unusued num_assertions field
jrchatruc 593db94
Merge branch 'main' into air-impl
jrchatruc 22b7da0
[WIP] fiat-shamir integration
jrchatruc 69ce919
Comment transcript.append line in fri function
entropidelic 0ba2fea
Fix fiat-shamir integration bugs
entropidelic fa095f5
Fix boundaryconstraints zerofier test
entropidelic afcaa1c
Fix clippy suggestiojns
entropidelic a91cc07
Remove outdated comments
jrchatruc 32b6892
Rename compute_transition_evaluations
entropidelic bfd9ecc
Add Fibonacci AIR test for a 17 finite field
entropidelic b1fd123
Merge branch 'air-impl' into compute_deep_composition_poly-refactor
entropidelic 2398381
Save refactor WIP
entropidelic 25987bd
Refactor compute_deep_composition_poly to generalize for a trace with…
entropidelic bcc3ba4
Merge branch 'main' into compute_deep_composition_poly-refactor
entropidelic d68d220
Add comments to dummy transcript challenge calls in verifier
entropidelic c9c725b
Use a better variable name
entropidelic cc90ee2
Merge branch 'main' into compute_deep_composition_poly-refactor
entropidelic 6926477
Remove debug comment
entropidelic 9e77305
Add comments and documentation
entropidelic 75c74f0
Fix typo
entropidelic 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
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
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
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
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ use lambdaworks_math::{ | |
element::FieldElement, | ||
traits::{IsField, IsTwoAdicField}, | ||
}, | ||
polynomial::{self, Polynomial}, | ||
polynomial::Polynomial, | ||
traits::ByteConversion, | ||
}; | ||
|
||
|
@@ -100,11 +100,13 @@ where | |
|
||
// Compute DEEP composition polynomial so we can commit to it using FRI. | ||
let mut deep_composition_poly = compute_deep_composition_poly( | ||
&trace_poly, | ||
air, | ||
&[trace_poly], | ||
&composition_poly_even, | ||
&composition_poly_odd, | ||
&z, | ||
&trace_primitive_root, | ||
transcript, | ||
); | ||
|
||
// * Do FRI on the composition polynomials | ||
|
@@ -121,7 +123,7 @@ where | |
|
||
for _i in 0..air.context().options.fri_number_of_queries { | ||
// * Sample q_1, ..., q_m using Fiat-Shamir | ||
let q_i: usize = transcript_to_usize(transcript) % 2_usize.pow(lde_root_order); | ||
let q_i = transcript_to_usize(transcript) % 2_usize.pow(lde_root_order); | ||
transcript.append(&q_i.to_be_bytes()); | ||
|
||
// * For every q_i, do FRI decommitment | ||
|
@@ -149,52 +151,63 @@ where | |
/// Returns the DEEP composition polynomial that the prover then commits to using | ||
/// FRI. This polynomial is a linear combination of the trace polynomial and the | ||
/// composition polynomial, with coefficients sampled by the verifier (i.e. using Fiat-Shamir). | ||
fn compute_deep_composition_poly<F: IsField>( | ||
trace_poly: &Polynomial<FieldElement<F>>, | ||
fn compute_deep_composition_poly<A: AIR, F: IsField>( | ||
air: &A, | ||
trace_polys: &[Polynomial<FieldElement<F>>], | ||
even_composition_poly: &Polynomial<FieldElement<F>>, | ||
odd_composition_poly: &Polynomial<FieldElement<F>>, | ||
ood_evaluation_point: &FieldElement<F>, | ||
primitive_root: &FieldElement<F>, | ||
transcript: &mut Transcript, | ||
) -> Polynomial<FieldElement<F>> { | ||
// TODO: Fiat-Shamir | ||
let gamma_1 = FieldElement::one(); | ||
let gamma_2 = FieldElement::one(); | ||
let gamma_3 = FieldElement::one(); | ||
let gamma_4 = FieldElement::one(); | ||
let transition_offsets = air.context().transition_offsets; | ||
|
||
// Get the number of trace terms the DEEP composition poly will have. | ||
// One coefficient will be sampled for each of them. | ||
let n_trace_terms = transition_offsets.len() * trace_polys.len(); | ||
let mut trace_term_coeffs = Vec::with_capacity(n_trace_terms); | ||
for _ in 0..n_trace_terms { | ||
trace_term_coeffs.push(transcript_to_field::<F>(transcript)); | ||
} | ||
|
||
let first_term = (trace_poly.clone() | ||
- Polynomial::new_monomial(trace_poly.evaluate(ood_evaluation_point), 0)) | ||
/ (Polynomial::new_monomial(FieldElement::one(), 1) | ||
- Polynomial::new_monomial(ood_evaluation_point.clone(), 0)); | ||
let second_term = (trace_poly.clone() | ||
- Polynomial::new_monomial( | ||
trace_poly.evaluate(&(ood_evaluation_point * primitive_root)), | ||
0, | ||
)) | ||
/ (Polynomial::new_monomial(FieldElement::one(), 1) | ||
- Polynomial::new_monomial(ood_evaluation_point * primitive_root, 0)); | ||
// Get coefficients for even and odd terms of the composition polynomial H(x) | ||
let gamma_even = transcript_to_field::<F>(transcript); | ||
let gamma_odd = transcript_to_field::<F>(transcript); | ||
|
||
// Evaluate in X^2 | ||
let even_composition_poly = polynomial::compose( | ||
even_composition_poly, | ||
&Polynomial::new_monomial(FieldElement::one(), 2), | ||
); | ||
let odd_composition_poly = polynomial::compose( | ||
odd_composition_poly, | ||
&Polynomial::new_monomial(FieldElement::one(), 2), | ||
// Get trace evaluations needed for the trace terms of the deep composition polynomial | ||
let trace_evaluations = Frame::get_trace_evaluations( | ||
trace_polys, | ||
ood_evaluation_point, | ||
&transition_offsets, | ||
primitive_root, | ||
); | ||
|
||
let third_term = (even_composition_poly.clone() | ||
// Compute all the trace terms of the deep composition polynomial. There will be one | ||
// term for every trace polynomial and every trace evaluation. | ||
let mut trace_terms = Polynomial::zero(); | ||
for (trace_evaluation, trace_poly) in trace_evaluations.iter().zip(trace_polys) { | ||
for (eval, coeff) in trace_evaluation.iter().zip(&trace_term_coeffs) { | ||
let poly = (trace_poly.clone() | ||
- Polynomial::new_monomial(trace_poly.evaluate(eval), 0)) | ||
/ (Polynomial::new_monomial(FieldElement::<F>::one(), 1) | ||
- Polynomial::new_monomial(eval.clone(), 0)); | ||
|
||
trace_terms = trace_terms + poly * coeff.clone(); | ||
Comment on lines
+190
to
+195
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. Can we avoid some of the clones here? |
||
} | ||
} | ||
|
||
let even_composition_poly_term = (even_composition_poly.clone() | ||
- Polynomial::new_monomial( | ||
even_composition_poly.evaluate(&ood_evaluation_point.clone()), | ||
0, | ||
)) | ||
/ (Polynomial::new_monomial(FieldElement::one(), 1) | ||
- Polynomial::new_monomial(ood_evaluation_point * ood_evaluation_point, 0)); | ||
let fourth_term = (odd_composition_poly.clone() | ||
|
||
let odd_composition_poly_term = (odd_composition_poly.clone() | ||
Comment on lines
+199
to
+207
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. Here as well. |
||
- Polynomial::new_monomial(odd_composition_poly.evaluate(ood_evaluation_point), 0)) | ||
/ (Polynomial::new_monomial(FieldElement::one(), 1) | ||
- Polynomial::new_monomial(ood_evaluation_point * ood_evaluation_point, 0)); | ||
|
||
first_term * gamma_1 + second_term * gamma_2 + third_term * gamma_3 + fourth_term * gamma_4 | ||
trace_terms + even_composition_poly_term * gamma_even + odd_composition_poly_term * gamma_odd | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.