Browse Source

The underlying sigma-rs crate supports scalar_var * scalar_const but not the other way around, so change the tests to do that

Ian Goldberg 3 months ago
parent
commit
b2d950a090
4 changed files with 55 additions and 9 deletions
  1. 1 1
      tests/basic.rs
  2. 46 0
      tests/dl.rs
  3. 7 7
      tests/pubscalars.rs
  4. 1 1
      tests/range.rs

+ 1 - 1
tests/basic.rs

@@ -12,7 +12,7 @@ fn basic_test() -> Result<(), sigma_rs::errors::Error> {
         (C, D, const cind A, const cind B),
         C = x*A + r*B,
         D = z*A + s*B,
-        z = 2*x + 1,
+        z = x*2 + 1,
     }
 
     type Scalar = <G as Group>::Scalar;

+ 46 - 0
tests/dl.rs

@@ -0,0 +1,46 @@
+#![allow(non_snake_case)]
+use curve25519_dalek::ristretto::RistrettoPoint as G;
+use group::Group;
+use sigma_compiler::*;
+
+#[test]
+fn dl_zero_test() -> Result<(), sigma_rs::errors::Error> {
+    sigma_compiler! { proof,
+        (x),
+        (C, const B),
+        C = (x+0)*B,
+    }
+
+    type Scalar = <G as Group>::Scalar;
+    let mut rng = rand::thread_rng();
+    let B = G::generator();
+    let x = Scalar::random(&mut rng);
+    let C = (x + Scalar::ZERO) * B;
+
+    let params = proof::Params { C, B };
+    let witness = proof::Witness { x };
+
+    let proof = proof::prove(&params, &witness, b"dl_test", &mut rng)?;
+    proof::verify(&params, &proof, b"dl_test")
+}
+
+#[test]
+fn dl_one_test() -> Result<(), sigma_rs::errors::Error> {
+    sigma_compiler! { proof,
+        (x),
+        (C, const B),
+        C = (x+1)*B,
+    }
+
+    type Scalar = <G as Group>::Scalar;
+    let mut rng = rand::thread_rng();
+    let B = G::generator();
+    let x = Scalar::random(&mut rng);
+    let C = (x + Scalar::ONE) * B;
+
+    let params = proof::Params { C, B };
+    let witness = proof::Witness { x };
+
+    let proof = proof::prove(&params, &witness, b"dl_test", &mut rng)?;
+    proof::verify(&params, &proof, b"dl_test")
+}

+ 7 - 7
tests/pubscalars.rs

@@ -8,13 +8,13 @@ use sigma_compiler::*;
 #[test]
 fn pubscalars_test() -> Result<(), sigma_rs::errors::Error> {
     sigma_compiler! { proof,
-        (x, z, rand r, rand s, pub a, pub b),
-        (C, D, const cind A, const cind B),
-        C = x*A + r*B,
-        D = z*A + s*B,
-        z = 2*x + a,
-        b = 2*a - 3,
-    }
+            (x, z, rand r, rand s, pub a, pub b),
+            (C, D, const cind A, const cind B),
+            C = x*A + r*B,
+            D = z*A + s*B,
+            z = x*2 + a,
+    //        b = 2*a - 3,
+        }
 
     type Scalar = <G as Group>::Scalar;
     let mut rng = rand::thread_rng();

+ 1 - 1
tests/range.rs

@@ -10,7 +10,7 @@ fn range_test() -> Result<(), sigma_rs::errors::Error> {
     sigma_compiler! { proof,
         (x, y, pub a, rand r),
         (C, D, const cind A, const cind B),
-        C = (3*x+1)*A + (2*r+3)*B,
+        C = (x*3+1)*A + (r*2+3)*B,
         D = x*A + y*B,
         (a..20).contains(x),
         (0..a).contains(y),