From 4902cd20feacae4a1ec8f6cdc15275fc7797398a Mon Sep 17 00:00:00 2001 From: Jules de Smit Date: Wed, 9 Aug 2023 19:29:01 +0200 Subject: [PATCH] Fix CI --- plonk-core/src/constraint_system/hash.rs | 22 ++++-- plonk-core/src/constraint_system/variable.rs | 7 +- plonk-core/src/proof_system/prover.rs | 2 +- .../src/proof_system/widget/arithmetic.rs | 17 ++++- plonk-hashing/src/poseidon/poseidon_ref.rs | 5 +- .../src/poseidon/zprize_constraints.rs | 74 +++++++++---------- rust-toolchain | 2 +- 7 files changed, 68 insertions(+), 61 deletions(-) diff --git a/plonk-core/src/constraint_system/hash.rs b/plonk-core/src/constraint_system/hash.rs index 93d29ae5..4cc9ac4e 100644 --- a/plonk-core/src/constraint_system/hash.rs +++ b/plonk-core/src/constraint_system/hash.rs @@ -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]) + selectors[1] * self.value_of_var(vars[1]).pow(&[SBOX_ALPHA]) + selectors[2] * self.value_of_var(vars[2]).pow(&[SBOX_ALPHA]) + selectors[3]) @@ -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]) + selectors[1] * self.value_of_var(vars[1]) + selectors[2] * self.value_of_var(vars[2]) + selectors[3]) @@ -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; @@ -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], @@ -184,4 +190,4 @@ mod test { ark_ed_on_bls12_377::EdwardsParameters ) ); -} \ No newline at end of file +} diff --git a/plonk-core/src/constraint_system/variable.rs b/plonk-core/src/constraint_system/variable.rs index 0439e081..b6c5448d 100644 --- a/plonk-core/src/constraint_system/variable.rs +++ b/plonk-core/src/constraint_system/variable.rs @@ -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 @@ -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 diff --git a/plonk-core/src/proof_system/prover.rs b/plonk-core/src/proof_system/prover.rs index e55f3fae..0de77474 100644 --- a/plonk-core/src/proof_system/prover.rs +++ b/plonk-core/src/proof_system/prover.rs @@ -108,7 +108,7 @@ where &self, n: usize, t_x: &DensePolynomial, - ) -> ([DensePolynomial; 8]) { + ) -> [DensePolynomial; 8] { let mut buf = t_x.coeffs.to_vec(); buf.resize(n << 3, F::zero()); diff --git a/plonk-core/src/proof_system/widget/arithmetic.rs b/plonk-core/src/proof_system/widget/arithmetic.rs index 0559d5a4..becb69cd 100644 --- a/plonk-core/src/proof_system/widget/arithmetic.rs +++ b/plonk-core/src/proof_system/widget/arithmetic.rs @@ -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; @@ -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); diff --git a/plonk-hashing/src/poseidon/poseidon_ref.rs b/plonk-hashing/src/poseidon/poseidon_ref.rs index b00ef223..09c23b29 100644 --- a/plonk-hashing/src/poseidon/poseidon_ref.rs +++ b/plonk-hashing/src/poseidon/poseidon_ref.rs @@ -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 = ::Fr; @@ -461,8 +460,8 @@ mod tests { // let mut neptune_poseidon = // neptune::Poseidon::::new(&nep_consts); - // let mut ark_poseidon = PoseidonRef::<(), NativeSpecRef, WIDTH>::new( - // &mut (), + // let mut ark_poseidon = PoseidonRef::<(), NativeSpecRef, + // WIDTH>::new( &mut (), // ark_consts, // ); diff --git a/plonk-hashing/src/poseidon/zprize_constraints.rs b/plonk-hashing/src/poseidon/zprize_constraints.rs index 664048d1..a0a5a4ab 100644 --- a/plonk-hashing/src/poseidon/zprize_constraints.rs +++ b/plonk-hashing/src/poseidon/zprize_constraints.rs @@ -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, @@ -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::>(); - 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, constants: &PoseidonConstants, @@ -232,42 +227,40 @@ impl< let res = state.clone(); let matrix = &constants.mds_matrices.m.iter_rows().collect::>(); - 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, v: Self::ParameterField, @@ -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, @@ -417,8 +410,10 @@ mod tests { let native_hash: Fr = poseidon.output_hash(&mut ()); let mut composer = Composer::new(); - let mut hasher = - PoseidonZZRef::<_, PlonkSpecZZ, 3>::new(&mut composer, param.clone()); + let mut hasher = PoseidonZZRef::<_, PlonkSpecZZ, 3>::new( + &mut composer, + param.clone(), + ); inputs.iter().for_each(|x| { let var = composer.add_input(*x); @@ -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); diff --git a/rust-toolchain b/rust-toolchain index 82166a21..21fe7327 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2022-01-05 +nightly-2023-06-15