From 6026b2b7db908d245d8bb35b40ae0c08a39d7a10 Mon Sep 17 00:00:00 2001 From: sifnoc Date: Fri, 31 May 2024 00:37:15 +0900 Subject: [PATCH 1/4] Added concatenated balance for nonzero constraint process --- prover/src/circuits/config/circuit_config.rs | 21 ++++++++- .../circuits/config/no_range_check_config.rs | 9 ++++ .../src/circuits/config/range_check_config.rs | 8 ++++ prover/src/circuits/summa_circuit.rs | 44 +++++++++++++++---- prover/src/circuits/tests.rs | 2 +- prover/src/entry.rs | 11 +++++ 6 files changed, 84 insertions(+), 11 deletions(-) diff --git a/prover/src/circuits/config/circuit_config.rs b/prover/src/circuits/config/circuit_config.rs index 51382773..fc3821e0 100644 --- a/prover/src/circuits/config/circuit_config.rs +++ b/prover/src/circuits/config/circuit_config.rs @@ -18,12 +18,15 @@ pub trait CircuitConfig: Clone fn configure( meta: &mut ConstraintSystem, username: Column, + concatenated_balance: Column, balances: [Column; N_CURRENCIES], instance: Column, ) -> Self; fn get_username(&self) -> Column; + fn get_concatenated_balance(&self) -> Column; + fn get_balances(&self) -> [Column; N_CURRENCIES]; fn get_instance(&self) -> Column; @@ -49,7 +52,15 @@ pub trait CircuitConfig: Clone || Value::known(big_uint_to_fp::(entry.username_as_big_uint())), )?; - let mut last_decompositions = vec![]; + region.assign_advice( + || "concatenated balance", + self.get_concatenated_balance(), + 0, + || Value::known(big_uint_to_fp::(&entry.concatenated_balance())), + )?; + + // Decompose the balances + let mut assigned_balances = Vec::new(); for (j, balance) in entry.balances().iter().enumerate() { let assigned_balance = region.assign_advice( @@ -59,10 +70,16 @@ pub trait CircuitConfig: Clone || Value::known(big_uint_to_fp(balance)), )?; + assigned_balances.push(assigned_balance); + } + + let mut last_decompositions = vec![]; + + for (j, assigned_balance) in assigned_balances.iter().enumerate() { let mut zs = Vec::with_capacity(4); if !range_check_chips.is_empty() { - range_check_chips[j].assign(&mut region, &mut zs, &assigned_balance)?; + range_check_chips[j].assign(&mut region, &mut zs, assigned_balance)?; last_decompositions.push(zs[3].clone()); } diff --git a/prover/src/circuits/config/no_range_check_config.rs b/prover/src/circuits/config/no_range_check_config.rs index 5d6d4ada..29a144fe 100644 --- a/prover/src/circuits/config/no_range_check_config.rs +++ b/prover/src/circuits/config/no_range_check_config.rs @@ -19,10 +19,13 @@ use super::circuit_config::CircuitConfig; /// # Fields /// /// * `username`: Advice column used to store the usernames of the users +/// * `concentrations`: Advice columns used to store the concentrations of the users /// * `balances`: Advice columns used to store the balances of the users +/// * `instance`: Instance column used to constrain the last balance decomposition #[derive(Clone)] pub struct NoRangeCheckConfig { username: Column, + concatenated_balance: Column, balances: [Column; N_CURRENCIES], instance: Column, } @@ -33,11 +36,13 @@ impl CircuitConfig, username: Column, + concatenated_balance: Column, balances: [Column; N_CURRENCIES], instance: Column, ) -> NoRangeCheckConfig { Self { username, + concatenated_balance, balances, instance, } @@ -47,6 +52,10 @@ impl CircuitConfig Column { + self.concatenated_balance + } + fn get_balances(&self) -> [Column; N_CURRENCIES] { self.balances } diff --git a/prover/src/circuits/config/range_check_config.rs b/prover/src/circuits/config/range_check_config.rs index 7a7c0e8a..6c918dae 100644 --- a/prover/src/circuits/config/range_check_config.rs +++ b/prover/src/circuits/config/range_check_config.rs @@ -18,6 +18,7 @@ use super::circuit_config::CircuitConfig; /// # Fields /// /// * `username`: Advice column used to store the usernames of the users +/// * `concatenated_balance`: Advice column used to store the concatenated balances of the users /// * `balances`: Advice columns used to store the balances of the users /// * `range_check_configs`: Range check chip configurations /// * `range_u16`: Fixed column used to store the lookup table @@ -25,6 +26,7 @@ use super::circuit_config::CircuitConfig; #[derive(Clone)] pub struct RangeCheckConfig { username: Column, + concatenated_balance: Column, balances: [Column; N_CURRENCIES], range_check_configs: [RangeCheckChipConfig; N_CURRENCIES], range_u16: Column, @@ -37,6 +39,7 @@ impl CircuitConfig, username: Column, + concatenated_balance: Column, balances: [Column; N_CURRENCIES], instance: Column, ) -> Self { @@ -68,6 +71,7 @@ impl CircuitConfig CircuitConfig Column { + self.concatenated_balance + } + fn get_balances(&self) -> [Column; N_CURRENCIES] { self.balances } diff --git a/prover/src/circuits/summa_circuit.rs b/prover/src/circuits/summa_circuit.rs index e8762d45..cc76478e 100644 --- a/prover/src/circuits/summa_circuit.rs +++ b/prover/src/circuits/summa_circuit.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; use halo2_proofs::{ circuit::{Layouter, SimpleFloorPlanner}, - plonk::{Circuit, ConstraintSystem, Error}, + plonk::{Circuit, ConstraintSystem, Error, Expression}, poly::Rotation, }; @@ -84,24 +84,52 @@ impl< let username = meta.advice_column(); + let concatenated_balance = meta.advice_column(); + meta.enable_equality(concatenated_balance); + + let q_enable = meta.complex_selector(); + let balances = [(); N_CURRENCIES].map(|_| meta.advice_column()); for column in &balances { meta.enable_equality(*column); } - meta.create_gate("Balance sumcheck gate", |meta| { - let mut nonzero_constraint = vec![]; - for balance in balances { - let current_balance = meta.query_advice(balance, Rotation::cur()); - nonzero_constraint.push(current_balance.clone()); + meta.create_gate("Concatenated balance sumcheck gate", |meta| { + vec![meta.query_advice(concatenated_balance, Rotation::cur())] + }); + + meta.create_gate("Concatenated balance validation check gate", |meta| { + let q_enable = meta.query_selector(q_enable); + + let concatenated_balance = meta.query_advice(concatenated_balance, Rotation::cur()); + let mut expr = Expression::Constant(Fp::zero()); // start with a zero expression if needed + + // Base shift value for 84 bits. + let base_shift = Fp::from(1 << 63).mul(&Fp::from(1 << 21)); + + // We will multiply this base_shift for each balance iteratively. + let mut current_shift = Expression::Constant(Fp::one()); // Start with no shift for the first element. + + for (i, balance_col) in balances.iter().enumerate() { + let balance = meta.query_advice(*balance_col, Rotation::cur()); + let shifted_balance = balance * current_shift.clone(); // Apply the current shift + expr = expr + shifted_balance; // Add to the expression + + // Update the shift for the next iteration + if i < balances.len() - 1 { + // Prevent updating shift unnecessarily on the last element + current_shift = current_shift * Expression::Constant(base_shift); + } } - nonzero_constraint + + // Ensure that the whole expression equals to the concatenated_balance + vec![q_enable * (concatenated_balance - expr)] }); let instance = meta.instance_column(); meta.enable_equality(instance); - CONFIG::configure(meta, username, balances, instance) + CONFIG::configure(meta, username, concatenated_balance, balances, instance) } fn synthesize(&self, config: Self::Config, layouter: impl Layouter) -> Result<(), Error> { diff --git a/prover/src/circuits/tests.rs b/prover/src/circuits/tests.rs index 88bbb4af..e2450ca7 100644 --- a/prover/src/circuits/tests.rs +++ b/prover/src/circuits/tests.rs @@ -177,7 +177,7 @@ fn test_summa_hyperplonk_e2e() { ); assert_eq!( fp_to_big_uint(&witness_polys[1].evaluate_as_univariate(&random_user_index)), - entries[random_user_index].balances()[0] + entries[random_user_index].concatenated_balance() ); // Convert challenge into a multivariate form diff --git a/prover/src/entry.rs b/prover/src/entry.rs index daaef76c..618ab033 100644 --- a/prover/src/entry.rs +++ b/prover/src/entry.rs @@ -34,6 +34,17 @@ impl Entry { &self.balances } + pub fn concatenated_balance(&self) -> BigUint { + let mut concatenated_balance = BigUint::from(0u32); + + for (i, balance) in self.balances.iter().enumerate() { + // Shift bits: 1 for buffer; 19 is highest bit for two power of userbase; 64 is for the maximum range check limit + concatenated_balance += balance << ((1 + 19 + 64) * i); + } + + concatenated_balance + } + pub fn username_as_big_uint(&self) -> &BigUint { &self.username_as_big_uint } From a805edb9590d2b50d3f72f2456bb4605af4d4dc2 Mon Sep 17 00:00:00 2001 From: sifnoc Date: Fri, 31 May 2024 15:58:39 +0900 Subject: [PATCH 2/4] fix: order of assigning balance value following the order of concatenated balance --- prover/Cargo.lock | 216 ++++++++++--------- prover/Cargo.toml | 2 +- prover/src/circuits/config/circuit_config.rs | 109 +++++----- prover/src/circuits/summa_circuit.rs | 49 +++-- prover/src/circuits/tests.rs | 55 ++--- prover/src/entry.rs | 3 +- prover/src/utils/dummy_entries.rs | 3 +- 7 files changed, 218 insertions(+), 219 deletions(-) diff --git a/prover/Cargo.lock b/prover/Cargo.lock index 610ff69a..7dd74ea1 100644 --- a/prover/Cargo.lock +++ b/prover/Cargo.lock @@ -34,9 +34,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.82" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] name = "ark-std" @@ -73,9 +73,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bincode" @@ -154,9 +154,9 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" +checksum = "78834c15cb5d5efe3452d58b1e8ba890dd62d21907f867f383358198e56ebca5" [[package]] name = "byteorder" @@ -172,9 +172,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.94" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" [[package]] name = "cfg-if" @@ -213,12 +213,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" -[[package]] -name = "const-cstr" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed3d0b5ff30645a68f35ece8cea4556ca14ef8a1651455f789a099a0513532a6" - [[package]] name = "constant_time_eq" version = "0.3.0" @@ -243,9 +237,9 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "core-graphics" -version = "0.22.3" +version = "0.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb" +checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" dependencies = [ "bitflags 1.3.2", "core-foundation", @@ -267,9 +261,9 @@ dependencies = [ [[package]] name = "core-text" -version = "19.2.0" +version = "20.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d74ada66e07c1cefa18f8abfba765b486f250de2e4a999e5727fc0dd4b4a25" +checksum = "c9d2790b5c08465d49f8dc05c8bcae9fea467855947db39b0f8145c091aaced5" dependencies = [ "core-foundation", "core-graphics", @@ -288,9 +282,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.4.0" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" dependencies = [ "cfg-if", ] @@ -352,9 +346,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.19" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crypto-common" @@ -366,6 +360,16 @@ dependencies = [ "typenum", ] +[[package]] +name = "cstr" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68523903c8ae5aacfa32a0d9ae60cadeb764e1da14ee0d26b1f3089f13a54636" +dependencies = [ + "proc-macro2", + "quote", +] + [[package]] name = "csv" version = "1.3.0" @@ -510,9 +514,9 @@ dependencies = [ [[package]] name = "either" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" [[package]] name = "fdeflate" @@ -536,9 +540,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.28" +version = "1.0.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +checksum = "5f54427cfd1c7829e2a139fcefea601bf088ebca651d2bf53ebc600eac295dae" dependencies = [ "crc32fast", "miniz_oxide", @@ -546,9 +550,9 @@ dependencies = [ [[package]] name = "float-ord" -version = "0.2.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bad48618fdb549078c333a7a8528acb57af271d0433bdecd523eb620628364e" +checksum = "8ce81f49ae8a0482e4c55ea62ebbd7e5a686af544c00b9d090bba3ff9be97b3d" [[package]] name = "fnv" @@ -558,11 +562,11 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "font-kit" -version = "0.11.0" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21fe28504d371085fae9ac7a3450f0b289ab71e07c8e57baa3fb68b9e57d6ce5" +checksum = "2845a73bbd781e691ab7c2a028c579727cd254942e8ced57ff73e0eafd60de87" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", "byteorder", "core-foundation", "core-graphics", @@ -570,7 +574,7 @@ dependencies = [ "dirs-next", "dwrote", "float-ord", - "freetype", + "freetype-sys", "lazy_static", "libc", "log", @@ -583,34 +587,36 @@ dependencies = [ [[package]] name = "foreign-types" -version = "0.3.2" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" dependencies = [ + "foreign-types-macros", "foreign-types-shared", ] [[package]] -name = "foreign-types-shared" -version = "0.1.1" +name = "foreign-types-macros" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", +] [[package]] -name = "freetype" -version = "0.7.1" +name = "foreign-types-shared" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efc8599a3078adf8edeb86c71e9f8fa7d88af5ca31e806a867756081f90f5d83" -dependencies = [ - "freetype-sys", - "libc", -] +checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" [[package]] name = "freetype-sys" -version = "0.19.0" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66ee28c39a43d89fbed8b4798fb4ba56722cfd2b5af81f9326c27614ba88ecd5" +checksum = "0e7edc5b9669349acfda99533e9e0bcf26a51862ab43b08ee7745c55d28eb134" dependencies = [ "cc", "libc", @@ -636,9 +642,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -839,9 +845,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.153" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libloading" @@ -877,9 +883,9 @@ checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "miniz_oxide" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", "simd-adler32", @@ -887,11 +893,10 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" dependencies = [ - "autocfg", "num-integer", "num-traits", ] @@ -907,9 +912,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -951,9 +956,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "pathfinder_geometry" @@ -989,7 +994,7 @@ checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] name = "plonkish_backend" version = "0.1.0" -source = "git+https://github.com/summa-dev/plonkish?branch=nonzero-constraints#e37ba53dcc8f8bd6e7add4e479d0e3295ee80661" +source = "git+https://github.com/summa-dev/plonkish?branch=nonzero-constraints#c9dc12571d4a9aa06a419598ff2422b42770ae91" dependencies = [ "bincode", "bitvec", @@ -1009,9 +1014,9 @@ dependencies = [ [[package]] name = "plotters" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" +checksum = "a15b6eccb8484002195a3e44fe65a4ce8e93a625797a063735536fd59cb01cf3" dependencies = [ "chrono", "font-kit", @@ -1029,15 +1034,15 @@ dependencies = [ [[package]] name = "plotters-backend" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" +checksum = "414cec62c6634ae900ea1c56128dfe87cf63e7caece0852ec76aba307cebadb7" [[package]] name = "plotters-bitmap" -version = "0.3.3" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cebbe1f70205299abc69e8b295035bb52a6a70ee35474ad10011f0a4efb8543" +checksum = "f7e7f6fb8302456d7c264a94dada86f76d76e1a03e2294ee86ca7da92983b0a6" dependencies = [ "gif", "image", @@ -1046,9 +1051,9 @@ dependencies = [ [[package]] name = "plotters-svg" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" +checksum = "81b30686a7d9c3e010b84284bdd26a29f2138574f52f5eb6f794fc0ad924e705" dependencies = [ "plotters-backend", ] @@ -1083,9 +1088,9 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.80" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] @@ -1206,9 +1211,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "same-file" @@ -1221,15 +1226,15 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] @@ -1246,20 +1251,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.66", ] [[package]] name = "serde_json" -version = "1.0.116" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", @@ -1345,9 +1350,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.59" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a6531ffc7b071655e4ce2e04bd464c4830bb585a61cabb96cf808f05172615a" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", @@ -1382,22 +1387,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.66", ] [[package]] @@ -1429,7 +1434,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.66", ] [[package]] @@ -1443,9 +1448,9 @@ dependencies = [ [[package]] name = "ttf-parser" -version = "0.17.1" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "375812fa44dab6df41c195cd2f7fecb488f6c09fbaafb62807488cefab642bff" +checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" [[package]] name = "typenum" @@ -1461,9 +1466,9 @@ checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-width" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" [[package]] name = "version_check" @@ -1508,7 +1513,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.66", "wasm-bindgen-shared", ] @@ -1530,7 +1535,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.59", + "syn 2.0.66", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1575,11 +1580,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ - "winapi", + "windows-sys", ] [[package]] @@ -1597,6 +1602,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.52.5" @@ -1681,11 +1695,11 @@ dependencies = [ [[package]] name = "yeslogic-fontconfig-sys" -version = "3.2.0" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2bbd69036d397ebbff671b1b8e4d918610c181c5a16073b96f984a38d08c386" +checksum = "ffb6b23999a8b1a997bf47c7bb4d19ad4029c3327bb3386ebe0a5ff584b33c7a" dependencies = [ - "const-cstr", + "cstr", "dlib", "once_cell", "pkg-config", diff --git a/prover/Cargo.toml b/prover/Cargo.toml index a897e375..16740928 100644 --- a/prover/Cargo.toml +++ b/prover/Cargo.toml @@ -30,4 +30,4 @@ criterion= "0.3" [[bench]] name = "proof_of_liabilities" -harness = false \ No newline at end of file +harness = false diff --git a/prover/src/circuits/config/circuit_config.rs b/prover/src/circuits/config/circuit_config.rs index fc3821e0..0d7f5b76 100644 --- a/prover/src/circuits/config/circuit_config.rs +++ b/prover/src/circuits/config/circuit_config.rs @@ -36,85 +36,82 @@ pub trait CircuitConfig: Clone &self, mut layouter: impl Layouter, entries: &[Entry], - grand_total: &[Fp], + concatenated_grand_total: &Fp, ) -> Result<(), Error> { // Initiate the range check chips let range_check_chips = self.initialize_range_check_chips(); for (i, entry) in entries.iter().enumerate() { - let last_decompositions = layouter.assign_region( - || format!("assign entry {} to the table", i), - |mut region| { - region.assign_advice( - || "username", - self.get_username(), - 0, - || Value::known(big_uint_to_fp::(entry.username_as_big_uint())), - )?; - - region.assign_advice( - || "concatenated balance", - self.get_concatenated_balance(), - 0, - || Value::known(big_uint_to_fp::(&entry.concatenated_balance())), - )?; - - // Decompose the balances - let mut assigned_balances = Vec::new(); - - for (j, balance) in entry.balances().iter().enumerate() { - let assigned_balance = region.assign_advice( - || format!("balance {}", j), - self.get_balances()[j], + let last_decompositions: Vec> = layouter + .assign_region( + || format!("assign entry {} to the table", i), + |mut region| { + region.assign_advice( + || "username", + self.get_username(), 0, - || Value::known(big_uint_to_fp(balance)), + || Value::known(big_uint_to_fp::(entry.username_as_big_uint())), )?; - assigned_balances.push(assigned_balance); - } + region.assign_advice( + || "concatenated balance", + self.get_concatenated_balance(), + 0, + || Value::known(big_uint_to_fp::(&entry.concatenated_balance())), + )?; + + // Decompose the balances + let mut assigned_balances = Vec::new(); + + for (j, balance) in entry.balances().iter().enumerate() { + let assigned_balance = region.assign_advice( + || format!("balance {}", j), + self.get_balances()[j], + 0, + || Value::known(big_uint_to_fp(balance)), + )?; + + assigned_balances.push(assigned_balance); + } - let mut last_decompositions = vec![]; + let mut last_decompositions = vec![]; - for (j, assigned_balance) in assigned_balances.iter().enumerate() { - let mut zs = Vec::with_capacity(4); + for (j, assigned_balance) in assigned_balances.iter().enumerate() { + let mut zs = Vec::with_capacity(4); - if !range_check_chips.is_empty() { - range_check_chips[j].assign(&mut region, &mut zs, assigned_balance)?; + if !range_check_chips.is_empty() { + range_check_chips[j].assign( + &mut region, + &mut zs, + assigned_balance, + )?; - last_decompositions.push(zs[3].clone()); + last_decompositions.push(zs[3].clone()); + } } - } - Ok(last_decompositions) - }, - )?; + Ok(last_decompositions) + }, + )?; self.constrain_decompositions(last_decompositions, &mut layouter)?; } let assigned_total = layouter.assign_region( - || "assign total".to_string(), + || "assign concatenated total".to_string(), |mut region| { - let mut assigned_total = vec![]; - - for (j, total) in grand_total.iter().enumerate() { - let balance_total = region.assign_advice( - || format!("total {}", j), - self.get_balances()[j], - 0, - || Value::known(total.neg()), - )?; - - assigned_total.push(balance_total); - } - - Ok(assigned_total) + let balance_total = region.assign_advice( + || format!("concateneated total({} currencies)", N_CURRENCIES), + self.get_concatenated_balance(), + 0, + || Value::known(concatenated_grand_total.nag()), + )?; + + Ok(balance_total) }, )?; - for (j, total) in assigned_total.iter().enumerate() { - layouter.constrain_instance(total.cell(), self.get_instance(), 1 + j)?; - } + layouter.constrain_instance(assigned_total.cell(), self.get_instance(), 1)?; self.load_lookup_table(layouter)?; diff --git a/prover/src/circuits/summa_circuit.rs b/prover/src/circuits/summa_circuit.rs index cc76478e..9bc04003 100644 --- a/prover/src/circuits/summa_circuit.rs +++ b/prover/src/circuits/summa_circuit.rs @@ -5,6 +5,7 @@ use halo2_proofs::{ plonk::{Circuit, ConstraintSystem, Error, Expression}, poly::Rotation, }; +use num_bigint::BigUint; use crate::{entry::Entry, utils::big_uint_to_fp}; @@ -22,7 +23,7 @@ pub struct SummaHyperplonk< CONFIG: CircuitConfig, > { pub entries: Vec>, - pub grand_total: Vec, + pub concatenated_grand_total: Fp, _marker: PhantomData, } @@ -33,16 +34,15 @@ impl< > SummaHyperplonk { pub fn init(user_entries: Vec>) -> Self { - let mut grand_total = vec![Fp::ZERO; N_CURRENCIES]; + let mut concatenated_grand_total = Fp::ZERO; + for entry in user_entries.iter() { - for (i, balance) in entry.balances().iter().enumerate() { - grand_total[i] += big_uint_to_fp::(balance); - } + concatenated_grand_total += big_uint_to_fp::(&entry.concatenated_balance()); } Self { entries: user_entries, - grand_total, + concatenated_grand_total, _marker: PhantomData, } } @@ -53,14 +53,11 @@ impl< pub fn init_invalid_grand_total(user_entries: Vec>) -> Self { use plonkish_backend::util::test::seeded_std_rng; - let mut grand_total = vec![Fp::ZERO; N_CURRENCIES]; - for i in 0..N_CURRENCIES { - grand_total[i] = Fp::random(seeded_std_rng()); - } + let concatenated_grand_total = Fp::random(seeded_std_rng()); Self { entries: user_entries, - grand_total, + concatenated_grand_total, _marker: PhantomData, } } @@ -87,6 +84,11 @@ impl< let concatenated_balance = meta.advice_column(); meta.enable_equality(concatenated_balance); + meta.create_gate("Concatenated balance sumcheck gate", |meta| { + let current_balance = meta.query_advice(concatenated_balance, Rotation::cur()); + vec![current_balance.clone()] + }); + let q_enable = meta.complex_selector(); let balances = [(); N_CURRENCIES].map(|_| meta.advice_column()); @@ -94,23 +96,18 @@ impl< meta.enable_equality(*column); } - meta.create_gate("Concatenated balance sumcheck gate", |meta| { - vec![meta.query_advice(concatenated_balance, Rotation::cur())] - }); - meta.create_gate("Concatenated balance validation check gate", |meta| { let q_enable = meta.query_selector(q_enable); let concatenated_balance = meta.query_advice(concatenated_balance, Rotation::cur()); - let mut expr = Expression::Constant(Fp::zero()); // start with a zero expression if needed - + let mut expr = Expression::Constant(Fp::zero()); // Base shift value for 84 bits. let base_shift = Fp::from(1 << 63).mul(&Fp::from(1 << 21)); - // We will multiply this base_shift for each balance iteratively. - let mut current_shift = Expression::Constant(Fp::one()); // Start with no shift for the first element. + let mut current_shift = Expression::Constant(Fp::one()); - for (i, balance_col) in balances.iter().enumerate() { + // Right-most balance column is for the least significant balance in concatenated balance. + for (i, balance_col) in balances.iter().rev().enumerate() { let balance = meta.query_advice(*balance_col, Rotation::cur()); let shifted_balance = balance * current_shift.clone(); // Apply the current shift expr = expr + shifted_balance; // Add to the expression @@ -133,7 +130,12 @@ impl< } fn synthesize(&self, config: Self::Config, layouter: impl Layouter) -> Result<(), Error> { - CONFIG::synthesize(&config, layouter, &self.entries, &self.grand_total) + CONFIG::synthesize( + &config, + layouter, + &self.entries, + &self.concatenated_grand_total, + ) } } @@ -149,9 +151,6 @@ impl< fn instances(&self) -> Vec> { // The 1st element is zero because the last decomposition of each range check chip should be zero - vec![vec![Fp::ZERO] - .into_iter() - .chain(self.grand_total.iter().map(|x| x.neg())) - .collect::>()] + vec![vec![Fp::ZERO, self.concatenated_grand_total.neg()]] } } diff --git a/prover/src/circuits/tests.rs b/prover/src/circuits/tests.rs index e2450ca7..4980d00b 100644 --- a/prover/src/circuits/tests.rs +++ b/prover/src/circuits/tests.rs @@ -31,7 +31,6 @@ use crate::{ const K: u32 = 17; const N_CURRENCIES: usize = 2; // One row is reserved for the grand total. -// TODO find out what occupies one extra row const N_USERS: usize = (1 << K) - 2; pub fn seeded_std_rng() -> impl RngCore + CryptoRng { @@ -48,21 +47,12 @@ fn test_summa_hyperplonk_e2e() { entries.to_vec(), ); - let neg_grand_total = halo2_circuit - .grand_total - .iter() - .fold(Fp::ZERO, |acc, f| acc + f) - .neg(); + let neg_grand_total = halo2_circuit.concatenated_grand_total.neg(); // We're putting the negated grand total at the end of each balance column, // so the sumcheck over such balance column would yield zero (given the special gate, // see the circuit). - assert!( - neg_grand_total - == halo2_circuit.instances()[0] - .iter() - .fold(Fp::ZERO, |acc, instance| { acc + instance }) - ); + assert!(neg_grand_total == halo2_circuit.instances()[0][1]); let num_vars = K; @@ -95,7 +85,7 @@ fn test_summa_hyperplonk_e2e() { (witness_polys, proof_transcript) }; - let num_points = N_CURRENCIES + 1; + let num_points = 2; let proof = proof_transcript.into_proof(); @@ -239,24 +229,18 @@ fn test_summa_hyperplonk_e2e() { multivariate_challenge.push(kzg_transcript.read_field_element().unwrap()); } - //The user knows their evaluation at the challenge point - let evals: Vec> = (0..N_CURRENCIES + 1) - .map(|i| { - if i == 0 { - Evaluation::new( - i, - 0, - big_uint_to_fp::(entries[random_user_index].username_as_big_uint()), - ) - } else { - Evaluation::new( - i, - 0, - big_uint_to_fp::(&entries[random_user_index].balances()[i - 1]), - ) - } - }) - .collect(); + let evals = vec![ + Evaluation::new( + 0, + 0, + big_uint_to_fp::(entries[random_user_index].username_as_big_uint()), + ), + Evaluation::new( + 1, + 0, + big_uint_to_fp::(&entries[random_user_index].concatenated_balance()), + ), + ]; MultilinearKzg::::batch_verify( &verifier_parameters.pcs, @@ -340,7 +324,10 @@ fn print_univariate_grand_sum_circuit() { let entries = generate_dummy_entries::().unwrap(); - let circuit = SummaHyperplonk::::init(entries.to_vec()); + let circuit = + SummaHyperplonk::>::init( + entries.to_vec(), + ); let root = BitMapBackend::new("prints/summa-hyperplonk-layout.png", (2048, 32768)).into_drawing_area(); @@ -349,7 +336,7 @@ fn print_univariate_grand_sum_circuit() { .titled("Summa Hyperplonk Layout", ("sans-serif", 60)) .unwrap(); - halo2_proofs::dev::CircuitLayout::default() - .render::, _, true>(K, &circuit, &root) + halo2_proofs::dev::Cir::default() + .render::>, _, true>(K, &circuit, &root) .unwrap(); } diff --git a/prover/src/entry.rs b/prover/src/entry.rs index 618ab033..37d4dbd4 100644 --- a/prover/src/entry.rs +++ b/prover/src/entry.rs @@ -37,7 +37,8 @@ impl Entry { pub fn concatenated_balance(&self) -> BigUint { let mut concatenated_balance = BigUint::from(0u32); - for (i, balance) in self.balances.iter().enumerate() { + // To arragne the balances in the correct order, we need to reverse the array + for (i, balance) in self.balances.iter().rev().enumerate() { // Shift bits: 1 for buffer; 19 is highest bit for two power of userbase; 64 is for the maximum range check limit concatenated_balance += balance << ((1 + 19 + 64) * i); } diff --git a/prover/src/utils/dummy_entries.rs b/prover/src/utils/dummy_entries.rs index f566b9c0..bdd507d9 100644 --- a/prover/src/utils/dummy_entries.rs +++ b/prover/src/utils/dummy_entries.rs @@ -21,7 +21,8 @@ pub fn generate_dummy_entries( let username: String = (0..10).map(|_| rng.sample(Alphanumeric) as char).collect(); let balances: [BigUint; N_CURRENCIES] = - std::array::from_fn(|_| BigUint::from(rng.gen_range(1000..90000) as u32)); + // std::array::from_fn(|_| BigUint::from(rng.gen_range(16777215..16777216) as u32)); + std::array::from_fn(|_| BigUint::from(rng.gen_range(10000..90000) as u32)); *entry = Entry::new(username, balances).expect("Failed to create entry"); }); From 9591f1a7512189c39113655b9f370c90da17469c Mon Sep 17 00:00:00 2001 From: sifnoc Date: Mon, 3 Jun 2024 23:32:41 +0900 Subject: [PATCH 3/4] fixing typo --- prover/src/circuits/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prover/src/circuits/tests.rs b/prover/src/circuits/tests.rs index 4980d00b..19a50f0b 100644 --- a/prover/src/circuits/tests.rs +++ b/prover/src/circuits/tests.rs @@ -336,7 +336,7 @@ fn print_univariate_grand_sum_circuit() { .titled("Summa Hyperplonk Layout", ("sans-serif", 60)) .unwrap(); - halo2_proofs::dev::Cir::default() + halo2_proofs::dev::CircuitLayout::default() .render::>, _, true>(K, &circuit, &root) .unwrap(); } From d240cf9653e7a80032f883022d02e51702e8deaf Mon Sep 17 00:00:00 2001 From: sifnoc Date: Tue, 4 Jun 2024 23:36:24 +0900 Subject: [PATCH 4/4] Fix selector and concatenated balance on nonzero-constrain --- backend/Cargo.lock | 2 +- prover/src/circuits/config/circuit_config.rs | 5 +-- .../circuits/config/no_range_check_config.rs | 3 +- .../src/circuits/config/range_check_config.rs | 8 ++--- prover/src/circuits/summa_circuit.rs | 36 +++++++++++-------- prover/src/circuits/tests.rs | 7 ++-- prover/src/utils/dummy_entries.rs | 4 ++- 7 files changed, 37 insertions(+), 28 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 95318bca..24e50410 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -2427,7 +2427,7 @@ checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "plonkish_backend" version = "0.1.0" -source = "git+https://github.com/summa-dev/plonkish?branch=nonzero-constraints#e37ba53dcc8f8bd6e7add4e479d0e3295ee80661" +source = "git+https://github.com/summa-dev/plonkish?branch=nonzero-constraints#c9dc12571d4a9aa06a419598ff2422b42770ae91" dependencies = [ "bincode", "bitvec 1.0.1", diff --git a/prover/src/circuits/config/circuit_config.rs b/prover/src/circuits/config/circuit_config.rs index 0d7f5b76..8c2786a6 100644 --- a/prover/src/circuits/config/circuit_config.rs +++ b/prover/src/circuits/config/circuit_config.rs @@ -1,6 +1,6 @@ use halo2_proofs::{ circuit::{Layouter, Value}, - plonk::{Advice, Column, ConstraintSystem, Error, Instance}, + plonk::{Advice, Column, ConstraintSystem, Error, Instance, Selector}, }; use crate::{entry::Entry, utils::big_uint_to_fp}; @@ -19,6 +19,7 @@ pub trait CircuitConfig: Clone meta: &mut ConstraintSystem, username: Column, concatenated_balance: Column, + selector: Selector, balances: [Column; N_CURRENCIES], instance: Column, ) -> Self; @@ -104,7 +105,7 @@ pub trait CircuitConfig: Clone || format!("concateneated total({} currencies)", N_CURRENCIES), self.get_concatenated_balance(), 0, - || Value::known(concatenated_grand_total.nag()), + || Value::known(concatenated_grand_total.neg()), )?; Ok(balance_total) diff --git a/prover/src/circuits/config/no_range_check_config.rs b/prover/src/circuits/config/no_range_check_config.rs index 29a144fe..e8239aa7 100644 --- a/prover/src/circuits/config/no_range_check_config.rs +++ b/prover/src/circuits/config/no_range_check_config.rs @@ -1,6 +1,6 @@ use halo2_proofs::{ circuit::Layouter, - plonk::{Advice, Column, ConstraintSystem, Error, Instance}, + plonk::{Advice, Column, ConstraintSystem, Error, Instance, Selector}, }; use crate::chips::range::range_check::RangeCheckU64Chip; @@ -37,6 +37,7 @@ impl CircuitConfig, username: Column, concatenated_balance: Column, + _selector: Selector, balances: [Column; N_CURRENCIES], instance: Column, ) -> NoRangeCheckConfig { diff --git a/prover/src/circuits/config/range_check_config.rs b/prover/src/circuits/config/range_check_config.rs index 6c918dae..08ad6f94 100644 --- a/prover/src/circuits/config/range_check_config.rs +++ b/prover/src/circuits/config/range_check_config.rs @@ -1,6 +1,6 @@ use halo2_proofs::{ circuit::{Layouter, Value}, - plonk::{Advice, Column, ConstraintSystem, Error, Fixed, Instance}, + plonk::{Advice, Column, ConstraintSystem, Error, Fixed, Instance, Selector}, }; use crate::chips::range::range_check::{RangeCheckChipConfig, RangeCheckU64Chip}; @@ -40,6 +40,7 @@ impl CircuitConfig, username: Column, concatenated_balance: Column, + selector: Selector, balances: [Column; N_CURRENCIES], instance: Column, ) -> Self { @@ -49,8 +50,6 @@ impl CircuitConfig CircuitConfig) -> Result<(), Error> { diff --git a/prover/src/circuits/tests.rs b/prover/src/circuits/tests.rs index 19a50f0b..d40e65ac 100644 --- a/prover/src/circuits/tests.rs +++ b/prover/src/circuits/tests.rs @@ -29,7 +29,7 @@ use crate::{ }, }; const K: u32 = 17; -const N_CURRENCIES: usize = 2; +const N_CURRENCIES: usize = 3; // One row is reserved for the grand total. const N_USERS: usize = (1 << K) - 2; @@ -85,8 +85,6 @@ fn test_summa_hyperplonk_e2e() { (witness_polys, proof_transcript) }; - let num_points = 2; - let proof = proof_transcript.into_proof(); let mut transcript; @@ -178,6 +176,9 @@ fn test_summa_hyperplonk_e2e() { let mut transcript = Keccak256Transcript::from_proof((), proof.as_slice()); + // Username and Concatenated balance + let num_points = 2; + let user_entry_commitments = MultilinearKzg::::read_commitments( &verifier_parameters.pcs, num_points, diff --git a/prover/src/utils/dummy_entries.rs b/prover/src/utils/dummy_entries.rs index bdd507d9..85e5b099 100644 --- a/prover/src/utils/dummy_entries.rs +++ b/prover/src/utils/dummy_entries.rs @@ -21,7 +21,6 @@ pub fn generate_dummy_entries( let username: String = (0..10).map(|_| rng.sample(Alphanumeric) as char).collect(); let balances: [BigUint; N_CURRENCIES] = - // std::array::from_fn(|_| BigUint::from(rng.gen_range(16777215..16777216) as u32)); std::array::from_fn(|_| BigUint::from(rng.gen_range(10000..90000) as u32)); *entry = Entry::new(username, balances).expect("Failed to create entry"); @@ -32,6 +31,9 @@ pub fn generate_dummy_entries( #[cfg(test)] mod tests { + use crate::utils::big_uint_to_fp; + use halo2_proofs::halo2curves::bn256::Fr as Fp; + use super::*; #[test]