3
1

range_dump.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #![cfg(feature = "dump")]
  2. #![allow(non_snake_case)]
  3. use curve25519_dalek::ristretto::RistrettoPoint as G;
  4. use group::ff::PrimeField;
  5. use group::Group;
  6. use sha2::Sha512;
  7. use sigma_compiler::*;
  8. #[test]
  9. fn range_dump_test() -> sigma_proofs::errors::Result<()> {
  10. sigma_compiler! { proof,
  11. (x, y, pub a, rand r),
  12. (C, D, const cind A, const cind B),
  13. C = (3*x+1)*A + (2*r+3)*B,
  14. D = x*A + y*B,
  15. (a..20).contains(x),
  16. (0..a).contains(y),
  17. }
  18. type Scalar = <G as Group>::Scalar;
  19. let mut rng = rand::thread_rng();
  20. let A = G::hash_from_bytes::<Sha512>(b"Generator A");
  21. let B = G::generator();
  22. let a = Scalar::from_u128(3);
  23. let r = Scalar::random(&mut rng);
  24. let x = Scalar::from_u128(19);
  25. let y = Scalar::from_u128(2);
  26. let C = (x + x + x + Scalar::ONE) * A + (r + r + Scalar::from_u128(3)) * B;
  27. let D = x * A + y * B;
  28. let instance = proof::Instance { C, D, a, A, B };
  29. let witness = proof::Witness { x, y, r };
  30. sigma_compiler::dumper::dump_to_string();
  31. let proof = proof::prove(&instance, &witness, b"range_test", &mut rng)?;
  32. let res = proof::verify(&instance, &proof, b"range_test");
  33. let buf = sigma_compiler::dumper::dump_buffer();
  34. print!("{buf}");
  35. res
  36. }