Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jules committed Aug 9, 2023
1 parent 497d76d commit 4902cd2
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 61 deletions.
22 changes: 14 additions & 8 deletions plonk-core/src/constraint_system/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ where
vars: &[Variable; 3],
selectors: &[F; 5],
) -> Variable {
let w4_val = (selectors[0] * self.value_of_var(vars[0]).pow(&[SBOX_ALPHA])
let w4_val = (selectors[0]
* self.value_of_var(vars[0]).pow(&[SBOX_ALPHA])

Check failure on line 26 in plonk-core/src/constraint_system/hash.rs

View workflow job for this annotation

GitHub Actions / Clippy lint checks

the borrowed expression implements the required traits
+ selectors[1] * self.value_of_var(vars[1]).pow(&[SBOX_ALPHA])

Check failure on line 27 in plonk-core/src/constraint_system/hash.rs

View workflow job for this annotation

GitHub Actions / Clippy lint checks

the borrowed expression implements the required traits
+ selectors[2] * self.value_of_var(vars[2]).pow(&[SBOX_ALPHA])

Check failure on line 28 in plonk-core/src/constraint_system/hash.rs

View workflow job for this annotation

GitHub Actions / Clippy lint checks

the borrowed expression implements the required traits
+ selectors[3])
Expand Down Expand Up @@ -74,7 +75,8 @@ where
vars: &[Variable; 3],
selectors: &[F; 5],
) -> Variable {
let w4_val = (selectors[0] * self.value_of_var(vars[0]).pow(&[SBOX_ALPHA])
let w4_val = (selectors[0]
* self.value_of_var(vars[0]).pow(&[SBOX_ALPHA])

Check failure on line 79 in plonk-core/src/constraint_system/hash.rs

View workflow job for this annotation

GitHub Actions / Clippy lint checks

the borrowed expression implements the required traits
+ selectors[1] * self.value_of_var(vars[1])
+ selectors[2] * self.value_of_var(vars[2])
+ selectors[3])
Expand Down Expand Up @@ -115,11 +117,13 @@ where
}
}


#[cfg(test)]
mod test {
use crate::{batch_test, commitment::HomomorphicCommitment, constraint_system::helper::gadget_tester};
use super::*;
use crate::{
batch_test, commitment::HomomorphicCommitment,
constraint_system::helper::gadget_tester,
};
use ark_bls12_377::Bls12_377;
use ark_bls12_381::Bls12_381;

Expand All @@ -146,9 +150,11 @@ mod test {
// 7*2^5+ 11*3 + 13*5 + 17
let e = composer.add_input(F::from(339u64));

let d_rec = composer
.full_affine_transform_gate(&[a, b, c], &[q1, q2, q3, q4,
q5]); composer.assert_equal(d, d_rec);
let d_rec = composer.full_affine_transform_gate(
&[a, b, c],
&[q1, q2, q3, q4, q5],
);
composer.assert_equal(d, d_rec);

let e_rec = composer.partial_affine_transform_gate(
&[a, b, c],
Expand Down Expand Up @@ -184,4 +190,4 @@ mod test {
ark_ed_on_bls12_377::EdwardsParameters
)
);
}
}
7 changes: 3 additions & 4 deletions plonk-core/src/constraint_system/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//! This module holds the components needed in the Constraint System.
//!
//! The two components used are Variables and Wires.
//!
use std::fmt::Display;

/// The value is a reference to the actual value that was added to the
Expand All @@ -16,10 +15,10 @@ use std::fmt::Display;
pub struct Variable(pub(crate) usize);

impl Display for Variable {
// This trait requires `fmt` with this exact signature.
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
// This trait requires `fmt` with this exact signature.
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
}

/// Stores the data for a specific wire in an arithmetic circuit
Expand Down
2 changes: 1 addition & 1 deletion plonk-core/src/proof_system/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ where
&self,
n: usize,
t_x: &DensePolynomial<F>,
) -> ([DensePolynomial<F>; 8]) {
) -> [DensePolynomial<F>; 8] {
let mut buf = t_x.coeffs.to_vec();
buf.resize(n << 3, F::zero());

Expand Down
17 changes: 13 additions & 4 deletions plonk-core/src/proof_system/widget/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

//! Arithmetic Gates

use crate::{proof_system::linearisation_poly::ProofEvaluations, constraint_system::SBOX_ALPHA};
use crate::proof_system::WitnessValues;
use crate::{
constraint_system::SBOX_ALPHA,
proof_system::linearisation_poly::ProofEvaluations,
};
use ark_ff::{FftField, PrimeField};
use ark_poly::{polynomial::univariate::DensePolynomial, Evaluations};
use ark_poly_commit::PolynomialCommitment;
Expand Down Expand Up @@ -176,13 +179,19 @@ where
scalars.push(evaluations.wire_evals.c_eval * q_arith_eval);
points.push(self.q_o.clone());

scalars.push(evaluations.wire_evals.a_eval.pow(&[SBOX_ALPHA]) * q_arith_eval);
scalars.push(
evaluations.wire_evals.a_eval.pow(&[SBOX_ALPHA]) * q_arith_eval,
);
points.push(self.q_hl.clone());

scalars.push(evaluations.wire_evals.b_eval.pow(&[SBOX_ALPHA]) * q_arith_eval);
scalars.push(
evaluations.wire_evals.b_eval.pow(&[SBOX_ALPHA]) * q_arith_eval,
);
points.push(self.q_hr.clone());

scalars.push(evaluations.wire_evals.d_eval.pow(&[SBOX_ALPHA]) * q_arith_eval);
scalars.push(
evaluations.wire_evals.d_eval.pow(&[SBOX_ALPHA]) * q_arith_eval,
);
points.push(self.q_h4.clone());

scalars.push(q_arith_eval);
Expand Down
5 changes: 2 additions & 3 deletions plonk-hashing/src/poseidon/poseidon_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ mod tests {
use super::*;
use ark_ec::PairingEngine;


type E = ark_bls12_381::Bls12_381;
type P = ark_ed_on_bls12_381::EdwardsParameters;
type Fr = <E as PairingEngine>::Fr;
Expand Down Expand Up @@ -461,8 +460,8 @@ mod tests {

// let mut neptune_poseidon =
// neptune::Poseidon::<blstrs::Scalar, NepArity>::new(&nep_consts);
// let mut ark_poseidon = PoseidonRef::<(), NativeSpecRef<Fr>, WIDTH>::new(
// &mut (),
// let mut ark_poseidon = PoseidonRef::<(), NativeSpecRef<Fr>,
// WIDTH>::new( &mut (),
// ark_consts,
// );

Expand Down
74 changes: 34 additions & 40 deletions plonk-hashing/src/poseidon/zprize_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::poseidon::PoseidonError;
use crate::poseidon::constants::PoseidonConstants;
use ark_ec::TEModelParameters;
use ark_ff::PrimeField;
use core::{marker::PhantomData};
use core::marker::PhantomData;
use derivative::Derivative;
use plonk_core::{
constraint_system::StandardComposer,
Expand Down Expand Up @@ -171,53 +171,48 @@ impl<
}

let zero = F::zero();
let current_round_key =

if pre_round_keys.len() == 3{
let current_round_key = if pre_round_keys.len() == 3 {
// Last round
(&zero,&zero,&zero,)
(&zero, &zero, &zero)
} else {
(pre_round_keys[3],pre_round_keys[4],pre_round_keys[5])
(pre_round_keys[3], pre_round_keys[4], pre_round_keys[5])
};


let matrix = &constants.mds_matrices.m.iter_rows().collect::<Vec<_>>();


state[0] = c.full_affine_transform_gate(
&[res[0], res[1], res[2]]
, &[
&[res[0], res[1], res[2]],
&[
matrix[0][0],
matrix[0][1],
matrix[0][2],
*current_round_key.0,
-F::one()
]
-F::one(),
],
);
state[1] = c.full_affine_transform_gate(
&[res[0], res[1], res[2]]
, &[
&[res[0], res[1], res[2]],
&[
matrix[1][0],
matrix[1][1],
matrix[1][2],
*current_round_key.1,
-F::one()
]
-F::one(),
],
);
state[2] = c.full_affine_transform_gate(
&[res[0], res[1], res[2]]
, &[
&[res[0], res[1], res[2]],
&[
matrix[2][0],
matrix[2][1],
matrix[2][2],
*current_round_key.2,
-F::one()
]
-F::one(),
],
);
*constants_offset += WIDTH;
}


fn partial_round(
c: &mut StandardComposer<F, P>,
constants: &PoseidonConstants<Self::ParameterField>,
Expand All @@ -232,42 +227,40 @@ impl<

let res = state.clone();
let matrix = &constants.mds_matrices.m.iter_rows().collect::<Vec<_>>();


state[0] = c.partial_affine_transform_gate(
&[res[0], res[1], res[2]]
, &[
&[res[0], res[1], res[2]],
&[
matrix[0][0],
matrix[0][1],
matrix[0][2],
*pre_round_keys[3],
-F::one()
]
-F::one(),
],
);
state[1] = c.partial_affine_transform_gate(
&[res[0], res[1], res[2]]
, &[
&[res[0], res[1], res[2]],
&[
matrix[1][0],
matrix[1][1],
matrix[1][2],
*pre_round_keys[4],
-F::one()
]
-F::one(),
],
);
state[2] = c.partial_affine_transform_gate(
&[res[0], res[1], res[2]]
, &[
&[res[0], res[1], res[2]],
&[
matrix[2][0],
matrix[2][1],
matrix[2][2],
*pre_round_keys[5],
-F::one()
]
-F::one(),
],
);
*constants_offset += WIDTH;
}


fn alloc(
c: &mut StandardComposer<F, P>,
v: Self::ParameterField,
Expand Down Expand Up @@ -378,11 +371,11 @@ where

#[cfg(test)]
mod tests {
use ark_bls12_381::{Fr};
use ark_bls12_381::Fr;
use ark_ed_on_bls12_381::EdwardsParameters;
use ark_ff::UniformRand;
use ark_std::test_rng;
use plonk_core::prelude::{StandardComposer};
use plonk_core::prelude::StandardComposer;

use crate::poseidon::{
constants::PoseidonConstants,
Expand Down Expand Up @@ -417,8 +410,10 @@ mod tests {
let native_hash: Fr = poseidon.output_hash(&mut ());

let mut composer = Composer::new();
let mut hasher =
PoseidonZZRef::<_, PlonkSpecZZ<Fr>, 3>::new(&mut composer, param.clone());
let mut hasher = PoseidonZZRef::<_, PlonkSpecZZ<Fr>, 3>::new(
&mut composer,
param.clone(),
);

inputs.iter().for_each(|x| {
let var = composer.add_input(*x);
Expand All @@ -431,7 +426,6 @@ mod tests {

let output = hasher.output_hash(&mut composer);


assert_eq!(native_hash, composer.value_of_var(output));

println!("{} {}", param.partial_rounds, param.full_rounds);
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2022-01-05
nightly-2023-06-15

0 comments on commit 4902cd2

Please sign in to comment.