Skip to content

Commit

Permalink
expose poseidon_test_config outside tests
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaucube committed Feb 1, 2024
1 parent c53ca83 commit 0b2675a
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 67 deletions.
29 changes: 2 additions & 27 deletions examples/fold_sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use ark_crypto_primitives::crh::{
},
CRHScheme, CRHSchemeGadget,
};
use ark_crypto_primitives::sponge::poseidon::{find_poseidon_ark_and_mds, PoseidonConfig};
use ark_ff::{BigInteger, PrimeField, ToConstraintField};
use ark_r1cs_std::{fields::fp::FpVar, ToBytesGadget, ToConstraintFieldGadget};
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
Expand All @@ -23,6 +22,7 @@ use ark_vesta::{constraints::GVar as GVar2, Projective as Projective2};
use folding_schemes::commitment::pedersen::Pedersen;
use folding_schemes::folding::nova::{get_r1cs, Nova, ProverParams, VerifierParams};
use folding_schemes::frontend::FCircuit;
use folding_schemes::transcript::poseidon::poseidon_test_config;
use folding_schemes::{Error, FoldingScheme};

/// This is the circuit that we want to fold, it implements the FCircuit trait
Expand Down Expand Up @@ -53,31 +53,6 @@ impl<F: PrimeField> FCircuit<F> for Sha256FCircuit<F> {
}
}

pub fn poseidon_test_config<F: PrimeField>() -> PoseidonConfig<F> {
let full_rounds = 8;
let partial_rounds = 31;
let alpha = 5;
let rate = 2;

let (ark, mds) = find_poseidon_ark_and_mds::<F>(
F::MODULUS_BIT_SIZE as u64,
rate,
full_rounds,
partial_rounds,
0,
);

PoseidonConfig::new(
full_rounds as usize,
partial_rounds as usize,
alpha,
mds,
ark,
rate,
1,
)
}

/// cargo test --example simple
#[cfg(test)]
pub mod tests {
Expand All @@ -103,7 +78,7 @@ pub mod tests {
}
}

