Skip to content

Commit

Permalink
Merge branch 'PlookUp' of github.com:rust-zkp/ark-plonk into PlookUp
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnevadoc committed Apr 11, 2022
2 parents abc727c + d807e7f commit 854f288
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 57 deletions.
2 changes: 1 addition & 1 deletion plonk-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion plonk-core/src/lookup/lookup_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
51 changes: 17 additions & 34 deletions plonk-core/src/permutation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,61 +781,44 @@ 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();
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))
}

fn lookup_numerator_irreducible<F: FftField>(
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<F: FftField>(
fn lookup_ratio<F: FftField>(
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()
}
}

Expand Down
32 changes: 16 additions & 16 deletions plonk-core/src/proof_system/preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
17 changes: 12 additions & 5 deletions plonk-core/src/proof_system/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,11 +509,18 @@ where
where
P: TEModelParameters<BaseField = F>,
{
// 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
Expand Down

0 comments on commit 854f288

Please sign in to comment.