Skip to content

Commit

Permalink
Fix minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xevisalle committed Mar 7, 2022
1 parent 7de6fbd commit db2138c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 25 deletions.
7 changes: 4 additions & 3 deletions src/circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ where
&mut self,
pub_params: &PublicParameters,
) -> Result<(ProverKey, VerifierData), Error> {
// Setup PublicParams
// Setup PublicParams, + 6 because adding the blinding factors
// requires some extra elements for the SRS
let (ck, _) = pub_params.trim(self.padded_gates() + 6)?;

// Generate & save `ProverKey` with some random values.
Expand Down Expand Up @@ -296,7 +297,7 @@ where
pub_params: &PublicParameters,
prover_key: &ProverKey,
transcript_init: &'static [u8],
mut rng: &mut R,
rng: &mut R,
) -> Result<Proof, Error> {
let (ck, _) = pub_params.trim(self.padded_gates() + 6)?;

Expand All @@ -308,7 +309,7 @@ where

// Add ProverKey to Prover
prover.prover_key = Some(prover_key.clone());
prover.prove(&ck, &mut rng)
prover.prove(&ck, rng)
}

/// Verify the provided proof for the compiled verifier data
Expand Down
4 changes: 2 additions & 2 deletions src/permutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl Permutation {
beta: &BlsScalar,
gamma: &BlsScalar,
sigma_polys: [&Polynomial; 4],
) -> Vec<dusk_bls12_381::BlsScalar> {
) -> Vec<BlsScalar> {
let n = domain.size();

// Constants defining cosets H, k1H, k2H, etc
Expand Down Expand Up @@ -308,7 +308,7 @@ impl Permutation {
h_2: &[BlsScalar],
delta: &BlsScalar,
epsilon: &BlsScalar,
) -> Vec<dusk_bls12_381::BlsScalar> {
) -> Vec<BlsScalar> {
let n = domain.size();

assert_eq!(f.len(), domain.size());
Expand Down
12 changes: 12 additions & 0 deletions src/proof_system/preprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ impl TurboComposer {
let (_, selectors, preprocessed_table, domain) =
self.preprocess_shared(commit_key, transcript)?;

<<<<<<< HEAD
<<<<<<< HEAD
// The polynomial needs an evaluation domain of 4n.
=======
// the polynomial needs an evaluation domain of 4n.
>>>>>>> 7fb83c2 (Revert move blind to Polynomial)
=======
// The polynomial needs an evaluation domain of 4n.
>>>>>>> 8746288 (Fix minor issues)
// Plus, adding the blinding factors translates to
// the polynomial not fitting in 4n, so now we need
// 8n, the next power of 2
let domain_8n = EvaluationDomain::new(8 * domain.size())?;
let q_m_eval_8n = Evaluations::from_vec_and_domain(
domain_8n.coset_fft(&selectors.q_m),
Expand Down
51 changes: 31 additions & 20 deletions src/proof_system/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,37 @@ impl Prover {

/// Adds the blinding scalars to a given vector. Always the same elements
/// of 'w_vec' are modified at the beginning of it, and appended at the end:
<<<<<<< HEAD
<<<<<<< HEAD
/// if hiding degree = 1: (b2*X^(n+1) + b1*X^n - b2*X - b1) + w_vec
/// if hiding degree = 2: (b3*X^(n+2) + b2*X^(n+1) + b1*X^n - b3*X^2 - b2*X
=======
/// if hiding degree = 1: (b2*X(n+1) + b1*X^n - b2*X - b1) + w_vec
/// if hiding degree = 2: (b3*X^(n+2) + b2*X(n+1) + b1*X^n - b3*X^2 - b2*X
>>>>>>> 7fb83c2 (Revert move blind to Polynomial)
=======
/// if hiding degree = 1: (b2*X^(n+1) + b1*X^n - b2*X - b1) + w_vec
/// if hiding degree = 2: (b3*X^(n+2) + b2*X^(n+1) + b1*X^n - b3*X^2 - b2*X
>>>>>>> 8746288 (Fix minor issues)
/// - b1) + w_vec
pub(crate) fn blind_poly<R: RngCore + CryptoRng>(
w_vec: &Vec<dusk_bls12_381::BlsScalar>,
w_vec: &Vec<BlsScalar>,
hiding_degree: usize,
domain: &EvaluationDomain,
mut rng: &mut R,
rng: &mut R,
) -> Polynomial {
let mut w_vec_i = domain.ifft(w_vec);
let mut w_vec_inverse = domain.ifft(w_vec);

for i in 0..hiding_degree + 1 {
// we declare and randomly select a blinding scalar
let blinding_scalar = util::random_scalar(&mut rng);
w_vec_i[i] = w_vec_i[i] - blinding_scalar; // modify the first elements of the vector
w_vec_i.push(blinding_scalar); // append last elements at the end of
// the vector
let blinding_scalar = util::random_scalar(rng);
// modify the first elements of the vector
w_vec_inverse[i] = w_vec_inverse[i] - blinding_scalar;
// append last elements at the end of the vector
w_vec_inverse.push(blinding_scalar);
}

Polynomial::from_coefficients_vec(w_vec_i)
Polynomial::from_coefficients_vec(w_vec_inverse)
}

/// Creates a [`Proof]` that demonstrates that a circuit is satisfied.
Expand All @@ -183,7 +194,7 @@ impl Prover {
&self,
commit_key: &CommitKey,
prover_key: &ProverKey,
mut rng: &mut R,
rng: &mut R,
) -> Result<Proof, Error> {
// make sure the domain is big enough to handle the circuit as well as
// the lookup table
Expand Down Expand Up @@ -211,10 +222,10 @@ impl Prover {

// Wires are now in evaluation form, convert them to coefficients so
// that we may commit to them
let a_w_poly = Prover::blind_poly(&a_w_scalar, 1, &domain, &mut rng);
let b_w_poly = Prover::blind_poly(&b_w_scalar, 1, &domain, &mut rng);
let c_w_poly = Prover::blind_poly(&c_w_scalar, 1, &domain, &mut rng);
let d_w_poly = Prover::blind_poly(&d_w_scalar, 1, &domain, &mut rng);
let a_w_poly = Prover::blind_poly(&a_w_scalar, 1, &domain, rng);
let b_w_poly = Prover::blind_poly(&b_w_scalar, 1, &domain, rng);
let c_w_poly = Prover::blind_poly(&c_w_scalar, 1, &domain, rng);
let d_w_poly = Prover::blind_poly(&d_w_scalar, 1, &domain, rng);

// Commit to wire polynomials
// ([a(x)]_1, [b(x)]_1, [c(x)]_1, [d(x)]_1)
Expand Down Expand Up @@ -289,7 +300,7 @@ impl Prover {

// Compute long query poly
let f_poly =
Prover::blind_poly(&compressed_f_multiset.0, 1, &domain, &mut rng);
Prover::blind_poly(&compressed_f_multiset.0, 1, &domain, rng);

// Commit to query polynomial
let f_poly_commit = commit_key.commit(&f_poly)?;
Expand All @@ -306,8 +317,8 @@ impl Prover {
let (h_1, h_2) = s.halve_alternating();

// Compute h polys
let h_1_poly = Prover::blind_poly(&h_1.0, 2, &domain, &mut rng);
let h_2_poly = Prover::blind_poly(&h_2.0, 1, &domain, &mut rng);
let h_1_poly = Prover::blind_poly(&h_1.0, 2, &domain, rng);
let h_2_poly = Prover::blind_poly(&h_2.0, 1, &domain, rng);

// Commit to h polys
let h_1_poly_commit = commit_key.commit(&h_1_poly).unwrap();
Expand Down Expand Up @@ -340,7 +351,7 @@ impl Prover {
),
2,
&domain,
&mut rng,
rng,
);

// Commit to permutation polynomial
Expand All @@ -362,7 +373,7 @@ impl Prover {
),
2,
&domain,
&mut rng,
rng,
);

// Commit to permutation polynomial
Expand Down Expand Up @@ -602,7 +613,7 @@ impl Prover {
pub fn prove<R: RngCore + CryptoRng>(
&mut self,
commit_key: &CommitKey,
mut rng: &mut R,
rng: &mut R,
) -> Result<Proof, Error> {
let prover_key: &ProverKey;

Expand All @@ -619,7 +630,7 @@ impl Prover {
prover_key = self.prover_key.as_ref().unwrap();

let proof =
self.prove_with_preprocessed(commit_key, prover_key, &mut rng)?;
self.prove_with_preprocessed(commit_key, prover_key, rng)?;

// Clear witness and reset composer variables
self.clear_witness();
Expand Down
1 change: 1 addition & 0 deletions src/proof_system/widget/permutation/proverkey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl ProverKey {
&self.s_sigma_4.0,
);

// the poly is increased by 2 after blinding it
let domain = EvaluationDomain::new(z_poly.degree() - 2).unwrap();
let c = self.compute_linearizer_check_is_one(
&domain,
Expand Down

0 comments on commit db2138c

Please sign in to comment.