pubstatements.rs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #![allow(non_snake_case)]
  2. use curve25519_dalek::ristretto::RistrettoPoint as G;
  3. use group::ff::PrimeField;
  4. use group::Group;
  5. use sigma_compiler::*;
  6. fn pubstatements_with_a(a_val: u128) -> Result<(), Box<dyn std::error::Error>> {
  7. sigma_compiler! { proof,
  8. (x, pub a),
  9. (C, D, const cind B),
  10. C = a*x*B,
  11. D = a*B,
  12. }
  13. type Scalar = <G as Group>::Scalar;
  14. let mut rng = rand::thread_rng();
  15. let B = G::generator();
  16. let x = Scalar::from_u128(5);
  17. let a = Scalar::from_u128(a_val);
  18. let C = a * x * B;
  19. let D = a * B;
  20. let instance = proof::Instance { C, D, B, a };
  21. let witness = proof::Witness { x };
  22. let proof = proof::prove(&instance, &witness, b"pubstatements_test", &mut rng)?;
  23. Ok(proof::verify(&instance, &proof, b"pubstatements_test")?)
  24. }
  25. #[test]
  26. fn pubstatements_test() -> Result<(), Box<dyn std::error::Error>> {
  27. // a = 0 sends both images to the identity, and sigma-proofs refuses an
  28. // instance that carries an identity group element.
  29. assert!(pubstatements_with_a(0).is_err());
  30. pubstatements_with_a(7)
  31. }