Browse Source

A few more tests

Ian Goldberg 3 months ago
parent
commit
70172afea4
3 changed files with 113 additions and 0 deletions
  1. 19 0
      tests/emptystatement.rs
  2. 57 0
      tests/pubscalars_or_and.rs
  3. 37 0
      tests/substitution_or.rs

+ 19 - 0
tests/emptystatement.rs

@@ -0,0 +1,19 @@
+#![allow(non_snake_case)]
+use curve25519_dalek::ristretto::RistrettoPoint as G;
+use sigma_compiler::*;
+
+#[test]
+fn emptystatement_test() -> Result<(), sigma_rs::errors::Error> {
+    sigma_compiler! { proof,
+        (),
+        (),
+    }
+
+    let mut rng = rand::thread_rng();
+
+    let instance = proof::Instance {};
+    let witness = proof::Witness {};
+
+    let proof = proof::prove(&instance, &witness, b"emptystatement_test", &mut rng)?;
+    proof::verify(&instance, &proof, b"emptystatement_test")
+}

+ 57 - 0
tests/pubscalars_or_and.rs

@@ -0,0 +1,57 @@
+#![allow(non_snake_case)]
+use curve25519_dalek::ristretto::RistrettoPoint as G;
+use group::ff::PrimeField;
+use group::Group;
+use sha2::Sha512;
+use sigma_compiler::*;
+
+fn pubscalars_or_and_test_val(x_val: u128, b_val: u128) -> Result<(), sigma_rs::errors::Error> {
+    sigma_compiler! { proof,
+        (x, rand r, pub a, pub b),
+        (C, const cind A, const cind B),
+        C = x*A + r*B,
+        OR (
+            AND (
+                b = 2*a,
+                x = 1,
+            ),
+            AND (
+                b = 2*a - 3,
+                x = 2,
+            )
+        )
+    }
+
+    type Scalar = <G as Group>::Scalar;
+    let mut rng = rand::thread_rng();
+    let A = G::hash_from_bytes::<Sha512>(b"Generator A");
+    let B = G::generator();
+    let r = Scalar::random(&mut rng);
+    let x = Scalar::from_u128(x_val);
+    let a = Scalar::from_u128(7);
+    let b = Scalar::from_u128(b_val);
+    let C = x * A + r * B;
+
+    let instance = proof::Instance { C, A, B, a, b };
+    let witness = proof::Witness { x, r };
+
+    let proof = proof::prove(&instance, &witness, b"pubscalars_or_and_test", &mut rng)?;
+    proof::verify(&instance, &proof, b"pubscalars_or_and_test")
+}
+
+#[test]
+fn pubscalars_or_test() {
+    pubscalars_or_and_test_val(1u128, 10u128).unwrap_err();
+    pubscalars_or_and_test_val(1u128, 11u128).unwrap_err();
+    pubscalars_or_and_test_val(1u128, 12u128).unwrap_err();
+    pubscalars_or_and_test_val(1u128, 13u128).unwrap_err();
+    pubscalars_or_and_test_val(1u128, 14u128).unwrap();
+    pubscalars_or_and_test_val(1u128, 15u128).unwrap_err();
+
+    pubscalars_or_and_test_val(2u128, 10u128).unwrap_err();
+    pubscalars_or_and_test_val(2u128, 11u128).unwrap();
+    pubscalars_or_and_test_val(2u128, 12u128).unwrap_err();
+    pubscalars_or_and_test_val(2u128, 13u128).unwrap_err();
+    pubscalars_or_and_test_val(2u128, 14u128).unwrap_err();
+    pubscalars_or_and_test_val(2u128, 15u128).unwrap_err();
+}

+ 37 - 0
tests/substitution_or.rs

@@ -0,0 +1,37 @@
+#![allow(non_snake_case)]
+use curve25519_dalek::ristretto::RistrettoPoint as G;
+use group::ff::PrimeField;
+use group::Group;
+use sha2::Sha512;
+use sigma_compiler::*;
+
+#[test]
+fn substitution_or_test() -> Result<(), sigma_rs::errors::Error> {
+    sigma_compiler! { proof,
+        (x, z, rand r, rand s),
+        (C, D, const cind A, const cind B),
+        C = x*A + r*B,
+        D = z*A + s*B,
+        OR(
+            z = 2*x,
+            z = 2*x + 1,
+        )
+    }
+
+    type Scalar = <G as Group>::Scalar;
+    let mut rng = rand::thread_rng();
+    let A = G::hash_from_bytes::<Sha512>(b"Generator A");
+    let B = G::generator();
+    let r = Scalar::random(&mut rng);
+    let s = Scalar::random(&mut rng);
+    let x = Scalar::from_u128(5);
+    let z = Scalar::from_u128(11);
+    let C = x * A + r * B;
+    let D = z * A + s * B;
+
+    let instance = proof::Instance { C, D, A, B };
+    let witness = proof::Witness { x, z, r, s };
+
+    let proof = proof::prove(&instance, &witness, b"substitution_or_test", &mut rng)?;
+    proof::verify(&instance, &proof, b"substitution_or_test")
+}