-
Notifications
You must be signed in to change notification settings - Fork 28
Frontend and backend for building circuits #799
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: master
Are you sure you want to change the base?
Conversation
dc664af
to
929eddf
Compare
Suggestions for #799 Feel free to pick and choose from the suggestions. I talk about most of them on your PR. --------- Co-authored-by: dreamATD <tianyi.liu.08@gmail.com>
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.
First pass on gkr_iop
. It makes sense so far.
16b57f3
to
29061f1
Compare
Suggestions for #799 Feel free to pick and choose from the suggestions. I talk about most of them on your PR. --------- Co-authored-by: dreamATD <tianyi.liu.08@gmail.com>
cffdd03
to
d51562b
Compare
/// Chip stores all information required in the GKR protocol, including the | ||
/// commit phases, the GKR phase and the opening phase. | ||
#[derive(Clone, Debug, Default)] | ||
pub struct Chip { |
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.
We can separate ChipBuilder vs ConstrainSystem.
Refer similar design in ceno_zkvm https://github.com/scroll-tech/ceno/blob/master/ceno_zkvm/src/circuit_builder.rs#L487-L488
All the information store in this chip struct should belong to ConstrainSystem
.
So it can be Serializable.
similar as commment here https://github.com/scroll-tech/ceno/pull/799/files#r1904053980
|
||
/// Vector of field type. | ||
#[derive(Clone, PartialEq, Eq)] | ||
pub enum VectorType<E: ExtensionField> { |
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.
we can reuse FieldType as it's exactly same functionality
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.
Sure, can I rename it to be VectorType
?
} | ||
} | ||
|
||
pub fn calc<E: ExtensionField>( |
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.
we should avoid heavily vector clone
internally, by wrap into Rc
or Arc
so we only clone pointer
Also we should improve it with parallel version to boost the performance
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.
Are there any "parallel clone"? Here I only clone for single vector, of which the space will be reused when applying operations, such as follows:
define_commutative_op_mle2!(VectorType, Add, add, |x, y| {
zip_eq(&mut x, y).for_each(|(x, y)| *x += y);
x
});
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.
Awesome job!
I leave few comments in separate section due to large PR so I did the review in segmented time.
Most of the utility of code reused can be done later, I think the most important point might be trying one pre-compile (e.g. keccak-f) first, and benchmark the preliminary performance. Once it meet the requirements, we proceed to more engineering polishing works :)
7762988
to
87d1a30
Compare
Suggestions for #799 Feel free to pick and choose from the suggestions. I talk about most of them on your PR. --------- Co-authored-by: dreamATD <tianyi.liu.08@gmail.com>
87d1a30
to
88f9b00
Compare
related to #191 |
Suggestions for #799 Feel free to pick and choose from the suggestions. I talk about most of them on your PR. --------- Co-authored-by: dreamATD <tianyi.liu.08@gmail.com>
88f9b00
to
eb4c9cb
Compare
Remove buffers and replace the underlying util functions. Add comments and fix some tiny bugs Suggestions for 'Frontend and backend for building circuits' (#801) Suggestions for #799 Feel free to pick and choose from the suggestions. I talk about most of them on your PR. --------- Co-authored-by: dreamATD <tianyi.liu.08@gmail.com> Refine according to comments refine the protocol prover and verifier structs Add more comments Tiny fix according to the latest comments.
eb4c9cb
to
ba053c2
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.
Some quick question
/// Positions to place the evaluations of the base inputs of this layer. | ||
pub in_bases: Vec<EvalExpression>, | ||
/// Positions to place the evaluations of the ext inputs of this layer. | ||
pub in_exts: Vec<EvalExpression>, |
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.
We had MultilinearExtension
+ op_mle_xxx
macro to deal with base/ext poly in unified code flow.
Could you elaborate more on the benefits for splitting them explicitly?
pub struct LayerWitness<E: ExtensionField> { | ||
pub bases: Vec<Vec<E::BaseField>>, | ||
pub exts: Vec<Vec<E>>, | ||
pub num_vars: usize, |
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.
same as above, could we make them all inDenseMultiliearPoly
format? with that we can make vector + num_vars in same structure
`keccakf` precompile + GKR-IOP integration
This is an implementation of the expression-based and plonkish-like GKR IOP protocol. The circuit is denoted as
Chip
, holding all information to process commit phases and GKR proving phase. In the current implementation, we assume there are two commit phases. To process the GKR phase, we extract aGKRCircuit
from it and run the GKR protocol. For the implementation status, the GKR phase is ready for review, while the commit phases hasn't been finalized.Define a GKR IOP protocol for a chip includes defining
build_commit_phase
,build_commit_phase2
andbuild_gkr_phase
. Specially,build_gkr_phase
is mainly to build GKR layers in the reverse order. In addition to specify the expressions, to simplify the case of either transferring evaluations from an input of a succeeding layer to an output of the current layer or even make some computations before feeding to the current layer, we use an evaluation tape to place the evaluations andEvalExpression
to define the computation. Each layer input will be assigned a position in the evaluation tape.EvalExpression
is defined as follows:of which the items denote how to compute the output evaluations. For more details please refer to gkr_iop/src/evaluation.rs.
Here are some subsequent tasks:
subprotocols/src/expression/
.Although the previous tasks should be done, I suggest to start the first round of review first. Would like to see comments from @naure and @hero78119 so that I can adjust the design before moving forward.
Upd: The design doc: https://hackmd.io/@sphere-liu/HyLR-h2L1g.