-
Notifications
You must be signed in to change notification settings - Fork 24
Add FRI comparison, closes issue #279 #366
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
base: main
Are you sure you want to change the base?
Conversation
Next steps are adapting it to use the WHIR parameters and reduce it to only the FRI PCS. The code in this commit is simply ripped out of the Plonky3 examples, where they build an entire STARK example.
|
Not sure how hard it is to do, but if you want to compare FRI and WHIR apple to apple (as low-degree tests) you can remove the following from WHIR (either properly or just from the timings)
(You can look at https://github.com/WizardOfMenlo/whir/blob/15cf6668e904ed2e80c9e6209dcce69f5bcf79b9/src/bin/main.rs#L195 for an example, I think it's the |
|
src/bin/main.rs
Outdated
| println!("Verification time: {} μs", verify_time.as_micros()); | ||
| } | ||
|
|
||
| #[allow(clippy::too_many_lines)] |
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.
| #[allow(clippy::too_many_lines)] |
SyxtonPrime
left a comment
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.
LGTM
As far as I can tell, you've set up FRI correctly so I think this is a reasonably fair test on that side.
| pub const fn create_benchmark_fri_params<Mmcs>(mmcs: Mmcs) -> FriParameters<Mmcs> { | ||
| FriParameters { | ||
| log_blowup: 1, | ||
| log_final_poly_len: 0, | ||
| num_queries: 40, | ||
| proof_of_work_bits: 8, | ||
| mmcs, | ||
| } | ||
| } |
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.
Ideally, we should fix a security parameter and then calculate the number of queries based off that.
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.
But with target_security = 90 for WHIR vs num_queries: 40 here for FRI we don't have the same level of security no? Or did I miss something?
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.
Yeah, I should have mentioned that these are obviously placeholder at the moment. I just don't have a good intuition for how to choose parameters sensibly here to compare with WHIR.
| // Define the number of columns we split the evaluations into | ||
| // TODO: could make this a CL arg? | ||
| const LOG_NUM_COLS: usize = 5; | ||
| const NUM_COLS: usize = 1 << LOG_NUM_COLS; // 32 |
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.
Hmm this doesn't really make sense from the FRI perspective (i.e. the low degree test).
I guess this is like doing several low degree tests in parallel?
|
|
||
| // Commit to the matrix | ||
| let commit_time = Instant::now(); | ||
| let (commitment, prover_data) = Pcs::<EF, MyChallenger>::commit(&pcs, matrix_iter.clone()); |
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.
This is cleaner
| let (commitment, prover_data) = Pcs::<EF, MyChallenger>::commit(&pcs, matrix_iter.clone()); | |
| let (commitment, prover_data) = pcs.commit(matrix_iter.clone()); |
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.
Yeah, that's what I wrote initially, but it leads to fun type annotations needed errors:
error[E0284]: type annotations needed
--> src/bin/main.rs:384:41
|
384 | let (commitment, prover_data) = pcs.commit(matrix_iter.clone());
| ^^^^^^ cannot infer type for type parameter `Challenger`
|
= note: cannot satisfy `<_ as GrindingChallenger>::Witness == p3_monty_31::monty_31::MontyField31<KoalaBearParameters>`
= note: required for `TwoAdicFriPcs<MontyField31<KoalaBearParameters>, Radix2DFTSmallBatch<MontyField31<KoalaBearParameters>>, MerkleTreeMmcs<..., ..., ..., ..., 8>, ...>` to implement `Pcs<BinomialExtensionField<p3_monty_31::monty_31::MontyField31<KoalaBearParameters>, 4>, _>`
= note: the full name for the type has been written to '/home/basti/src/rust/whir-p3/target/debug/deps/main-6703cdc4c79f20a7.long-type-9852739075644608931.txt'
= note: consider using `--verbose` to print the full type name to the console
error[E0283]: type annotations needed
--> src/bin/main.rs:384:41
|
384 | let (commitment, prover_data) = pcs.commit(matrix_iter.clone());
| ^^^^^^ cannot infer type for type parameter `Challenger`
|
= note: multiple `impl`s satisfying `_: FieldChallenger<p3_monty_31::monty_31::MontyField31<KoalaBearParameters>>` found in the `p3_challenger` crate:
...................................
error[E0283]: type annotations needed
--> src/bin/main.rs:384:41
|
384 | let (commitment, prover_data) = pcs.commit(matrix_iter.clone());
| ^^^^^^ cannot infer type for type parameter `Challenger`
|
= note: multiple `impl`s satisfying `_: CanObserve<p3_symmetric::Hash<p3_monty_31::monty_31::MontyField31<KoalaBearParameters>, p3_monty_31::monty_31::MontyField31<KoalaBearParameters>, 8>>` found in the `p3_challenger` crate:
..................................
at which point I just resigned to calling it as above...
src/bin/main.rs
Outdated
| let (opened_values, proof) = Pcs::<EF, MyChallenger>::open( | ||
| &pcs, | ||
| vec![(&prover_data, points)], | ||
| &mut ctx.challenger.clone(), | ||
| ); |
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.
| let (opened_values, proof) = Pcs::<EF, MyChallenger>::open( | |
| &pcs, | |
| vec![(&prover_data, points)], | |
| &mut ctx.challenger.clone(), | |
| ); | |
| let (opened_values, proof) = pcs.open( | |
| vec![(&prover_data, points)], | |
| &mut ctx.challenger.clone(), | |
| ); |
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.
Huh, this does not actually produce the same problems as for commit. I thought I saw similar errors, but I guess that was while I was still writing code or I misremember.
src/bin/main.rs
Outdated
| let res = Pcs::<EF, MyChallenger>::verify( | ||
| &pcs, | ||
| vec![(commitment, verifier_points)], | ||
| &proof, | ||
| &mut ctx.challenger.clone(), | ||
| ); |
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.
| let res = Pcs::<EF, MyChallenger>::verify( | |
| &pcs, | |
| vec![(commitment, verifier_points)], | |
| &proof, | |
| &mut ctx.challenger.clone(), | |
| ); | |
| let res = pcs.verify( | |
| vec![(commitment, verifier_points)], | |
| &proof, | |
| &mut ctx.challenger.clone(), | |
| ); |
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.
Also works to my surprise.
|
Also I'm pretty sure you are using the packing version of Poseidon2. This should be used automatically due to how you've defined |
|
First of all sorry for being absent. Spent the majority of the week in bed. So before I address some of your comments explicitly, let me show my ignorance. You mention that in the FRI code here we use FRI only as a low degree test. I was under the impression that the Regarding the multi column approach: I did that for three reasons:
I guess that understanding is completely wrong then? I suppose your @tcoratger
addresses parts of my misunderstanding. My long breaks working on other stuff since initially reading up on WHIR and the related concepts is certainly not helping. 🫣
Oh, right. I thought part of my last minute removals of a bunch of leftovers from the entire STARK setup, I also removed this custom
True. For the moment I just assumed the overhead would be small, but that may be wrong. |
This PR adds a comparison to the FRI PCS in the main binary. Due to the very different nature of FRI vs WHIR (multilinear vs univariate), I'm not certain how apples-to-apples this really is.
In addition I still have a few open questions:
TwoAdicMultiplicativeCosetor some other domain?RowMajorMatrixconstruction sensibly? I split the evaluations sampled for WHIR intoNUM_COLS. Currently aconst, but we could make that a command line argument.num_variablesto 25. AtNUM_COLS = 1, this would fail.With the parameters I currently hardcoded, I get this output: