pubscalars_or_and.rs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #![allow(non_snake_case)]
  2. use curve25519_dalek::ristretto::RistrettoPoint as G;
  3. use group::ff::PrimeField;
  4. use group::Group;
  5. use sha2::Sha512;
  6. use sigma_compiler::*;
  7. fn pubscalars_or_and_test_val(x_val: u128, b_val: u128) -> sigma_proofs::errors::Result<()> {
  8. sigma_compiler! { proof,
  9. (x, rand r, pub a, pub b),
  10. (C, const cind A, const cind B),
  11. C = x*A + r*B,
  12. OR (
  13. AND (
  14. b = 2*a,
  15. x = 1,
  16. ),
  17. AND (
  18. b = 2*a - 3,
  19. x = 2,
  20. )
  21. )
  22. }
  23. type Scalar = <G as Group>::Scalar;
  24. let mut rng = rand::thread_rng();
  25. let A = G::hash_from_bytes::<Sha512>(b"Generator A");
  26. let B = G::generator();
  27. let r = Scalar::random(&mut rng);
  28. let x = Scalar::from_u128(x_val);
  29. let a = Scalar::from_u128(7);
  30. let b = Scalar::from_u128(b_val);
  31. let C = x * A + r * B;
  32. let instance = proof::Instance { C, A, B, a, b };
  33. let witness = proof::Witness { x, r };
  34. let proof = proof::prove(&instance, &witness, b"pubscalars_or_and_test", &mut rng)?;
  35. proof::verify(&instance, &proof, b"pubscalars_or_and_test")
  36. }
  37. #[test]
  38. fn pubscalars_or_test() {
  39. pubscalars_or_and_test_val(1u128, 10u128).unwrap_err();
  40. pubscalars_or_and_test_val(1u128, 11u128).unwrap_err();
  41. pubscalars_or_and_test_val(1u128, 12u128).unwrap_err();
  42. pubscalars_or_and_test_val(1u128, 13u128).unwrap_err();
  43. pubscalars_or_and_test_val(1u128, 14u128).unwrap();
  44. pubscalars_or_and_test_val(1u128, 15u128).unwrap_err();
  45. pubscalars_or_and_test_val(2u128, 10u128).unwrap_err();
  46. pubscalars_or_and_test_val(2u128, 11u128).unwrap();
  47. pubscalars_or_and_test_val(2u128, 12u128).unwrap_err();
  48. pubscalars_or_and_test_val(2u128, 13u128).unwrap_err();
  49. pubscalars_or_and_test_val(2u128, 14u128).unwrap_err();
  50. pubscalars_or_and_test_val(2u128, 15u128).unwrap_err();
  51. }