Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion build/websnark_bn128.js
Original file line number Diff line number Diff line change
Expand Up @@ -5534,7 +5534,7 @@ class Bn128 {
}, [signals, polsA, polsB]);
}

async groth16GenProof(signals, pkey) {
async groth16GenProof(signals, pkey, allowDetlaZero) {
const pkey32 = new Uint32Array(pkey);
const nSignals = pkey32[0];
const nPublic = pkey32[1];
Expand All @@ -5560,6 +5560,9 @@ class Bn128 {
const beta2 = pkey.slice(10*4 + 192, 10*4 + 320);
const delta2 = pkey.slice(10*4 + 320, 10*4 + 448);

if (!allowDeltaZero && ((this.instance.exports.g1m_isZero(delta1) == 1) || (this.instance.exports.g1m_isZero(delta2) == 1))) {
throw new Error('delta1 or delta2 are zero, subverted CRS');
}

const pH = this.calcH(signals.slice(0), polsA, polsB, nSignals, domainSize).then( (h) => {
/* Debug code to print the result of h
Expand Down
5 changes: 4 additions & 1 deletion example/bn128/websnark_bn128.js
Original file line number Diff line number Diff line change
Expand Up @@ -5534,7 +5534,7 @@ class Bn128 {
}, [signals, polsA, polsB]);
}

async groth16GenProof(signals, pkey) {
async groth16GenProof(signals, pkey, allowDetlaZero) {
const pkey32 = new Uint32Array(pkey);
const nSignals = pkey32[0];
const nPublic = pkey32[1];
Expand All @@ -5560,6 +5560,9 @@ class Bn128 {
const beta2 = pkey.slice(10*4 + 192, 10*4 + 320);
const delta2 = pkey.slice(10*4 + 320, 10*4 + 448);

if (!allowDeltaZero && ((this.instance.exports.g1m_isZero(delta1) == 1) || (this.instance.exports.g1m_isZero(delta2) == 1))) {
throw new Error('delta1 or delta2 are zero, subverted CRS');
}

const pH = this.calcH(signals.slice(0), polsA, polsB, nSignals, domainSize).then( (h) => {
/* Debug code to print the result of h
Expand Down
5 changes: 4 additions & 1 deletion src/bn128.js
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ class Bn128 {
}, [signals, polsA, polsB]);
}

async groth16GenProof(signals, pkey) {
async groth16GenProof(signals, pkey, allowDeltaZero) {
const pkey32 = new Uint32Array(pkey);
const nSignals = pkey32[0];
const nPublic = pkey32[1];
Expand All @@ -604,6 +604,9 @@ class Bn128 {
const beta2 = pkey.slice(10*4 + 192, 10*4 + 320);
const delta2 = pkey.slice(10*4 + 320, 10*4 + 448);

if (!allowDeltaZero && ((this.instance.exports.g1m_isZero(delta1) == 1) || (this.instance.exports.g1m_isZero(delta2) == 1))) {
throw new Error('delta1 or delta2 are zero, subverted CRS');
}

const pH = this.calcH(signals.slice(0), polsA, polsB, nSignals, domainSize).then( (h) => {
/* Debug code to print the result of h
Expand Down
2 changes: 1 addition & 1 deletion test/bn128_prover.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("Basic tests for bn128 proof generator", () => {

const signals = fs.readFileSync(path.join(__dirname, "data", "witness.bin"));
const provingKey = fs.readFileSync(path.join(__dirname, "data", "proving_key.bin"));
const proofS = await bn128.proof(signals.buffer, provingKey.buffer);
const proofS = await bn128.groth16GenProof(signals.buffer, provingKey.buffer, true);

const proof = snarkjs.unstringifyBigInts(proofS);
const verifierKey = snarkjs.unstringifyBigInts(JSON.parse(fs.readFileSync(path.join(__dirname, "data", "verification_key.json"), "utf8")));
Expand Down