Skip to content

Commit

Permalink
perf: skip some intermediate % in Weierstrass add
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed Nov 12, 2024
1 parent e0ad053 commit 9969766
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions src/abstract/weierstrass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,32 +475,32 @@ export function weierstrassPoints<T>(opts: CurvePointsType<T>): CurvePointsRes<T
let t1 = Fp.mul(Y1, Y1);
let t2 = Fp.mul(Z1, Z1);
let t3 = Fp.mul(X1, Y1);
t3 = Fp.add(t3, t3); // step 5
t3 = Fp.addN(t3, t3); // step 5
Z3 = Fp.mul(X1, Z1);
Z3 = Fp.add(Z3, Z3);
Z3 = Fp.addN(Z3, Z3);
X3 = Fp.mul(a, Z3);
Y3 = Fp.mul(b3, t2);
Y3 = Fp.add(X3, Y3); // step 10
X3 = Fp.sub(t1, Y3);
Y3 = Fp.add(t1, Y3);
Y3 = Fp.addN(X3, Y3); // step 10
X3 = Fp.subN(t1, Y3);
Y3 = Fp.addN(t1, Y3);
Y3 = Fp.mul(X3, Y3);
X3 = Fp.mul(t3, X3);
Z3 = Fp.mul(b3, Z3); // step 15
t2 = Fp.mul(a, t2);
t3 = Fp.sub(t0, t2);
t3 = Fp.subN(t0, t2);
t3 = Fp.mul(a, t3);
t3 = Fp.add(t3, Z3);
Z3 = Fp.add(t0, t0); // step 20
t0 = Fp.add(Z3, t0);
t0 = Fp.add(t0, t2);
t3 = Fp.addN(t3, Z3);
Z3 = Fp.addN(t0, t0); // step 20
t0 = Fp.addN(Z3, t0);
t0 = Fp.addN(t0, t2);
t0 = Fp.mul(t0, t3);
Y3 = Fp.add(Y3, t0);
t2 = Fp.mul(Y1, Z1); // step 25
t2 = Fp.add(t2, t2);
t2 = Fp.addN(t2, t2);
t0 = Fp.mul(t2, t3);
X3 = Fp.sub(X3, t0);
Z3 = Fp.mul(t2, t1);
Z3 = Fp.add(Z3, Z3); // step 30
Z3 = Fp.addN(Z3, Z3); // step 30
Z3 = Fp.add(Z3, Z3);
return new Point(X3, Y3, Z3);
}
Expand All @@ -519,35 +519,35 @@ export function weierstrassPoints<T>(opts: CurvePointsType<T>): CurvePointsRes<T
let t0 = Fp.mul(X1, X2); // step 1
let t1 = Fp.mul(Y1, Y2);
let t2 = Fp.mul(Z1, Z2);
let t3 = Fp.add(X1, Y1);
let t4 = Fp.add(X2, Y2); // step 5
let t3 = Fp.addN(X1, Y1);
let t4 = Fp.addN(X2, Y2); // step 5
t3 = Fp.mul(t3, t4);
t4 = Fp.add(t0, t1);
t3 = Fp.sub(t3, t4);
t4 = Fp.add(X1, Z1);
let t5 = Fp.add(X2, Z2); // step 10
t4 = Fp.addN(t0, t1);
t3 = Fp.subN(t3, t4);
t4 = Fp.addN(X1, Z1);
let t5 = Fp.addN(X2, Z2); // step 10
t4 = Fp.mul(t4, t5);
t5 = Fp.add(t0, t2);
t4 = Fp.sub(t4, t5);
t5 = Fp.add(Y1, Z1);
X3 = Fp.add(Y2, Z2); // step 15
t5 = Fp.addN(t0, t2);
t4 = Fp.subN(t4, t5);
t5 = Fp.addN(Y1, Z1);
X3 = Fp.addN(Y2, Z2); // step 15
t5 = Fp.mul(t5, X3);
X3 = Fp.add(t1, t2);
t5 = Fp.sub(t5, X3);
X3 = Fp.addN(t1, t2);
t5 = Fp.subN(t5, X3);
Z3 = Fp.mul(a, t4);
X3 = Fp.mul(b3, t2); // step 20
Z3 = Fp.add(X3, Z3);
X3 = Fp.sub(t1, Z3);
Z3 = Fp.add(t1, Z3);
Z3 = Fp.addN(X3, Z3);
X3 = Fp.subN(t1, Z3);
Z3 = Fp.addN(t1, Z3);
Y3 = Fp.mul(X3, Z3);
t1 = Fp.add(t0, t0); // step 25
t1 = Fp.add(t1, t0);
t1 = Fp.addN(t0, t0); // step 25
t1 = Fp.addN(t1, t0);
t2 = Fp.mul(a, t2);
t4 = Fp.mul(b3, t4);
t1 = Fp.add(t1, t2);
t2 = Fp.sub(t0, t2); // step 30
t1 = Fp.addN(t1, t2);
t2 = Fp.subN(t0, t2); // step 30
t2 = Fp.mul(a, t2);
t4 = Fp.add(t4, t2);
t4 = Fp.addN(t4, t2);
t0 = Fp.mul(t1, t4);
Y3 = Fp.add(Y3, t0);
t0 = Fp.mul(t5, t4); // step 35
Expand Down

0 comments on commit 9969766

Please sign in to comment.