1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00

fix indentation and add docs

This commit is contained in:
sdeml 2019-03-18 14:24:50 +01:00
parent b983a57fe4
commit 75d873b26c
10 changed files with 38 additions and 26 deletions

View file

@ -4,15 +4,15 @@ import "ecc/babyjubjubParams.code" as context
// https://en.wikipedia.org/wiki/Twisted_Edwards_curve#Addition_on_twisted_Edwards_curves
def main(field[2] pt1, field[2] pt2, field[10] context) -> (field[2]):
field a = context[0]
field a = context[0]
field d = context[1]
field u1 = pt1[0]
field v1 = pt1[1]
field u2 = pt2[0]
field v2 = pt2[1]
field u1 = pt1[0]
field v1 = pt1[1]
field u2 = pt2[0]
field v2 = pt2[1]
field uOut = (u1*v2 + v1*u2) / (1 + d*u1*u2*v1*v2)
field vOut = (v1*v2 - a*u1*u2) / (1 - d*u1*u2*v1*v2)
return [uOut, vOut]
field uOut = (u1*v2 + v1*u2) / (1 + d*u1*u2*v1*v2)
field vOut = (v1*v2 - a*u1*u2) / (1 - d*u1*u2*v1*v2)
return [uOut, vOut]

View file

@ -4,7 +4,7 @@ import "ecc/babyjubjubParams.code" as context
// Twisted Edwards Curves, BBJLP-2008, section 2 pg 2
def main(field[2] pt, field[10] context) -> (field[2]):
field u = pt[0]
field v = pt[1]
field u = pt[0]
field v = pt[1]
return [0-u, v]
return [0-u, v]

View file

@ -4,13 +4,13 @@
// https://github.com/zcash/zips/blob/master/protocol/protocol.pdf
def main(field[2] pt, field[10] context) -> (field):
field a = context[0]
field d = context[1]
field a = context[0]
field d = context[1]
field uu = pt[0] * pt[0]
field vv = pt[1] * pt[1]
field uuvv = uu * vv
a * uu + vv == 1 + d * uuvv
return 1
field uu = pt[0] * pt[0]
field vv = pt[1] * pt[1]
field uuvv = uu * vv
a * uu + vv == 1 + d * uuvv
return 1

View file

@ -9,11 +9,11 @@ import "utils/pack/unpack256.code" as unpack256
// https://github.com/zcash-hackworks/sapling-crypto/blob/master/src/jubjub/edwards.rs#L166
def main(field[2] pt, field[10] context) -> (field):
field cofactor = context[7]
field[256] cofactorExponent = unpack256(cofactor)
field cofactor = context[7]
field[256] cofactorExponent = unpack256(cofactor)
field[2] ptExp = multiply(cofactorExponent, pt, context)
field[2] ptExp = multiply(cofactorExponent, pt, context)
field out = if ptExp[0] == 0 && ptExp[1] == 1 then 0 else 1 fi
field out = if ptExp[0] == 0 && ptExp[1] == 1 then 0 else 1 fi
return out
return out

View file

@ -2,6 +2,8 @@ import "ecc/edwardsAdd.code" as add
import "ecc/edwardsNegate.code" as neg
import "ecc/babyjubjubParams.code" as context
// Code to create test cases:
// https://github.com/stefandeml/zokrates-pycrypto/blob/master/tests/test_babyjubjub.py
def testDoubleViaAdd() -> (field):
context = context()
field[2] G = [context[4], context[5]]

View file

@ -1,6 +1,8 @@
import "ecc/babyjubjubParams.code" as context
import "ecc/edwardsOnCurve.code" as onCurve
// Code to create test cases:
// https://github.com/stefandeml/zokrates-pycrypto/blob/master/tests/test_babyjubjub.py
def testOnCurveTrue() -> (field):
context = context()

View file

@ -1,6 +1,8 @@
import "ecc/edwardsOrderCheck.code" as orderCheck
import "ecc/babyjubjubParams.code" as context
// Code to create test cases:
// https://github.com/stefandeml/zokrates-pycrypto/blob/master/tests/test_babyjubjub.py
def testOrderCheckTrue() -> (field):
context = context()

View file

@ -1,6 +1,8 @@
import "ecc/babyjubjubParams.code" as context
import "ecc/edwardsScalarMult.code" as mul
// Code to create test cases:
// https://github.com/stefandeml/zokrates-pycrypto/blob/master/tests/test_babyjubjub.py
def testCyclic() -> (field):
context = context()
field[2] G = [context[4], context[5]]

View file

@ -3,6 +3,8 @@ import "ecc/proofOfOwnership.code" as proofOfOwnership
import "ecc/edwardsScalarMult.code" as multiply
import "utils/pack/unpack256.code" as unpack256
// Code to create test cases:
// https://github.com/stefandeml/zokrates-pycrypto/blob/master/tests/test_babyjubjub.py
def testOwnershipTrue() -> (field):
context = context()
field[2] G = [context[4], context[5]]

View file

@ -1,6 +1,8 @@
import "signatures/verifyEddsa.code" as verifyEddsa
import "ecc/babyjubjubParams.code" as context
// Code to create test case:
// https://github.com/stefandeml/zokrates-pycrypto/blob/master/tests/test_eddsa.py
def main() -> (field):
context = context()