From e98cf5c2e7aa2cf1f571bf67b209adba967f625f Mon Sep 17 00:00:00 2001 From: Joshua B Fitzgerald Date: Wed, 6 Apr 2022 16:43:38 -0400 Subject: [PATCH 1/6] simplify lookup permutation --- plonk-core/src/permutation/mod.rs | 43 +++++++++++-------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/plonk-core/src/permutation/mod.rs b/plonk-core/src/permutation/mod.rs index 2a98f70d..a42e8d16 100644 --- a/plonk-core/src/permutation/mod.rs +++ b/plonk-core/src/permutation/mod.rs @@ -781,16 +781,10 @@ impl Permutation { // Derive the numerator and denominator for each gate plonkup // gate and pair the results .map(|(((((f, t), t_next), h_1), h_1_next), h_2)| { - ( - Self::lookup_numerator_irreducible( - &delta, &epsilon, f, t, &t_next, - ), - Self::lookup_denominator_irreducible( - delta, epsilon, *h_1, h_1_next, *h_2, - ), + Self::lookup_ratio( + delta, epsilon, *f, *t, t_next, *h_1, h_1_next, *h_2, ) }) - .map(|(num, den)| num * den.inverse().unwrap()) .collect(); let mut state = F::one(); @@ -810,32 +804,25 @@ impl Permutation { DensePolynomial::from_coefficients_vec(domain.ifft(&p)) } - fn lookup_numerator_irreducible( - delta: &F, - epsilon: &F, - f: &F, - t: &F, - t_next: &F, - ) -> F { - let prod_1 = F::one() + delta; - let prod_2 = *epsilon + f; - let prod_3 = (*epsilon * prod_1) + t + (*delta * t_next); - - prod_1 * prod_2 * prod_3 - } - - fn lookup_denominator_irreducible( + fn lookup_ratio( delta: F, epsilon: F, + f: F, + t: F, + t_next: F, h_1: F, h_1_next: F, h_2: F, ) -> F { - let epsilon_plus_one_delta = epsilon * (F::one() + delta); - let prod_1 = epsilon_plus_one_delta + h_1 + (h_2 * delta); - let prod_2 = epsilon_plus_one_delta + h_2 + (h_1_next * delta); - - prod_1 * prod_2 + let one_plus_delta = F::one() + delta; + let epsilon_one_plus_delta = epsilon * one_plus_delta; + one_plus_delta + * (epsilon + f) + * (epsilon_one_plus_delta + t + (delta * t_next)) + * ((epsilon_one_plus_delta + h_1 + (h_2 * delta)) + * (epsilon_one_plus_delta + h_2 + (h_1_next * delta))) + .inverse() + .unwrap() } } From 8e7bc71f4b0f23e2e6e59abd94f9cc5739d0d293 Mon Sep 17 00:00:00 2001 From: Joshua B Fitzgerald Date: Wed, 6 Apr 2022 16:48:33 -0400 Subject: [PATCH 2/6] edit lookup perm poly computation --- plonk-core/src/permutation/mod.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/plonk-core/src/permutation/mod.rs b/plonk-core/src/permutation/mod.rs index a42e8d16..c2bfdf8e 100644 --- a/plonk-core/src/permutation/mod.rs +++ b/plonk-core/src/permutation/mod.rs @@ -788,17 +788,13 @@ impl Permutation { .collect(); let mut state = F::one(); - let mut p = Vec::with_capacity(n); + let mut p = Vec::with_capacity(n + 1); p.push(state); - for s in product_arguments { state *= s; p.push(state); } - - // remove the last element - p.remove(n); - + p.pop(); assert_eq!(n, p.len()); DensePolynomial::from_coefficients_vec(domain.ifft(&p)) From d3aa8ec228dc3ebf4924605c6610068df2835bc4 Mon Sep 17 00:00:00 2001 From: Joshua B Fitzgerald Date: Thu, 7 Apr 2022 11:48:01 -0400 Subject: [PATCH 3/6] change vec capacity to accomodate lookups and fix comment --- plonk-core/src/proof_system/proof.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/plonk-core/src/proof_system/proof.rs b/plonk-core/src/proof_system/proof.rs index 83d40e92..b183983b 100644 --- a/plonk-core/src/proof_system/proof.rs +++ b/plonk-core/src/proof_system/proof.rs @@ -509,11 +509,18 @@ where where P: TEModelParameters, { - // 5 for each type of gate + 1 for permutations + 4 for each piece of - // the quotient poly - // TODO How much more for lookups? - let mut scalars = Vec::with_capacity(10); - let mut points = Vec::with_capacity(10); + // 6 for arithmetic + // + 1 for range + // + 1 for logic + // + 1 for fixed base mul + // + 1 for curve add + // + 3 for lookups + // + 2 for permutation + // + 4 for each piece of the quotient poly + // = 19 total scalars and points + + let mut scalars = Vec::with_capacity(19); + let mut points = Vec::with_capacity(19); plonk_verifier_key .arithmetic From cc62f99719a540fcff40c211e827d5cf362bd818 Mon Sep 17 00:00:00 2001 From: Joshua B Fitzgerald Date: Thu, 7 Apr 2022 14:00:14 -0400 Subject: [PATCH 4/6] shorten comments so fmt allows consistency --- plonk-core/src/proof_system/preprocess.rs | 32 +++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/plonk-core/src/proof_system/preprocess.rs b/plonk-core/src/proof_system/preprocess.rs index 259206ac..ef39414a 100644 --- a/plonk-core/src/proof_system/preprocess.rs +++ b/plonk-core/src/proof_system/preprocess.rs @@ -375,22 +375,22 @@ where let verifier_key = widget::VerifierKey::from_polynomial_commitments( self.n, - commitments[0].commitment().clone(), // q_m_poly_commit.0, - commitments[1].commitment().clone(), // q_l_poly_commit.0, - commitments[2].commitment().clone(), // q_r_poly_commit.0, - commitments[3].commitment().clone(), // q_o_poly_commit.0, - commitments[4].commitment().clone(), // q_4_poly_commit.0, - commitments[5].commitment().clone(), // q_c_poly_commit.0, - commitments[6].commitment().clone(), // q_arith_poly_commit.0, - commitments[7].commitment().clone(), // q_range_poly_commit.0, - commitments[8].commitment().clone(), // q_logic_poly_commit.0, - commitments[9].commitment().clone(), /* q_lookup_poly_commit.0, */ - commitments[10].commitment().clone(), /* q_fixed_group_add_poly_commit.0, */ - commitments[11].commitment().clone(), /* q_variable_group_add_poly_commit.0, */ - commitments[12].commitment().clone(), // left_sigma_poly_commit.0, - commitments[13].commitment().clone(), // right_sigma_poly_commit.0, - commitments[14].commitment().clone(), // out_sigma_poly_commit.0, - commitments[15].commitment().clone(), /* fourth_sigma_poly_commit.0, */ + commitments[0].commitment().clone(), // q_m + commitments[1].commitment().clone(), // q_l + commitments[2].commitment().clone(), // q_r + commitments[3].commitment().clone(), // q_o + commitments[4].commitment().clone(), // q_4 + commitments[5].commitment().clone(), // q_c + commitments[6].commitment().clone(), // q_arith + commitments[7].commitment().clone(), // q_range + commitments[8].commitment().clone(), // q_logic + commitments[9].commitment().clone(), // q_lookup + commitments[10].commitment().clone(), // q_fixed_group_add + commitments[11].commitment().clone(), // q_variable_group_add + commitments[12].commitment().clone(), // left_sigma + commitments[13].commitment().clone(), // right_sigma + commitments[14].commitment().clone(), // out_sigma + commitments[15].commitment().clone(), // fourth_sigma preprocessed_table.t[0].1.clone(), preprocessed_table.t[1].1.clone(), preprocessed_table.t[2].1.clone(), From dc0c8d62482c9def134a91126eb62cba1499751f Mon Sep 17 00:00:00 2001 From: David Nevado Date: Fri, 8 Apr 2022 10:37:00 +0200 Subject: [PATCH 5/6] Spelling nit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Carlos Pérez <37264926+CPerezz@users.noreply.github.com> --- plonk-core/src/lookup/lookup_table.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plonk-core/src/lookup/lookup_table.rs b/plonk-core/src/lookup/lookup_table.rs index 937e2868..d95bf466 100644 --- a/plonk-core/src/lookup/lookup_table.rs +++ b/plonk-core/src/lookup/lookup_table.rs @@ -51,7 +51,7 @@ where self.insert_row(F::from(a), F::from(b), F::from(c), F::zero()); } - /// Insert a new row for an multiplication operation. + /// Insert a new row for a multiplication operation. /// This function needs to know the upper bound of the amount of /// multiplication operations that will be done in the plookup table. pub fn insert_mul_row(&mut self, a: u64, b: u64, upper_bound: u64) { From d807e7fa851415167eec3c986f387dc0ddc484e2 Mon Sep 17 00:00:00 2001 From: David Nevado Date: Fri, 8 Apr 2022 10:57:18 +0200 Subject: [PATCH 6/6] Update version MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Carlos Pérez <37264926+CPerezz@users.noreply.github.com> --- plonk-core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plonk-core/Cargo.toml b/plonk-core/Cargo.toml index a4d6f4ed..059372c6 100644 --- a/plonk-core/Cargo.toml +++ b/plonk-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "plonk-core" -version = "0.0.0" +version = "0.1.0" authors = ["ZK-GARAGE Authors"] readme = "README.md" repository = "https://github.com/zk-garage/plonk"