Skip to content

Commit

Permalink
refactor: remove unnecessary type annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
ashWhiteHat committed Nov 2, 2023
1 parent ca3429a commit f2c538c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
18 changes: 6 additions & 12 deletions primitive/zksnarks/src/groth16/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ impl<P: Pairing, C: Circuit<P::JubjubAffine, ConstraintSystem = Groth16<P::Jubju
impl<P: Pairing, C: Circuit<P::JubjubAffine, ConstraintSystem = Groth16<P::JubjubAffine>>>
Groth16Key<P, C>
{
#[allow(clippy::type_complexity)]
#[allow(unused_variables)]
/// Create a new arguments set from a given circuit instance
///
/// Use the provided circuit instead of the default implementation
Expand All @@ -57,22 +55,20 @@ impl<P: Pairing, C: Circuit<P::JubjubAffine, ConstraintSystem = Groth16<P::Jubju

let size = cs.m().next_power_of_two();
let k = size.trailing_zeros();

let fft = Fft::<P::ScalarField>::new(k as usize);

let (alpha, beta, gamma, delta, tau) = pp.toxic_waste;

let g1 = pp.generators.0;
let g2 = pp.generators.1;
let mut powers_of_tau = PointsValue(vec![P::ScalarField::zero(); cs.m()]);

let gamma_inverse = gamma.invert().ok_or(Error::UnexpectedIdentity)?;
let delta_inverse = delta.invert().ok_or(Error::UnexpectedIdentity)?;

let mut h: Vec<P::G1Affine> =
vec![P::G1Affine::ADDITIVE_IDENTITY; powers_of_tau.0.len() - 1];
let mut h = vec![P::G1Affine::ADDITIVE_IDENTITY; cs.m() - 1];

// Compute (1, tau, tau^2, ...)
let mut powers_of_tau = PointsValue(vec![P::ScalarField::zero(); cs.m()]);
let mut current_pow_of_tau = P::ScalarField::one();
for x in powers_of_tau.0.iter_mut() {
*x = current_pow_of_tau;
Expand All @@ -91,14 +87,12 @@ impl<P: Pairing, C: Circuit<P::JubjubAffine, ConstraintSystem = Groth16<P::Jubju
// Use inverse FFT to convert powers of tau to Lagrange coefficients
let powers_of_tau = fft.idft(powers_of_tau);

let mut a: Vec<P::G1Affine> =
vec![P::G1Affine::ADDITIVE_IDENTITY; cs.instance_len() + cs.witness_len()];
let mut b_g1: Vec<P::G1Affine> =
vec![P::G1Affine::ADDITIVE_IDENTITY; cs.instance_len() + cs.witness_len()];
let mut a = vec![P::G1Affine::ADDITIVE_IDENTITY; cs.instance_len() + cs.witness_len()];
let mut b_g1 = vec![P::G1Affine::ADDITIVE_IDENTITY; cs.instance_len() + cs.witness_len()];
let mut b_g2: Vec<P::G2Affine> =
vec![P::G2Affine::ADDITIVE_IDENTITY; cs.instance_len() + cs.witness_len()];
let mut ic: Vec<P::G1Affine> = vec![P::G1Affine::ADDITIVE_IDENTITY; cs.instance_len()];
let mut l: Vec<P::G1Affine> = vec![P::G1Affine::ADDITIVE_IDENTITY; cs.witness_len()];
let mut ic = vec![P::G1Affine::ADDITIVE_IDENTITY; cs.instance_len()];
let mut l = vec![P::G1Affine::ADDITIVE_IDENTITY; cs.witness_len()];

let ((at_inputs, bt_inputs, ct_inputs), (at_aux, bt_aux, ct_aux)) = cs.inputs_iter();

Expand Down
2 changes: 0 additions & 2 deletions primitive/zksnarks/src/groth16/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ fn get_value_from_wire<F: PrimeField>(index: Wire, vectors: &[Element<F>]) -> Op
None
}

#[allow(clippy::op_ref)]
impl<F: PrimeField> Mul<F> for SparseRow<F> {
type Output = SparseRow<F>;

Expand All @@ -146,7 +145,6 @@ impl<F: PrimeField> Mul<&F> for SparseRow<F> {
}
}

#[allow(clippy::op_ref)]
impl<F: PrimeField> Mul<F> for &SparseRow<F> {
type Output = SparseRow<F>;

Expand Down
2 changes: 0 additions & 2 deletions primitive/zksnarks/src/groth16/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use zkstd::common::*;

/// Kate polynomial commitment params used for prover polynomial domain and proof verification
#[derive(Clone, Debug, PartialEq, Decode, Encode, Default)]
#[allow(dead_code)]
#[allow(clippy::type_complexity)]
pub struct Groth16Params<P: Pairing> {
pub(crate) generators: (P::G1Affine, P::G2Affine),
pub(crate) toxic_waste: (
Expand Down
7 changes: 3 additions & 4 deletions primitive/zksnarks/src/groth16/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ impl<P: Pairing> Prover<P> {
let k = size.trailing_zeros();
let vk = self.params.vk.clone();

let r = P::ScalarField::random(&mut *rng);
let s = P::ScalarField::random(&mut *rng);

let fft = Fft::<P::ScalarField>::new(k as usize);

let (a, b, c) = cs.eval_constraints();

// Do the calculation of H(X): A(X) * B(X) - C(X) == H(X) * T(X)
Expand Down Expand Up @@ -88,6 +84,9 @@ impl<P: Pairing> Prover<P> {
return Err(Groth16Error::General.into());
}

let r = P::ScalarField::random(&mut *rng);
let s = P::ScalarField::random(&mut *rng);

// Setup shift parameters r * delta and s * delta in A, B and C computations.
let mut g_a = vk.delta_g1 * r + vk.alpha_g1;
let mut g_b = vk.delta_g2 * s + vk.beta_g2;
Expand Down

0 comments on commit f2c538c

Please sign in to comment.