// this method computes the Prover & Verifier parameters for the example. For a real world use case
// This method computes the Prover & Verifier parameters for the example. For a real world use case
// those parameters should be generated carefuly (both the PoseidonConfig and the PedersenParams)
#[allow(clippy::type_complexity)]
fn nova_setup<FC: FCircuit<Fr>>(
Expand Down
2 changes: 1 addition & 1 deletion src/commitment/kzg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ mod tests {
use ark_std::{test_rng, UniformRand};

use super::*;
use crate::transcript::poseidon::{tests::poseidon_test_config, PoseidonTranscript};
use crate::transcript::poseidon::{poseidon_test_config, PoseidonTranscript};

#[test]
fn test_kzg_commitment_scheme() {
Expand Down
2 changes: 1 addition & 1 deletion src/commitment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mod tests {
use super::kzg::{KZGProver, KZGSetup, ProverKey};
use super::pedersen::Pedersen;
use crate::transcript::{
poseidon::{tests::poseidon_test_config, PoseidonTranscript},
poseidon::{poseidon_test_config, PoseidonTranscript},
Transcript,
};

Expand Down
2 changes: 1 addition & 1 deletion src/commitment/pedersen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ mod tests {
use ark_std::UniformRand;

use super::*;
use crate::transcript::poseidon::{tests::poseidon_test_config, PoseidonTranscript};
use crate::transcript::poseidon::{poseidon_test_config, PoseidonTranscript};

#[test]
fn test_pedersen_vector() {
Expand Down
2 changes: 1 addition & 1 deletion src/folding/circuits/sum_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ mod tests {
use crate::{
folding::circuits::sum_check::{IOPProofVar, VPAuxInfoVar},
transcript::{
poseidon::{tests::poseidon_test_config, PoseidonTranscript, PoseidonTranscriptVar},
poseidon::{poseidon_test_config, PoseidonTranscript, PoseidonTranscriptVar},
Transcript, TranscriptVar,
},
utils::{
Expand Down
2 changes: 1 addition & 1 deletion src/folding/hypernova/nimfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ where
pub mod tests {
use super::*;
use crate::ccs::tests::{get_test_ccs, get_test_z};
use crate::transcript::poseidon::tests::poseidon_test_config;
use crate::transcript::poseidon::poseidon_test_config;
use crate::transcript::poseidon::PoseidonTranscript;
use ark_std::test_rng;
use ark_std::UniformRand;
Expand Down
2 changes: 1 addition & 1 deletion src/folding/nova/circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ pub mod tests {
get_committed_instance_coordinates, nifs::NIFS, traits::NovaR1CS, Witness,
};
use crate::frontend::tests::CubicFCircuit;
use crate::transcript::poseidon::tests::poseidon_test_config;
use crate::transcript::poseidon::poseidon_test_config;

#[test]
fn test_committed_instance_var() {
Expand Down
2 changes: 1 addition & 1 deletion src/folding/nova/cyclefold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ pub mod tests {
use ark_std::UniformRand;

use crate::folding::nova::nifs::tests::prepare_simple_fold_inputs;
use crate::transcript::poseidon::tests::poseidon_test_config;
use crate::transcript::poseidon::poseidon_test_config;

#[test]
fn test_committed_instance_cyclefold_var() {
Expand Down
2 changes: 1 addition & 1 deletion src/folding/nova/decider_eth_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ pub mod tests {
use crate::commitment::pedersen::Pedersen;
use crate::folding::nova::{get_pedersen_params_len, ProverParams, VerifierParams};
use crate::frontend::tests::{CubicFCircuit, CustomFCircuit, WrapperCircuit};
use crate::transcript::poseidon::tests::poseidon_test_config;
use crate::transcript::poseidon::poseidon_test_config;
use crate::FoldingScheme;

use crate::ccs::r1cs::{extract_r1cs, extract_w_x};
Expand Down
2 changes: 1 addition & 1 deletion src/folding/nova/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ pub mod tests {

use crate::commitment::pedersen::Pedersen;
use crate::frontend::tests::CubicFCircuit;
use crate::transcript::poseidon::tests::poseidon_test_config;
use crate::transcript::poseidon::poseidon_test_config;

#[test]
fn test_ivc() {
Expand Down
2 changes: 1 addition & 1 deletion src/folding/nova/nifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pub mod tests {
use crate::commitment::pedersen::{Params as PedersenParams, Pedersen};
use crate::folding::nova::circuits::ChallengeGadget;
use crate::folding::nova::traits::NovaR1CS;
use crate::transcript::poseidon::{tests::poseidon_test_config, PoseidonTranscript};
use crate::transcript::poseidon::{poseidon_test_config, PoseidonTranscript};
use crate::utils::vec::vec_scalar_mul;

#[allow(clippy::type_complexity)]
Expand Down
2 changes: 1 addition & 1 deletion src/folding/protogalaxy/folding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ mod tests {

use crate::ccs::r1cs::tests::{get_test_r1cs, get_test_z};
use crate::commitment::{pedersen::Pedersen, CommitmentProver};
use crate::transcript::poseidon::{tests::poseidon_test_config, PoseidonTranscript};
use crate::transcript::poseidon::{poseidon_test_config, PoseidonTranscript};

pub(crate) fn check_instance<C: CurveGroup>(
r1cs: &R1CS<C::ScalarField>,
Expand Down
54 changes: 26 additions & 28 deletions src/transcript/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,43 +115,41 @@ impl<F: PrimeField> TranscriptVar<F> for PoseidonTranscriptVar<F> {
}
}

/// WARNING the method poseidon_test_config is for tests only
pub fn poseidon_test_config<F: PrimeField>() -> PoseidonConfig<F> {
let full_rounds = 8;
let partial_rounds = 31;
let alpha = 5;
let rate = 2;

let (ark, mds) = ark_crypto_primitives::sponge::poseidon::find_poseidon_ark_and_mds::<F>(
F::MODULUS_BIT_SIZE as u64,
rate,
full_rounds,
partial_rounds,
0,
);

PoseidonConfig::new(
full_rounds as usize,
partial_rounds as usize,
alpha,
mds,
ark,
rate,
1,
)
}

#[cfg(test)]
pub mod tests {
use super::*;
use ark_crypto_primitives::sponge::poseidon::find_poseidon_ark_and_mds;
use ark_pallas::{constraints::GVar, Fq, Fr, Projective};
use ark_r1cs_std::{alloc::AllocVar, fields::fp::FpVar, groups::CurveVar, R1CSVar};
use ark_relations::r1cs::ConstraintSystem;
use ark_vesta::Projective as E2Projective;
use std::ops::Mul;

/// WARNING the method poseidon_test_config is for tests only
#[cfg(test)]
pub fn poseidon_test_config<F: PrimeField>() -> PoseidonConfig<F> {
let full_rounds = 8;
let partial_rounds = 31;
let alpha = 5;
let rate = 2;

let (ark, mds) = find_poseidon_ark_and_mds::<F>(
F::MODULUS_BIT_SIZE as u64,
rate,
full_rounds,
partial_rounds,
0,
);

PoseidonConfig::new(
full_rounds as usize,
partial_rounds as usize,
alpha,
mds,
ark,
rate,
1,
)
}

#[test]
fn test_transcript_and_transcriptvar_get_challenge() {
// use 'native' transcript
Expand Down
2 changes: 1 addition & 1 deletion src/utils/espresso/sum_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub mod tests {
use ark_poly::MultilinearExtension;
use ark_std::test_rng;

use crate::transcript::poseidon::tests::poseidon_test_config;
use crate::transcript::poseidon::poseidon_test_config;
use crate::transcript::poseidon::PoseidonTranscript;
use crate::transcript::Transcript;
use crate::utils::sum_check::SumCheck;
Expand Down

0 comments on commit 0b2675a

Please sign in to comment.