-
Notifications
You must be signed in to change notification settings - Fork 35
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
Circuit improvements #198
Circuit improvements #198
Conversation
|
@alxkzmn thanks for sorting this out! I think that the value that you hardcoded for the merkle tree levels is not correct. These are the parameters that we are using for building the verifier (https://github.com/summa-dev/summa-solvency/blob/circuit-improvement-enrico/zk_prover/examples/gen_inclusion_verifier.rs). Can you update them, adding |
@@ -20,7 +20,7 @@ pub struct MerkleSumTreeConfig { | |||
/// Chip that performs various constraints related to a Merkle Sum Tree data structure such as: | |||
/// | |||
/// * `s * swap_bit * (1 - swap_bit) = 0` (if `bool_and_swap_selector` is toggled). It basically enforces that swap_bit is either a 0 or 1. | |||
/// * `s * (swap_bit * 2 * (elelment_r_cur - elelment_l_cur) - (elelment_l_next - elelment_l_cur) - (elelment_r_cur - elelment_r_next)) = 0`. Enforces that if the swap_bit is equal to 1, the values will be swapped on the next row (if `bool_and_swap_selector` is toggled). | |||
/// * `s * (swap_bit * 2 * (element_r_cur - element_l_cur) - (element_l_next - element_l_cur) - (element_r_cur - element_r_next)) = 0`. Enforces that if the swap_bit is equal to 1, the values will be swapped on the next row (if `bool_and_swap_selector` is toggled). |
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.
The description is outdated
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.
Fixed!
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.
Looks good to me! but I left small thing what i found.
zk_prover/src/circuits/traits.rs
Outdated
@@ -30,4 +30,24 @@ pub trait CircuitBase { | |||
|mut region| region.assign_advice(|| "value", advice_col, 0, || Value::known(value)), | |||
) | |||
} | |||
|
|||
/// /// Loads the lookup table with values from `0` to `2^8 - 1` |
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.
Duplicated ///
zk_prover/src/circuits/traits.rs
Outdated
|
||
/// /// Loads the lookup table with values from `0` to `2^8 - 1` | ||
fn load(&self, layouter: &mut impl Layouter<Fp>, column: Column<Fixed>) -> Result<(), Error> { | ||
let range = 1 << (8); |
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.
May not need parentheses for 8
Thanks @sifnoc, applied changes |
@@ -30,4 +30,24 @@ pub trait CircuitBase { | |||
|mut region| region.assign_advice(|| "value", advice_col, 0, || Value::known(value)), | |||
) | |||
} | |||
|
|||
/// Loads the lookup table with values from `0` to `2^8 - 1` | |||
fn load(&self, layouter: &mut impl Layouter<Fp>, column: Column<Fixed>) -> Result<(), Error> { |
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.
Technically this is not a problem, but this method is very specific to the implementation of our MST. It makes CircuitBase
not a common trait anymore but a specific API for this case, so either naming and description don't correspond to the function anymore, or the method should be inside the MST circuit implementation.
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 guess the trait is a leftover from the time when we had two circuits
0ce4a0d
into
v1-improvements-and-consolidation
* chore: apply clippy fixes * fix: audit comment 1 - Lookup table lives outside of `RangeCheckChip` * fix: audit comment 2 - `swap_constraint` * feat: optimize number of balances to be range checked * chore: update `InclusionVerifier` contract * chore: comment * Record circuit config parameters in the contract * Fix contract deployment parameters * Fix typo * chore: rename to `assetsCount` * chore: update backend * chore: fix comments * chore: minor changes --------- Co-authored-by: Alex Kuzmin <[email protected]>
* chore: apply clippy fixes * fix: audit comment 1 - Lookup table lives outside of `RangeCheckChip` * fix: audit comment 2 - `swap_constraint` * feat: optimize number of balances to be range checked * chore: update `InclusionVerifier` contract * chore: comment * Record circuit config parameters in the contract * Fix contract deployment parameters * Fix typo * chore: rename to `assetsCount` * chore: update backend * chore: fix comments * chore: minor changes --------- Co-authored-by: Alex Kuzmin <[email protected]>
Subject of this PR:
On the last part there's still two missing things:
N_BYTES
andLEVELS
on the smart contract level. (this is better described in the issue) cc: @alxkzmncsv
files folder for Benchmark #197). I think we can still go on and merge this PR and update the benchmarks later @sifnoc