Skip to content

Commit

Permalink
fix: lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lydiagarms committed Jan 8, 2025
1 parent 95ecf4e commit b187f21
Showing 1 changed file with 57 additions and 72 deletions.
129 changes: 57 additions & 72 deletions plonkish_backend/src/circuits/poseidongadget/poseidon/pow5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,45 +730,39 @@ mod tests {
}
}

impl_circuit_ext!(
2, 1,
3, 2,
4, 3,
5, 4,
6, 5,
7, 6
);
impl_circuit_ext!(2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6);

#[test]
fn poseidon_permute() {
type Pb = HyperPlonk<Zeromorph<UnivariateKzg<Bn256>>>;
macro_rules! test_poseidon_permute {
($i:expr, $j:expr) => {
{
let circuit = Halo2Circuit::new::<Pb>(6, PermuteCircuit::<newParam<$j, $i, 0>, $j, $i>(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()
};
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(()))
}
};
($i:expr, $j:expr) => {{
let circuit = Halo2Circuit::new::<Pb>(
6,
PermuteCircuit::<newParam<$j, $i, 0>, $j, $i>(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()
};
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(()))
}};
}
for i in 2..7 {
match i {
1 => test_poseidon_permute!(1,2),
2 => test_poseidon_permute!(2,3),
3 => test_poseidon_permute!(3,4),
4 => test_poseidon_permute!(4,5),
5 => test_poseidon_permute!(5,6),
6 => test_poseidon_permute!(6,7),
1 => test_poseidon_permute!(1, 2),
2 => test_poseidon_permute!(2, 3),
3 => test_poseidon_permute!(3, 4),
4 => test_poseidon_permute!(4, 5),
5 => test_poseidon_permute!(5, 6),
6 => test_poseidon_permute!(6, 7),
_ => unreachable!(),
}
}
Expand Down Expand Up @@ -942,14 +936,7 @@ mod tests {
}
}

impl_circuit_ext!(
2, 1,
3, 2,
4, 3,
5, 4,
6, 5,
7, 6
);
impl_circuit_ext!(2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6);

impl CircuitExt<Fr> for HashCircuit<newParam<3, 2, 0>, 3, 2, 3> {
fn instances(&self) -> Vec<Vec<Fr>> {
Expand All @@ -966,42 +953,40 @@ mod tests {
fn poseidon_hash() {
type Pb = HyperPlonk<Zeromorph<UnivariateKzg<Bn256>>>;
macro_rules! test_poseidon_hash {
($i:expr, $j:expr) => {
{
let message: [Fr; $i] = [Fr::random(OsRng); $i];
let output =
poseidon::Hash::<_, newParam<$j, $i, 0>, ConstantLength<$i>, $j, $i>::init().hash(message);
let circuit = Halo2Circuit::new::<Pb>(
6,
HashCircuit::<newParam<$j, $i, 0>, $j, $i, $i> {
message: Value::known(message),
output: Value::known(output),
_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()
};
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(()))
}
};
($i:expr, $j:expr) => {{
let message: [Fr; $i] = [Fr::random(OsRng); $i];
let output =
poseidon::Hash::<_, newParam<$j, $i, 0>, ConstantLength<$i>, $j, $i>::init().hash(message);
let circuit = Halo2Circuit::new::<Pb>(
6,
HashCircuit::<newParam<$j, $i, 0>, $j, $i, $i> {
message: Value::known(message),
output: Value::known(output),
_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()
};
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(()))
}};
}
for i in 2..7 {
match i {
1 => test_poseidon_hash!(1,2),
2 => test_poseidon_hash!(2,3),
3 => test_poseidon_hash!(3,4),
4 => test_poseidon_hash!(4,5),
5 => test_poseidon_hash!(5,6),
6 => test_poseidon_hash!(6,7),
1 => test_poseidon_hash!(1, 2),
2 => test_poseidon_hash!(2, 3),
3 => test_poseidon_hash!(3, 4),
4 => test_poseidon_hash!(4, 5),
5 => test_poseidon_hash!(5, 6),
6 => test_poseidon_hash!(6, 7),
_ => unreachable!(),
}
}
Expand Down

0 comments on commit b187f21

Please sign in to comment.