Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coconut Proof allows empty blinding messages #21

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benches/benches/ps_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn pok_sig_benchmark(c: &mut Criterion) {
let sig = &sigs_range[i];

let mut prove_group = c.benchmark_group(format!("Creating proof for Proof-of-knowledge of signature and corresponding multi-message of size {}", count));
for (_j, r_count) in k.iter().enumerate() {
for (j, r_count) in k.iter().enumerate() {
prove_group.bench_with_input(
BenchmarkId::from_parameter(format!("Revealing {} messages", r_count)),
&r_count,
Expand All @@ -89,7 +89,7 @@ fn pok_sig_benchmark(c: &mut Criterion) {
.iter()
.enumerate()
.merge_join_by(
revealed_indices[i].iter(),
revealed_indices[j].iter(),
|(m_idx, _), reveal_idx| m_idx.cmp(reveal_idx),
)
.map(|either| match either {
Expand Down
23 changes: 16 additions & 7 deletions coconut/src/proof/messages_pok/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,14 +558,23 @@ mod tests {
#[test]
fn empty_proof() {
let mut rng = StdRng::seed_from_u64(0u64);
let (_sk, _pk, params, _messages) = test_setup::<Bls12_381, Blake2b512, _>(&mut rng, 1);
let (_, _, params, messages) = test_setup::<Bls12_381, Blake2b512, _>(&mut rng, 1);
let h = G1::rand(&mut rng).into_affine();

assert_eq!(
MessagesPoKGenerator::init(&mut rng, &[], &params, &h),
Err(MessagesPoKError::MessageInputError(
MessageUnpackingError::NoMessagesProvided
))
);
let pok = MessagesPoKGenerator::init(&mut rng, &[], &params, &h)
.unwrap();

let mut chal_bytes_prover = vec![];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you are using the same variables for prover's and verifier's challenge, they should not have suffix _prover, chal_bytes is good.

pok.challenge_contribution(&mut chal_bytes_prover, &params, &h)
.unwrap();
let challenge_prover =
compute_random_oracle_challenge::<Fr, Blake2b512>(&chal_bytes_prover);

let proof = pok.clone().gen_proof(&challenge_prover).unwrap();
let indices = (0..messages.len()).rev();

assert!(proof
.verify(&challenge_prover, indices.clone(), &params, &h)
.is_ok());
}
}
2 changes: 1 addition & 1 deletion coconut/src/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl<'pair, Pair, F: PrimeField> UnpackedBlindedMessages<'pair, Pair, F> {
let (paired, (msgs, blindings)): (Vec<_>, _) =
process_results(paired, |iter| iter.unzip())?;
if paired.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this if block as the last else block will return the desired result.

Err(MessageUnpackingError::NoMessagesProvided)
Ok(Self(paired, msgs, blindings))
} else if pair_with.len() != total_count {
Err(MessageUnpackingError::LessMessagesThanExpected {
provided: total_count,
Expand Down
20 changes: 14 additions & 6 deletions coconut/src/proof/signature_pok/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,20 @@ mod tests {

let sig = Signature::new(&mut rng, messages.as_slice(), &sk, &params).unwrap();

assert_eq!(
SignaturePoKGenerator::init(&mut rng, &[], &sig, &pk, &params),
Err(SignaturePoKError::MessageInputError(
MessageUnpackingError::NoMessagesProvided
))
);
let pok = SignaturePoKGenerator::init(&mut rng, &[], &sig, &pk, &params).unwrap();

let mut chal_bytes_prover = vec![];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment as above on naming.

pok.challenge_contribution(&mut chal_bytes_prover, &pk, &params)
.unwrap();
let challenge_prover =
compute_random_oracle_challenge::<Fr, Blake2b512>(&chal_bytes_prover);

let proof = pok.clone().gen_proof(&challenge_prover).unwrap();
let revealed = messages.iter().enumerate().into_iter().rev();

assert!(proof
.verify(&challenge_prover, revealed.clone(), &pk, &params)
.is_ok());
}

#[test]
Expand Down
Loading