pubscalars.rs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. #[test]
  8. fn pubscalars_test() -> Result<(), sigma_rs::errors::Error> {
  9. sigma_compiler! { proof,
  10. (x, z, rand r, rand s, pub a, pub b),
  11. (C, D, const cind A, const cind B),
  12. C = x*A + r*B,
  13. D = z*A + s*B,
  14. z = 2*x + a,
  15. // b = 2*a - 3,
  16. }
  17. type Scalar = <G as Group>::Scalar;
  18. let mut rng = rand::thread_rng();
  19. let A = G::hash_from_bytes::<Sha512>(b"Generator A");
  20. let B = G::generator();
  21. let r = Scalar::random(&mut rng);
  22. let s = Scalar::random(&mut rng);
  23. let x = Scalar::from_u128(5);
  24. let z = Scalar::from_u128(17);
  25. let a = Scalar::from_u128(7);
  26. let b = Scalar::from_u128(11);
  27. let C = x * A + r * B;
  28. let D = z * A + s * B;
  29. let instance = proof::Instance { C, D, A, B, a, b };
  30. let witness = proof::Witness { x, z, r, s };
  31. let proof = proof::prove(&instance, &witness, b"pubscalars_test", &mut rng)?;
  32. proof::verify(&instance, &proof, b"pubscalars_test")
  33. }