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

Implement Plonky3 frontend adaptor #306

Merged
merged 27 commits into from
May 27, 2024
Merged

Implement Plonky3 frontend adaptor #306

merged 27 commits into from
May 27, 2024

Conversation

ed255
Copy link
Member

@ed255 ed255 commented Apr 2, 2024

Plonky3 frontend implementation. Allows using a circuit defined with the Air trait from plonky3 to be proved with a halo2 backend.

Bump rust version from 1.73.0 to 1.75.0 because plonky3 requires it.

ed255 added 10 commits March 27, 2024 15:32
- Bring back Rc instead of Box in SymbolicExpression so that expressions
  built with folding avoid many clones
- Rewrite Expression doulbe as `e * 2` instead of `e + e` to avoid
  exponential cloning in expressions built with folding
- When a constraint doesn't use a location, change it to use a selector
  for usable columns to avoid failing in poisoned rows
@CPerezz CPerezz self-requested a review April 8, 2024 10:55
@ed255 ed255 changed the title Implement plonky3 frontend adaptor Implement Plonky3 frontend adaptor Apr 8, 2024
@ed255 ed255 marked this pull request as ready for review April 9, 2024 11:08
@ed255
Copy link
Member Author

ed255 commented Apr 9, 2024

I just made this PR ready for review to get some feedback.
There are some TODOs in the code but the main logic is working.

Copy link

@davidnevadoc davidnevadoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for the TODOs you left, everything else LGTM.
Really cool to see the modularity of the front-back split in action :)

&|v| match v {
VarMid::Query(q) => {
let offset = offset as i32 + q.rotation.0;
// TODO: Try to do mod n with a rust function

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the expected behavior.
I'd say its probably simpler and safer to disallow querying next in the last row. I may be mistaken though and would be very interested in seeing a circuit that makes use of the "cycle" in the rows.

Copy link
Member Author

@ed255 ed255 May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I haven't seen a circuit that does this:

  • querying next on the last row
  • querying prev in the first row

But this is technically valid in Plonkish. If you have blinding rows, probably this doesn't make sense (but we support unblinded columns). This is a function that checks if the witness passes the constraints and my goal was to make this function accept all witnesses that would pass the constraints. So if the witness can be used to calculate a valid proof, I'd like this function to accept such a witness. It's like a simplified mock prover.

Also very important: this function receives CompiledCircuitV2 so it's not AIR specific!

p3_frontend/src/lib.rs Outdated Show resolved Hide resolved
@codecov-commenter
Copy link

codecov-commenter commented May 17, 2024

Codecov Report

Attention: Patch coverage is 95.93095% with 33 lines in your changes are missing coverage. Please review.

Project coverage is 81.84%. Comparing base (87fb07f) to head (37c916f).

Files Patch % Lines
p3_frontend/src/lib.rs 94.00% 15 Missing ⚠️
p3_frontend/src/symbolic_expression.rs 95.33% 11 Missing ⚠️
p3_frontend/src/fwrap.rs 97.68% 5 Missing ⚠️
halo2_backend/src/helpers.rs 0.00% 1 Missing ⚠️
p3_frontend/src/symbolic_builder.rs 97.14% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #306      +/-   ##
==========================================
+ Coverage   80.86%   81.84%   +0.97%     
==========================================
  Files          80       82       +2     
  Lines       16567    17000     +433     
==========================================
+ Hits        13397    13913     +516     
+ Misses       3170     3087      -83     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ed255
Copy link
Member Author

ed255 commented May 21, 2024

I've added unit tests and increased the test coverage to ~90%
The only file that doesn't have unit tests is the p3_frontend/src/lib.rs, but most of it is covered by the fibonacci and keccak tests. Nevertheless I may add unit tests for that in the future.

p3_frontend/src/fwrap.rs Outdated Show resolved Hide resolved
let mut trace =
RowMajorMatrix::new(vec![F::zero(); n * NUM_FIBONACCI_COLS], NUM_FIBONACCI_COLS);

let (prefix, rows, suffix) = unsafe { trace.values.align_to_mut::<FibonacciRow<F>>() };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:feelsgood:

rust-toolchain Outdated Show resolved Hide resolved
Copy link
Member

@adria0 adria0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, it's nice to have a new frontend! :)

@ed255 ed255 merged commit b76ffc2 into main May 27, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants