solutions/zokrates_prover/.zokrates/stdlib/ecc/edwardsAdd.zok

21 lines
622 B
Plaintext
Raw Permalink Normal View History

2023-12-05 06:06:28 +00:00
from "ecc/babyjubjubParams" import BabyJubJubParams;
// 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, BabyJubJubParams context) -> field[2] {
field a = context.JUBJUB_A;
field d = context.JUBJUB_D;
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];
}