Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.

Commit

Permalink
fix issue in bench; add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Boyuan Feng committed Apr 27, 2022
1 parent 7f887b4 commit bae3f95
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/benches/poseidon_opt_native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn poseidon_opt_native(c: &mut Criterion) {
group.bench_function("Poseidon NATIVE Height-20 ARITY-2 MT", |b| {
let inputs = (0..20).map(|_| Fr::rand(&mut rng)).collect::<Vec<_>>();
b.iter(|| {
let mut poseidon = Poseidon::<(), NativeSpec<Fr, 3>, 3>::new(&mut (), param.clone());
let mut poseidon = Poseidon::<(), NativeSpec<Fr, 3>, 3>::new(&mut (), &param);
let mut curr_hash = Fr::zero();
for x in inputs.iter() {
poseidon.reset(&mut ());
Expand Down
2 changes: 1 addition & 1 deletion src/benches/poseidon_opt_plonk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where
const CIRCUIT_ID: [u8; 32] = [0xff; 32];

fn gadget(&mut self, composer: &mut StandardComposer<F, P>) -> Result<(), Error> {
let mut poseidon = Poseidon::<_, PlonkSpec<3>, 3>::new(composer, self.constants.clone());
let mut poseidon = Poseidon::<_, PlonkSpec<3>, 3>::new(composer, &self.constants);

let inputs_var = self
.input
Expand Down
2 changes: 1 addition & 1 deletion src/benches/poseidon_opt_r1cs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl ConstraintSynthesizer<Fr> for TestCircuit
fn generate_constraints(self, mut cs: ConstraintSystemRef<Fr>) -> Result<(), SynthesisError> {
const WIDTH: usize = 3;
let mut poseidon =
Poseidon::<_, R1csSpec<Fr, WIDTH>, WIDTH>::new(&mut cs, self.constants.clone());
Poseidon::<_, R1csSpec<Fr, WIDTH>, WIDTH>::new(&mut cs, &self.constants);

let inputs_var = self
.input
Expand Down
6 changes: 6 additions & 0 deletions src/poseidon/poseidon_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use plonk_core::prelude as plonk;
use std::fmt::{Debug};
use std::marker::PhantomData;

/// Trait for unoptimized poseidon hash.
pub trait PoseidonRefSpec<COM, const WIDTH: usize> {
/// Field used as state
type Field: Debug + Clone;
Expand Down Expand Up @@ -234,6 +235,8 @@ pub struct NativeSpecRef<F: PrimeField> {
}

impl<F: PrimeField, const WIDTH: usize> PoseidonRefSpec<(), WIDTH> for NativeSpecRef<F> {
// Field is private variables, ParameterField is public constants.
// In Naitve Spec, we do not distinguish these two values.
type Field = F;
type ParameterField = F;

Expand Down Expand Up @@ -327,6 +330,9 @@ mod r1cs {
impl<F: PrimeField, const WIDTH: usize> PoseidonRefSpec<ConstraintSystemRef<F>, WIDTH>
for R1csSpecRef<F, WIDTH>
{
// Field is private variables, ParameterField is public constants.
// In R1cs Spec, these two types lead to different privacy and #constraints.
// See add() and addi() below.
type Field = FpVar<F>;
type ParameterField = F;

Expand Down

0 comments on commit bae3f95

Please sign in to comment.