You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The implementation of Poseidon has an issue with inputs of size 1.
How to reproduce the bug
Adding the following test to the pow5 test suite will reproduce the error
#[test]fnposeidon_hash_shorter_input(){let rng = OsRng;let message = [Fp::random(rng)];let output =
poseidon::Hash::<_,OrchardNullifier,ConstantLength<1>,3,2>::init().hash(message);let k = 7;let circuit = HashCircuit::<OrchardNullifier,3,2,1>{message:Value::known(message),output:Value::known(output),_spec:PhantomData,};// Mock prover runs correctlylet prover = MockProver::run(k,&circuit,vec![]).unwrap();assert_eq!(prover.verify(),Ok(()));let params:ParamsIPA<vesta::Affine> = ParamsIPA::new(k);let vk = keygen_vk(¶ms,&circuit).expect("keygen_vk should not fail");let pk = keygen_pk(¶ms, vk,&circuit).expect("keygen_pk should not fail");letmut rng = OsRng;letmut transcript = Blake2bWrite::<_,EqAffine,Challenge255<_>>::init(vec![]);create_proof::<IPACommitmentScheme<_>,ProverIPA<_>,_,_,_,_>(¶ms,&pk,&[circuit],&[&[]],&mut rng,&mut transcript,).expect("proof generation should not fail")// <- Proof generation fails with SynthesisError}
Fix
Surprisingly enough, the error disappears if we modify the code for load_input_word (line 340) with the following:
// Load the input into this region.let load_input_word = |i:usize| {let(cell, value) = match input.0[i].clone(){Some(PaddedWord::Message(word)) => (word.cell(), word.value().copied()),Some(PaddedWord::Padding(padding_value)) => {let cell = region
.assign_fixed(
|| format!("load pad_{}", i),
config.rc_b[i],1,
|| Value::known(padding_value),)?
.cell();(cell,Value::known(padding_value))}
_ => panic!("Input is not padded"),};let var = region.assign_advice(
|| format!("load input_{}", i),
config.state[i],1,
|| value,)?;
region.constrain_equal(cell, var.cell())?;Ok(StateWord(var))};
Note that there does not seem to be any apparent difference with the previous code. Previously, we use copy_advice instead of assign_advice and then constrain_equal. However, that is exactly what copy_advice does. I'm quite puzzled, and that is why I haven't opened a PR with the fix, because this might be hiding a bigger issue.
The text was updated successfully, but these errors were encountered:
The implementation of Poseidon has an issue with inputs of size 1.
How to reproduce the bug
Adding the following test to the
pow5
test suite will reproduce the errorFix
Surprisingly enough, the error disappears if we modify the code for
load_input_word
(line 340) with the following:Note that there does not seem to be any apparent difference with the previous code. Previously, we use
copy_advice
instead ofassign_advice
and thenconstrain_equal
. However, that is exactly whatcopy_advice
does. I'm quite puzzled, and that is why I haven't opened a PR with the fix, because this might be hiding a bigger issue.The text was updated successfully, but these errors were encountered: