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

Arithmetic gate simplification #59

Closed CPerezz closed 2 years ago

CPerezz commented 2 years ago

The best representation to show how this changes the way of writing circuits is:

let output = composer.big_arith(
    q_m,
    a,
    b,
    q_l,
    q_r,
    Some((q_4, d)),
    q_c,
    None,
);

Now is done as:

let output = composer.arithmetic_gate(|gate| {
    gate.witness(a, b, None)
        .mul(q_m)
        .add(q_l, q_r)
        .fan_in_3(q_4, d)
        .constant(q_c)
});

@ZK-Garage/infra might want to take a look before accepting. Resolves: #46

bhgomes commented 2 years ago

Now is done as:


let output = composer.arithmetic_gate(|gate| {
    gate.witness((a, b, None))
        .mul(q_m)
        .add((q_l, q_r))
        .fan_in_3((q_4, d))
        .const_sel(q_c)

});

Can we remove the redundant parenthesis?

And why not return a builder from arithmetic_gate and call build/finish or something to return the variable. No need for the extra indirection of adding a lambda.

CPerezz commented 2 years ago

Now is done as:

let output = composer.arithmetic_gate(|gate| {
    gate.witness((a, b, None))
        .mul(q_m)
        .add((q_l, q_r))
        .fan_in_3((q_4, d))
        .const_sel(q_c)

});

Can we remove the redundant parenthesis?

And why not return a builder from arithmetic_gate and call build/finish or something to return the variable. No need for the extra indirection of adding a lambda.

I was on it locally :sweat_smile: Solving some test errors first. But definitely I had in mind to remove them! :)

CPerezz commented 2 years ago

LGTM! Address some of the nits and feel free to merge :)

Which nits?

LukePearson1 commented 2 years ago

LGTM! Address some of the nits and feel free to merge :)

Which nits?

The conflicts now. Previously it was the file headers