diff --git a/index.js b/index.js index 82af4dd..2449960 100644 --- a/index.js +++ b/index.js @@ -31,5 +31,9 @@ exports.groth = { exports.bigInt = require("./src/bigint.js"); exports.ZqField = require("./src/zqfield.js"); +exports.stringifyBigInts = require("./src/stringifybigint.js").stringifyBigInts; +exports.unstringifyBigInts = require("./src/stringifybigint.js").unstringifyBigInts; + + const Bn128 = require("./src/bn128.js"); exports.bn128 = new Bn128(); diff --git a/src/bn128.js b/src/bn128.js index bb0fd91..4e8ba1b 100644 --- a/src/bn128.js +++ b/src/bn128.js @@ -30,7 +30,7 @@ class BN128 { this.q = bigInt("21888242871839275222246405745257275088696311157297823662689037894645226208583"); this.r = bigInt("21888242871839275222246405745257275088548364400416034343698204186575808495617"); - this.g1 = [ bigInt(1), bigInt(2) ]; + this.g1 = [ bigInt(1), bigInt(2), bigInt(1)]; this.g2 = [ [ bigInt("10857046999023057135944570762232829481370756359578518086990519993285655852781"), @@ -39,6 +39,10 @@ class BN128 { [ bigInt("8495653923123431417604973247489272438418190587263600148770280649306958101930"), bigInt("4082367875863433681332203403145435568316851327593401208105741076214120093531") + ], + [ + bigInt("1"), + bigInt("0") ] ]; @@ -219,7 +223,7 @@ class BN128 { } - if (this.loopCountNef) + if (this.loopCountNeg) { f = this.F12.inverse(f); } diff --git a/src/calculateWitness.js b/src/calculateWitness.js index 3f4b4ac..226c9b4 100644 --- a/src/calculateWitness.js +++ b/src/calculateWitness.js @@ -64,8 +64,8 @@ function calculateWitness(circuit, inputSignals, log) { } log(circuit.signalNames(i) + " --> " + ctx.witness[i].toString()); } -// return ctx.witness.slice(0, circuit.nVars); - return ctx.witness; + return ctx.witness.slice(0, circuit.nVars); +// return ctx.witness; } class RTCtx { diff --git a/src/prover_groth.js b/src/prover_groth.js index f35d2d7..13904e5 100644 --- a/src/prover_groth.js +++ b/src/prover_groth.js @@ -69,9 +69,7 @@ module.exports = function genProof(vk_proof, witness) { pib1 = G1.add( pib1, vk_proof.vk_beta_1 ); pib1 = G1.add( pib1, G1.mulScalar( vk_proof.vk_delta_1, s )); - const h = calculateH(vk_proof, witness, PolF.F.zero, PolF.F.zero, PolF.F.zero); - -// console.log(h.length + "/" + vk_proof.hExps.length); + const h = calculateH(vk_proof, witness); for (let i = 0; i < h.length; i++) { proof.pi_c = G1.add( proof.pi_c, G1.mulScalar( vk_proof.hExps[i], h[i])); @@ -92,10 +90,11 @@ module.exports = function genProof(vk_proof, witness) { proof.protocol = "groth"; return {proof, publicSignals}; + }; -function calculateH(vk_proof, witness, d1, d2, d3) { +function calculateH(vk_proof, witness) { const F = PolF.F; const m = vk_proof.domainSize; @@ -124,39 +123,7 @@ function calculateH(vk_proof, witness, d1, d2, d3) { const polABC_S = PolF.sub(polAB_S, polC_S); - const polZ_S = new Array(m+1).fill(F.zero); - polZ_S[m] = F.one; - polZ_S[0] = F.neg(F.one); - - let H_S = PolF.div(polABC_S, polZ_S); -/* - const H2S = PolF.mul(H_S, polZ_S); - - if (PolF.equals(H2S, polABC_S)) { - console.log("Is Divisible!"); - } else { - console.log("ERROR: Not divisible!"); - } -*/ - - /* add coefficients of the polynomial (d2*A + d1*B - d3) + d1*d2*Z */ - - H_S = PolF.extend(H_S, m+1); - - for (let i=0; i