cambrian / accumulator

Cryptographic accumulators in Rust.
https://cambrian.github.io/accumulator
MIT License
133 stars 34 forks source link

Unable to generate membership proof for output of compute_individual_witnesses. #47

Closed sshravan closed 5 years ago

sshravan commented 5 years ago

I run to BadWitness error when I try to generate membership proof for an element from the output of compute_individual_witnesses.

In this example, I am trying to verify the membership of "cat" in the set after performing batch add. However, I run into errors at prove_membership.

  let acc = Accumulator::<G, &'static str>::empty();
  let (acc, proof) = acc.add_with_proof(&["dog", "cat", "cow"]);
  let witness = Witness(acc.clone());
  let indv_witness = witness.compute_individual_witnesses(&["dog", "cat", "cow"]);

  let proof_cat = acc.prove_membership(&[indv_witness[1].clone()]).unwrap(); // Bad witness
  println!("Cat: {:?}", acc.verify_membership(&"cat", &proof_cat));
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BadWitness', src/libcore/result.rs:999:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
sshravan commented 5 years ago

Turns out that my usage of Witness is wrong. If I switch

let witness = Witness(acc.clone());

to

let witness = proof.witness.clone(); // Or
let witness = Witness(Accumulator::<G, &'static str>::empty());

It works fine.