-
Notifications
You must be signed in to change notification settings - Fork 89
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
Nova backend in Supernova R1CS #453
Conversation
Updated:
TODO
|
Thanks! I'll start reviewing it today. |
Updated:
|
about this @hero78119 . What do you mean by witnesses are wrong? Currently unused columns should be removed completely, so if this is buggy we should open a separate issue and investigate there. |
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.
Basic review for the non-Nova related things. Doing the new nova crate next.
@@ -1,2 +1,2 @@ | |||
[toolchain] | |||
channel = "stable" | |||
channel = "nightly" |
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.
I don't think this is a good idea... why do we need nightly?
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.
because im using a #![feature(box_patterns)]
pattern match to retrieve expression inside Box<Expression>
to make code less verbose, and this feature is not in stable channel.
it just temporarily here and will remove it once figure out how to make pattern match efficiently
@@ -62,6 +62,9 @@ pub struct Halo2MockBackend; | |||
#[cfg(feature = "halo2")] | |||
pub struct Halo2AggregationBackend; | |||
|
|||
#[cfg(feature = "nova")] | |||
pub struct NovaBackend; |
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.
There's currently a refactoring going on changing this backend
crate, #417 . It shouldn't be too hard to rebase after it gets merged.
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.
Notice that after 417 merge, if adding powdr-asm
raw parsed data then it will affect other backend, i.e. Halo2 as well, because now prove
function are unified.
Since now Nova still need to parse information from powdr-asm meta. Will rebase later once we figure out a better way to deal with meta info from PIL directly.
@@ -14,7 +14,8 @@ use json::JsonValue; | |||
pub mod util; | |||
mod verify; | |||
|
|||
use analysis::analyze; | |||
// TODO should analyze be `pub`? |
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.
If needed, sure.
@@ -184,6 +186,29 @@ enum Commands { | |||
params: Option<String>, | |||
}, | |||
|
|||
ProveNova { |
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.
It probably does make sense to keep Nova separated from the other backends for now since it needs the asm
file too, but eventually we should also just add Nova
to the backends enum and support it in the normal pipeline.
PR Updated
Witness are wrong means the witness doesnt satisfy the constraints, I will try to reproduce it later and if confirm, will report in a separate issue |
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.
A few more comments, missing only the main part of circuit_builder.rs
zero_nova/zero.asm
Outdated
|
||
instr incr X -> Y { | ||
// range check on X | ||
// Y = Z + 1, // this one work means assignment register signature `X -> Y` doen't take effect lol ? |
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.
Currently all registers are available in instructions so you can use the byte registers for example for byte composition, the input/output ones are just to typecheck the calls and do assignments.
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.
yes I aware of this.
As the time of writing, now each instruction augmented circuit only parse the constraints inside the instruction definition, but not parsing the general constraints due to efficiency concern.
@leonardoalt I think there are 2 design choices
inline
support: since each instruction is self-contained in current folding schems, do you think it make sense to have someinline
feature during asm -> pil compiler, so all the constraints being touch by instruction A, it will be layout in the line of i.e.instr_A * (all the constrains chain)
?nova augment circuit builder optimisation
: introduce some lazily constraints compiling strategy in nova augment circuit parsing, such as DFS recursive traverse to expand polynomial reference in constraints area. This is optimise so other un-related constraints will not be compiled into the circuit
or is there other better way is welcome :)
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.
- Currently this is done like this, but I think inside constraints for next-registers. Need to think about it.
- This direction sounds good, yes.
Another thing that I haven't understood so far is, what happens to the constraints
block of a machine? These constraints should be true for every line, so are they used in the single-instruction-circuits?
The comments above show as outdated because of the change in the directory name from |
Sure :) along with renaming crate to |
3af4c2f
to
7bea53f
Compare
Impressive work @hero78119 ! I'm still going through the main parts of There's one thing that could make it easier for me and others to review/understand it: if it's not too much work, could you add a README in the Nova crate with a succinct explanation of how the constraint generation works, perhaps over a small example, like the test you added? Visualizing the source instructions/program and the generated constraints would help a lot in matching the behavior to the code. Thanks! |
Hi @leonardoalt, an simple README is added in latest commit 9bce29f |
a35c65a
to
a3078ae
Compare
Updated:
|
polish comments supernova finish constaints done, add workaround to collect meta info from asm source more commments supernova prove&verify successfully support unsigned const in instruction param remove temporarily file rename zero_nova crate to nova cosmetics comment cite private mod from nova unify way to convert between FieldElement & PrimeField nova crate readme support PIL constant constraints in R1CS forcely nova refactor to separate codebase into different mod
Updated:
Right now 3 major functionality are lefted
Following by another big topic
After that, I think Nova backend will be preliminary ready as a folding backend in R1CS. |
Updated: Pending Topic:
|
Super cool stuff! I have yet to dig into the low level details but jugging from the high level my main thoughts now are:
You turn instruction blocks into R1CS. What would be your plan when it comes to introducing intermediate values? I'm thinking you could allow local declarations of committed polynomials:
This is abusing the semantics of PIL a bit, but it seems to me that it would work: if you consider a single row of the execution trace, each instruction circuit can "extend" the set of columns with more columns and have constraints between them on that same row.
I'll add more thoughts as I understand the internals better. |
Hi~ sorry a bit late reply for being on vocation 😃
For current PR circuit parser design, extending intermediate variables defined in its respective instr block is well supported without need for any change. Each instruction is in respective isolated constraint system, so there is also free of variables naming confliction problem. One nice features is, supporting
I think one open question is powdr asm meta info => now for building Nova circuit, there are few meta info fetching from powdr asm => we need a way to integrate them together with PIL language so we can fetch them from same place, or we find way to unify both infornation into a new structure data.
Yeah and good idea! I will do that sooner
Appreciated if for further review :) |
I'm trying to run some tests with the Nova backend, and I ran into a panic. # running this first to get the pil file out of the asm file
cargo run --release pil test_data/asm/simple_sum.asm -f -i "1,1,1" --field bn254
# then the nova backend
cargo run --release prove-nova simple_sum_opt.pil test_data/asm/simple_sum.asm -i "1,1,1" Any ideas why? |
Hi, it's due to previously I assumed only support jump to the label ahead. Now with command
it will run into new error
This is expected for now, because with current folding per instruction design philosophy with SuperNova, it's hard to support syntax input retrieving with expression Understand there will be another scenario for Frontend program which will touch the dynamic input position via expression + variable. One workaround I can imagine is linker assembly stage convert it to memory load instruction. Then the prover input is also encode into memory commitment, then it will be work nicely in Nova use case Appreciated if there is further suggestion :) |
I met IRL with @hero78119 and we had a discussion about this PR, I understand how it works now! It's really neat. |
This PR is aimed for powdr-asm VM to support folding scheme nova backend as R1CS, to benefit constant size circuit & prove on arbitrary length of computation
In the prelimenary version, most of circuit logic are in
circuit_builder.rs
Features highlights (TBC)
pc
witness support marknext
.Features list:
instr
into bellperson constraints.Other pending topic
Step to run
compile pil
run nova prove step
Spotted Issues
reg
in asm then compile to pil, compile will success also show witness inference success, however some witness are wrong by print out them to check. Detail reason still unknown