const tester = require("../ports/c/buildasm/buildzqfieldtester.js"); const ZqField = require("fflib").ZqField; const bigInt = require("big-integer"); const bn128q = new bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208583"); const bn128r = new bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); const secp256k1q = new bigInt("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 16); const secp256k1r = new bigInt("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 16); const mnt6753q = new bigInt("41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888458477323173057491593855069696241854796396165721416325350064441470418137846398469611935719059908164220784476160001"); const mnt6753r = new bigInt("41898490967918953402344214791240637128170709919953949071783502921025352812571106773058893763790338921418070971888253786114353726529584385201591605722013126468931404347949840543007986327743462853720628051692141265303114721689601"); describe("field asm test", function () { this.timeout(1000000000); it("bn128r add", async () => { const tv = buildTestVector2(bn128r, "add"); await tester(bn128r, tv); }); it("secp256k1q add", async () => { const tv = buildTestVector2(secp256k1q, "add"); await tester(secp256k1q, tv); }); it("mnt6753q add", async () => { const tv = buildTestVector2(mnt6753q, "add"); await tester(mnt6753q, tv); }); it("bn128r sub", async () => { const tv = buildTestVector2(bn128r, "sub"); await tester(bn128r, tv); }); it("secp256k1q sub", async () => { const tv = buildTestVector2(secp256k1q, "sub"); await tester(secp256k1q, tv); }); it("mnt6753q sub", async () => { const tv = buildTestVector2(mnt6753q, "sub"); await tester(mnt6753q, tv); }); it("bn128r neg", async () => { const tv = buildTestVector1(bn128r, "neg"); await tester(bn128r, tv); }); it("secp256k1q neg", async () => { const tv = buildTestVector1(secp256k1q, "neg"); await tester(secp256k1q, tv); }); it("mnt6753q neg", async () => { const tv = buildTestVector1(mnt6753q, "neg"); await tester(mnt6753q, tv); }); it("bn128r mul", async () => { const tv = buildTestVector2(bn128r, "mul"); await tester(bn128r, tv); }); it("secp256k1q mul", async () => { const tv = buildTestVector2(secp256k1q, "mul"); await tester(secp256k1q, tv); }); it("mnt6753q mul", async () => { const tv = buildTestVector2(mnt6753q, "mul"); await tester(mnt6753q, tv); }); it("bn128r binary and", async () => { const tv = buildTestVector2(bn128r, "band"); await tester(bn128r, tv); }); it("secp256k1q binary and", async () => { const tv = buildTestVector2(secp256k1q, "band"); await tester(secp256k1q, tv); }); it("mnt6753q binary and", async () => { const tv = buildTestVector2(mnt6753q, "band"); await tester(mnt6753q, tv); }); it("bn128r binary or", async () => { const tv = buildTestVector2(bn128r, "bor"); await tester(bn128r, tv); }); it("secp256k1q binary or", async () => { const tv = buildTestVector2(secp256k1q, "bor"); await tester(secp256k1q, tv); }); it("mnt6753q binary or", async () => { const tv = buildTestVector2(mnt6753q, "bor"); await tester(mnt6753q, tv); }); it("bn128r binary xor", async () => { const tv = buildTestVector2(bn128r, "bxor"); await tester(bn128r, tv); }); it("secp256k1q binary xor", async () => { const tv = buildTestVector2(secp256k1q, "bxor"); await tester(secp256k1q, tv); }); it("mnt6753q binary xor", async () => { const tv = buildTestVector2(mnt6753q, "bxor"); await tester(mnt6753q, tv); }); it("bn128r binary not", async () => { const tv = buildTestVector1(bn128r, "bnot"); await tester(bn128r, tv); }); it("secp256k1q binary not", async () => { const tv = buildTestVector1(secp256k1q, "bnot"); await tester(secp256k1q, tv); }); it("mnt6753q binary not", async () => { const tv = buildTestVector1(mnt6753q, "bnot"); await tester(mnt6753q, tv); }); it("bn128r eq", async () => { const tv = buildTestVector2(bn128r, "eq"); await tester(bn128r, tv); }); it("secp256k1q eq", async () => { const tv = buildTestVector2(secp256k1q, "eq"); await tester(secp256k1q, tv); }); it("mnt6753q eq", async () => { const tv = buildTestVector2(mnt6753q, "eq"); await tester(mnt6753q, tv); }); it("bn128r neq", async () => { const tv = buildTestVector2(bn128r, "neq"); await tester(bn128r, tv); }); it("secp256k1q neq", async () => { const tv = buildTestVector2(secp256k1q, "neq"); await tester(secp256k1q, tv); }); it("mnt6753q neq", async () => { const tv = buildTestVector2(mnt6753q, "neq"); await tester(mnt6753q, tv); }); it("bn128r lt", async () => { const tv = buildTestVector2(bn128r, "lt"); await tester(bn128r, tv); }); it("secp256k1q lt", async () => { const tv = buildTestVector2(secp256k1q, "lt"); await tester(secp256k1q, tv); }); it("mnt6753q lt", async () => { const tv = buildTestVector2(mnt6753q, "lt"); await tester(mnt6753q, tv); }); it("bn128r gt", async () => { const tv = buildTestVector2(bn128r, "gt"); await tester(bn128r, tv); }); it("secp256k1q gt", async () => { const tv = buildTestVector2(secp256k1q, "gt"); await tester(secp256k1q, tv); }); it("mnt6753q gt", async () => { const tv = buildTestVector2(mnt6753q, "gt"); await tester(mnt6753q, tv); }); it("bn128r leq", async () => { const tv = buildTestVector2(bn128r, "leq"); await tester(bn128r, tv); }); it("secp256k1q leq", async () => { const tv = buildTestVector2(secp256k1q, "leq"); await tester(secp256k1q, tv); }); it("mnt6753q leq", async () => { const tv = buildTestVector2(mnt6753q, "leq"); await tester(mnt6753q, tv); }); it("bn128r geq", async () => { const tv = buildTestVector2(bn128r, "geq"); await tester(bn128r, tv); }); it("secp256k1q geq", async () => { const tv = buildTestVector2(secp256k1q, "geq"); await tester(secp256k1q, tv); }); it("mnt6753q geq", async () => { const tv = buildTestVector2(mnt6753q, "geq"); await tester(mnt6753q, tv); }); it("bn128r logical and", async () => { const tv = buildTestVector2(bn128r, "land"); await tester(bn128r, tv); }); it("secp256k1q logical and", async () => { const tv = buildTestVector2(secp256k1q, "land"); await tester(secp256k1q, tv); }); it("mnt6753q logical and", async () => { const tv = buildTestVector2(mnt6753q, "land"); await tester(mnt6753q, tv); }); it("bn128r logical or", async () => { const tv = buildTestVector2(bn128r, "lor"); await tester(bn128r, tv); }); it("secp256k1q logical or", async () => { const tv = buildTestVector2(secp256k1q, "lor"); await tester(secp256k1q, tv); }); it("mnt6753q logical or", async () => { const tv = buildTestVector2(mnt6753q, "lor"); await tester(mnt6753q, tv); }); it("bn128r logical not", async () => { const tv = buildTestVector1(bn128r, "lnot"); await tester(bn128r, tv); }); it("secp256k1q logical not", async () => { const tv = buildTestVector1(secp256k1q, "lnot"); await tester(secp256k1q, tv); }); it("mnt6753q logical not", async () => { const tv = buildTestVector1(mnt6753q, "lnot"); await tester(mnt6753q, tv); }); it("bn128r idiv", async () => { const tv = buildTestVector2(bn128r, "idiv"); await tester(bn128r, tv); }); it("secp256k1q idiv", async () => { const tv = buildTestVector2(secp256k1q, "idiv"); await tester(secp256k1q, tv); }); it("mnt6753q idiv", async () => { const tv = buildTestVector2(mnt6753q, "idiv"); await tester(mnt6753q, tv); }); it("bn128r inv", async () => { const tv = buildTestVector1(bn128r, "inv"); await tester(bn128r, tv); }); it("secp256k1q inv", async () => { const tv = buildTestVector1(secp256k1q, "inv"); await tester(secp256k1q, tv); }); it("mnt6753q inv", async () => { const tv = buildTestVector1(mnt6753q, "inv"); await tester(mnt6753q, tv); }); it("bn128r div", async () => { const tv = buildTestVector2(bn128r, "div"); await tester(bn128r, tv); }); it("secp256k1q div", async () => { const tv = buildTestVector2(secp256k1q, "div"); await tester(secp256k1q, tv); }); it("mnt6753q div", async () => { const tv = buildTestVector2(mnt6753q, "div"); await tester(mnt6753q, tv); }); it("bn128r square", async () => { const tv = buildTestVector1(bn128r, "square"); await tester(bn128r, tv); }); it("secp256k1q square", async () => { const tv = buildTestVector1(secp256k1q, "square"); await tester(secp256k1q, tv); }); it("mnt6753q square", async () => { const tv = buildTestVector1(mnt6753q, "square"); await tester(mnt6753q, tv); }); }); function buildTestVector2(p, op) { const F = new ZqField(p); const tv = []; const nums = getCriticalNumbers(p, 2); const excludeZero = ["div", "mod", "idiv"].indexOf(op) >= 0; for (let i=0; i= 0; for (let i=0; i