Skip to content

Commit

Permalink
chore: poseidon longer input tests and delete unnecessary ones
Browse files Browse the repository at this point in the history
  • Loading branch information
lydiagarms committed Jan 8, 2025
1 parent f1449a6 commit e2e7a56
Showing 1 changed file with 39 additions and 55 deletions.
94 changes: 39 additions & 55 deletions plonkish_backend/src/circuits/poseidongadget/poseidon/pow5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ impl<
)?,
_ => panic!("Input is not padded"),
};
// TO DO: the Synthesis error in poseidon_hash_longer_input occurs here when i =1 (the input is padding)
constraint_var
.copy_advice(
|| format!("load input_{i}"),
Expand Down Expand Up @@ -861,7 +862,6 @@ mod tests {
mut layouter: impl Layouter<Fr>,
) -> Result<(), Error> {
let chip = Pow5Chip::construct(config.clone());

let message = layouter.assign_region(
|| "load message",
|mut region| {
Expand All @@ -884,6 +884,7 @@ mod tests {
chip,
layouter.namespace(|| "init"),
)?;
//TO DO: add_input called here leading to error in poseidon_hash_longer_input
let output = hasher.hash(layouter.namespace(|| "hash"), message)?;

layouter.assign_region(
Expand Down Expand Up @@ -912,6 +913,17 @@ mod tests {
}
}

impl CircuitExt<Fr> for HashCircuit<newParam<3, 2, 0>, 3, 2, 3> {
fn instances(&self) -> Vec<Vec<Fr>> {
/*let mut expected_final_state = (0..7)
.map(|idx| Fq::from(idx as u64))
.collect::<Vec<_>>()
.try_into()
.unwrap();*/
Vec::new()
}
}

#[test]
fn poseidon_hash() {
let message = [
Expand Down Expand Up @@ -945,65 +957,37 @@ mod tests {
assert_eq!(result, Ok(()))
}

/*#[ignore]
// This test is ignored because there is an error that should be fixed.
#[ignore]
#[test]
fn poseidon_hash_longer_input() {
let rng = OsRng;
let message = [Fp::random(rng), Fp::random(rng), Fp::random(rng)];
let message = [
Fr::random(OsRng),
Fr::random(OsRng),
Fr::random(OsRng),
];
let output =
poseidon::Hash::<_, OrchardNullifier, ConstantLength<3>, 3, 2>::init().hash(message);
let k = 7;
let circuit = HashCircuit::<OrchardNullifier, 3, 2, 3> {
message: Value::known(message),
output: Value::known(output),
_spec: PhantomData,
};
let prover = MockProver::run::<_, true>(k, &circuit, vec![]).unwrap();
assert_eq!(prover.verify(), Ok(()))
}
#[ignore]
#[test]
fn hash_test_vectors() {
for tv in crate::circuits::poseidongadget::poseidon::primitives::test_vectors::fp::hash() {
let message = [
pallas::Base::from_repr(tv.input[0]).unwrap(),
pallas::Base::from_repr(tv.input[1]).unwrap(),
];
let output = poseidon::Hash::<_, OrchardNullifier, ConstantLength<2>, 3, 2>::init()
.hash(message);
let k = 6;
let circuit = HashCircuit::<OrchardNullifier, 3, 2, 2> {
poseidon::Hash::<_, newParam<3, 2, 0>, ConstantLength<3>, 3, 2>::init().hash(message);
type Pb = HyperPlonk<Zeromorph<UnivariateKzg<Bn256>>>;
let circuit = Halo2Circuit::new::<Pb>(
7,
HashCircuit::<newParam<3, 2, 0>, 3, 2, 3> {
message: Value::known(message),
output: Value::known(output),
_spec: PhantomData,
};
let prover = MockProver::run::<_, true>(k, &circuit, vec![]).unwrap();
assert_eq!(prover.verify(), Ok(()));
}
}
#[cfg(feature = "test-dev-graph")]
#[test]
fn print_poseidon_chip() {
use plotters::prelude::*;
let root = BitMapBackend::new("poseidon-chip-layout.png", (1024, 768)).into_drawing_area();
root.fill(&WHITE).unwrap();
let root = root
.titled("Poseidon Chip Layout", ("sans-serif", 60))
.unwrap();
let circuit = HashCircuit::<OrchardNullifier, 3, 2, 2> {
message: Value::unknown(),
output: Value::unknown(),
_spec: PhantomData,
},
);
let param = Pb::setup(&circuit.circuit_info().unwrap(), seeded_std_rng()).unwrap();
let (pp, vp) = Pb::preprocess(&param, &circuit.circuit_info().unwrap()).unwrap();
let proof = {
let mut transcript = Keccak256Transcript::new(());
Pb::prove(&pp, &circuit, &mut transcript, seeded_std_rng()).unwrap();
transcript.into_proof()
};
halo2_proofs::dev::CircuitLayout::default()
.render(6, &circuit, &root)
.unwrap();
}*/
let result = {
let mut transcript = Keccak256Transcript::from_proof((), proof.as_slice());
Pb::verify(&vp, circuit.instances(), &mut transcript, seeded_std_rng())
};
assert_eq!(result, Ok(()))
}
}

0 comments on commit e2e7a56

Please sign in to comment.