mirror of
https://github.com/arnaucube/circomlib.git
synced 2026-02-06 18:56:43 +01:00
Change to a standard generator for Baby Jub
This commit is contained in:
@@ -7,19 +7,23 @@ exports.inCurve = inCurve;
|
||||
exports.inSubgroup = inSubgroup;
|
||||
exports.packPoint = packPoint;
|
||||
exports.unpackPoint = unpackPoint;
|
||||
exports.Generator = [
|
||||
bigInt("995203441582195749578291179787384436505546430278305826713579947235728471134"),
|
||||
bigInt("5472060717959818805561601436314318772137091100104008585924551046643952123905")
|
||||
];
|
||||
exports.Base8 = [
|
||||
bigInt("17777552123799933955779906779655732241715742912184938656739573121738514868268"),
|
||||
bigInt("2626589144620713026669568689430873010625803728049924121243784502389097019475")
|
||||
bigInt("5299619240641551281634865583518297030282874472190772894086521144482721001553"),
|
||||
bigInt("16950150798460657717958625567821834550301663161624707787222815936182638968203")
|
||||
];
|
||||
exports.order = bigInt("21888242871839275222246405745257275088614511777268538073601725287587578984328");
|
||||
exports.subOrder = exports.order.shr(3);
|
||||
exports.p = bn128.r;
|
||||
exports.A = bigInt("168700");
|
||||
exports.D = bigInt("168696");
|
||||
|
||||
|
||||
function addPoint(a,b) {
|
||||
const q = bn128.r;
|
||||
const cta = bigInt("168700");
|
||||
const d = bigInt("168696");
|
||||
|
||||
const res = [];
|
||||
|
||||
@@ -27,8 +31,8 @@ function addPoint(a,b) {
|
||||
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);
|
||||
res[0] = bigInt((bigInt(a[0]).mul(b[1]).add(bigInt(b[0]).mul(a[1]))).mul(bigInt(bigInt("1").add(exports.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(exports.A.mul(a[0]).mul(b[0]))).mul(bigInt(bigInt("1").sub(exports.D.mul(a[0]).mul(b[0]).mul(a[1]).mul(b[1]))).inverse(q))).affine(q);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -58,15 +62,12 @@ function inSubgroup(P) {
|
||||
function inCurve(P) {
|
||||
const F = bn128.Fr;
|
||||
|
||||
const a = bigInt("168700");
|
||||
const d = bigInt("168696");
|
||||
|
||||
const x2 = F.square(P[0]);
|
||||
const y2 = F.square(P[1]);
|
||||
|
||||
if (!F.equals(
|
||||
F.add(F.mul(a, x2), y2),
|
||||
F.add(F.one, F.mul(F.mul(x2, y2), d)))) return false;
|
||||
F.add(F.mul(exports.A, x2), y2),
|
||||
F.add(F.one, F.mul(F.mul(x2, y2), exports.D)))) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -92,14 +93,11 @@ function unpackPoint(_buff) {
|
||||
P[1] = bigInt.leBuff2int(buff);
|
||||
if (P[1].greaterOrEquals(exports.p)) return null;
|
||||
|
||||
const a = bigInt("168700");
|
||||
const d = bigInt("168696");
|
||||
|
||||
const y2 = F.square(P[1]);
|
||||
|
||||
let x = F.sqrt(F.div(
|
||||
F.sub(F.one, y2),
|
||||
F.sub(a, F.mul(d, y2))));
|
||||
F.sub(exports.A, F.mul(exports.D, y2))));
|
||||
|
||||
if (x == null) return null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user