ZK-Garage / plonk

A pure Rust PLONK implementation using arkworks as a backend.
https://discord.gg/XWJdhVf37F
Mozilla Public License 2.0
295 stars 76 forks source link

Refactor Gadget definition strategy to treat it as a `Gate` or `Collection of Gates` #102

Open CPerezz opened 2 years ago

CPerezz commented 2 years ago

With this change, it would be possible to add &str definitions for each gate created which can be used for debugging purposes later on.

The idea is to end up with something much closer and that is better handled in other libs such as Halo2 which looks like:

meta.create_gate("R1CS constraint", |meta| {
             let a = meta.query_advice(a, Rotation::cur());
             let b = meta.query_advice(b, Rotation::cur());
             let c = meta.query_advice(c, Rotation::cur());
             let s = meta.query_selector(s);

             // BUG: Should be a * b - c
             Some(("buggy R1CS", s * (a * b + c)))
         });

Which enables producing better err messages while debugging like:

Err(vec![VerifyFailure::ConstraintNotSatisfied {
constraint: ((0, "R1CS constraint").into(), 0, "buggy R1CS").into(),
location: FailureLocation::InRegion {
region: (0, "Example region").into(),
offset: 0,
},

That overall should help to: