Skip to content
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

Use batch commitment scheme and commit only polynomial linear combination #144

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions plonk-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ merlin = { version = "3.0", default-features = false }
num-traits = { version = "0.2.14" }
rand_core = {version = "0.6", default-features=false, features = ["getrandom"] }

ark-marlin = "0.3.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In regards of ark-marlin, we are just getting FiatShamirRng. Don't we have an alternative to save us this dep and more complexity?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think that in the newer version FiatShamirRng is separated from ark-marlin, will make sure to check and fix :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If possible, I would not recommend using ark-marlin as a dependency to use FiatShamirRng, because as CPerezz pointed out, there would be significant refactoring around FiatShamirRng in arkworks-rs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you recommend using until then?

digest = { version = "0.9" }

[dev-dependencies]
ark-bls12-377 = "0.3"
ark-bls12-381 = "0.3"
Expand Down
4 changes: 2 additions & 2 deletions plonk-core/src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ where
fn compile<PC>(
&mut self,
u_params: &PC::UniversalParams,
) -> Result<(ProverKey<F>, VerifierKey<F, PC>), Error>
) -> Result<(ProverKey<F, PC>, VerifierKey<F, PC>), Error>
where
F: PrimeField,
PC: HomomorphicCommitment<F>,
Expand Down Expand Up @@ -265,7 +265,7 @@ where
fn gen_proof<PC>(
&mut self,
u_params: &PC::UniversalParams,
prover_key: ProverKey<F>,
prover_key: ProverKey<F, PC>,
transcript_init: &'static [u8],
) -> Result<(Proof<F, PC>, PublicInputs<F>), Error>
where
Expand Down
11 changes: 6 additions & 5 deletions plonk-core/src/proof_system/linearisation_poly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Copyright (c) DUSK NETWORK. All rights reserved.

