Explorar o código

make fake zk jubjub add

narodnik %!s(int64=5) %!d(string=hai) anos
pai
achega
77b7552d5a
Modificáronse 1 ficheiros con 35 adicións e 0 borrados
  1. 35 0
      scripts/jubjub.py

+ 35 - 0
scripts/jubjub.py

@@ -25,11 +25,46 @@ def add(params, point_1, point_2):
 
     return (x3, y3)
 
+def fake_zk_add(params, point_1, point_2):
+    # From here: https://z.cash/technology/jubjub/
+
+    a, d = params
+
+    x1, y1 = point_1
+    x2, y2 = point_2
+
+    # Compute U = (u1 + v1) * (v2 - EDWARDS_A*u2)
+    #           = (u1 + v1) * (u2 + v2)
+    U = (x1 + y1) * (x2 + y2)
+    assert (x1 + y1) * (x2 + y2) == U
+
+    # Compute A = v2 * u1
+    A = y2 * x1
+    # Compute B = u2 * v1
+    B = x2 * y1
+    # Compute C = d*A*B
+    C = d * A * B
+    assert (d * A) * (B) == C
+
+    # Compute u3 = (A + B) / (1 + C)
+    # NOTE: make sure we check for (1 + C) has an inverse
+    u3 = (A + B) / (1 + C)
+    assert (1 + C) * (u3) == (A + B)
+
+    # Compute v3 = (U - A - B) / (1 - C)
+    # We will also need to check inverse here as well.
+    v3 = (U - A - B) / (1 - C)
+    assert (1 - C) * (v3) == (U - A - B)
+
+    return u3, v3
+
 x = 0x15a36d1f0f390d8852a35a8c1908dd87a361ee3fd48fdf77b9819dc82d90607e
 y = 0x015d8c7f5b43fe33f7891142c001d9251f3abeeb98fad3e87b0dc53c4ebf1891
 
 x3, y3 = add(params, (x, y), (x, y))
 print(hex(x3.n), hex(y3.n))
+u3, v3 = fake_zk_add(params, (x, y), (x, y))
+print(hex(u3.n), hex(v3.n))
 
 print(is_jubjub(params, x, y))
 print(is_jubjub(params, x3, y3))