Skip to content

Instantly share code, notes, and snippets.

@stefandeml
Created August 17, 2019 16:33
Show Gist options
  • Select an option

  • Save stefandeml/3ffa617a26f93d0ffc8f3459e8fb4b2a to your computer and use it in GitHub Desktop.

Select an option

Save stefandeml/3ffa617a26f93d0ffc8f3459e8fb4b2a to your computer and use it in GitHub Desktop.

Revisions

  1. stefandeml created this gist Aug 17, 2019.
    18 changes: 18 additions & 0 deletions ZoKrates Twisted Edwards Curve Addition
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    import "ecc/babyjubjubParams.code" as context
    // Add two points on a twisted Edwards curve
    // Curve parameters are defined with the last argument
    // 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 d = context[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]