use crate::{
commitment::HomomorphicCommitment,
error::Error,
label_eval,
proof_system::{
Expand Down Expand Up @@ -161,9 +162,9 @@ where
}

/// Compute the linearisation polynomial.
pub fn compute<F, P>(
pub fn compute<F, P, PC: HomomorphicCommitment<F>>(
domain: &GeneralEvaluationDomain<F>,
prover_key: &ProverKey<F>,
prover_key: &ProverKey<F, PC>,
alpha: &F,
beta: &F,
gamma: &F,
Expand Down Expand Up @@ -284,7 +285,7 @@ where
table_next_eval,
};

let gate_constraints = compute_gate_constraint_satisfiability::<F, P>(
let gate_constraints = compute_gate_constraint_satisfiability::<F, P, PC>(
range_separation_challenge,
logic_separation_challenge,
fixed_base_separation_challenge,
Expand Down Expand Up @@ -350,15 +351,15 @@ where

/// Computes the gate constraint satisfiability portion of the linearisation
/// polynomial.
fn compute_gate_constraint_satisfiability<F, P>(
fn compute_gate_constraint_satisfiability<F, P, PC: HomomorphicCommitment<F>>(
range_separation_challenge: &F,
logic_separation_challenge: &F,
fixed_base_separation_challenge: &F,
var_base_separation_challenge: &F,
wire_evals: &WireEvaluations<F>,
q_arith_eval: F,
custom_evals: &CustomEvaluations<F>,
prover_key: &ProverKey<F>,
prover_key: &ProverKey<F, PC>,
) -> DensePolynomial<F>
where
F: PrimeField,
Expand Down
25 changes: 14 additions & 11 deletions plonk-core/src/proof_system/permutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,34 @@ use ark_poly::{
polynomial::univariate::DensePolynomial, EvaluationDomain, Evaluations,
GeneralEvaluationDomain,
};
use ark_poly_commit::PCCommitment;
use ark_poly_commit::{PCCommitment, PolynomialCommitment};
use ark_serialize::*;

// Copy(bound = "PC::Commitment: Copy"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover?

/// Permutation Prover Key
#[derive(CanonicalDeserialize, CanonicalSerialize, derivative::Derivative)]
#[derivative(
Clone(bound = ""),
Debug(bound = ""),
Eq(bound = ""),
PartialEq(bound = "")
Clone,
Debug(bound = "PC::Commitment: std::fmt::Debug"),
Eq(bound = "PC::Commitment: Eq"),
PartialEq(bound = "PC::Commitment: PartialEq")
)]
pub struct ProverKey<F>
pub struct ProverKey<F, PC>
where
F: FftField,
PC: PolynomialCommitment<F, DensePolynomial<F>>,
{
/// Left Permutation
pub left_sigma: (DensePolynomial<F>, Evaluations<F>),
pub left_sigma: (DensePolynomial<F>, Evaluations<F>, PC::Commitment),

/// Right Permutation
pub right_sigma: (DensePolynomial<F>, Evaluations<F>),
pub right_sigma: (DensePolynomial<F>, Evaluations<F>, PC::Commitment),

/// Output Permutation
pub out_sigma: (DensePolynomial<F>, Evaluations<F>),
pub out_sigma: (DensePolynomial<F>, Evaluations<F>, PC::Commitment),

/// Fourth Permutation
pub fourth_sigma: (DensePolynomial<F>, Evaluations<F>),
pub fourth_sigma: (DensePolynomial<F>, Evaluations<F>, PC::Commitment),

/// Linear Evaluations
pub linear_evaluations: Evaluations<F>,
Expand All @@ -53,9 +55,10 @@ where
* domain elements] */
}

impl<F> ProverKey<F>
impl<F, PC> ProverKey<F, PC>
where
F: FftField,
PC: PolynomialCommitment<F, DensePolynomial<F>>,
{
/// Computes permutation term of the quotient polynomial at the `i`th domain
/// point.
Expand Down
46 changes: 41 additions & 5 deletions plonk-core/src/proof_system/preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ where
commit_key: &PC::CommitterKey,
transcript: &mut Transcript,
_pc: PhantomData<PC>,
) -> Result<ProverKey<F>, Error>
) -> Result<ProverKey<F, PC>, Error>
where
PC: HomomorphicCommitment<F>,
{
Expand Down Expand Up @@ -215,6 +215,26 @@ where
let v_h_coset_4n =
compute_vanishing_poly_over_coset(domain_4n, domain.size() as u64);

let (
left_sigma_poly,
right_sigma_poly,
out_sigma_poly,
fourth_sigma_poly,
) = self.perm.compute_sigma_polynomials(self.n, &domain);

let (commitments, _) = PC::commit(
commit_key,
[
label_polynomial!(left_sigma_poly),
label_polynomial!(right_sigma_poly),
label_polynomial!(out_sigma_poly),
label_polynomial!(fourth_sigma_poly),
]
.iter(),
None,
)
.map_err(to_pc_error::<F, PC>)?;

Ok(ProverKey::from_polynomials_and_evals(
domain.size(),
(selectors.q_m, q_m_eval_4n),
Expand All @@ -229,10 +249,26 @@ where
(selectors.q_lookup, q_lookup_eval_4n),
(selectors.q_fixed_group_add, q_fixed_group_add_eval_4n),
(selectors.q_variable_group_add, q_variable_group_add_eval_4n),
(selectors.left_sigma, left_sigma_eval_4n),
(selectors.right_sigma, right_sigma_eval_4n),
(selectors.out_sigma, out_sigma_eval_4n),
(selectors.fourth_sigma, fourth_sigma_eval_4n),
(
selectors.left_sigma,
left_sigma_eval_4n,
commitments[0].commitment().clone(),
),
(
selectors.right_sigma,
right_sigma_eval_4n,
commitments[1].commitment().clone(),
),
(
selectors.out_sigma,
out_sigma_eval_4n,
commitments[2].commitment().clone(),
),
(
selectors.fourth_sigma,
fourth_sigma_eval_4n,
commitments[3].commitment().clone(),
),
linear_eval_4n,
v_h_coset_4n,
preprocessed_table.t[0].0.clone(),
Expand Down
Loading