From 0503ec9de989cef549ab72e7c49e57cd74175d41 Mon Sep 17 00:00:00 2001 From: Kobi Gurkan Date: Mon, 22 Apr 2019 17:19:39 +0300 Subject: [PATCH] fixes babyjubjub addition to use generic bigint interfaces --- src/babyjub.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/babyjub.js b/src/babyjub.js index bb6753a..50aed18 100644 --- a/src/babyjub.js +++ b/src/babyjub.js @@ -22,8 +22,14 @@ function addPoint(a,b) { const d = bigInt("168696"); const res = []; - res[0] = bigInt((a[0]*b[1] + b[0]*a[1]) * bigInt(bigInt("1") + d*a[0]*b[0]*a[1]*b[1]).inverse(q)).affine(q); + + /* does the equivalent of: + res[0] = bigInt((a[0]*b[1] + b[0]*a[1]) * bigInt(bigInt("1") + d*a[0]*b[0]*a[1]*b[1]).inverse(q)).affine(q); res[1] = bigInt((a[1]*b[1] - cta*a[0]*b[0]) * bigInt(bigInt("1") - d*a[0]*b[0]*a[1]*b[1]).inverse(q)).affine(q); + */ + res[0] = bigInt((bigInt(a[0]).mul(b[1]).add(bigInt(b[0]).mul(a[1]))).mul(bigInt(bigInt("1").add(d.mul(a[0]).mul(b[0]).mul(a[1]).mul(b[1]))).inverse(q))).affine(q); + res[1] = bigInt((bigInt(a[1]).mul(b[1]).sub(cta.mul(a[0]).mul(b[0]))).mul(bigInt(bigInt("1").sub(d.mul(a[0]).mul(b[0]).mul(a[1]).mul(b[1]))).inverse(q))).affine(q); + return res; }