Fix proof generation big proofs

This commit is contained in:
Jordi Baylina 2020-10-22 16:31:05 +02:00
parent 62099732bb
commit 31631db4d6
No known key found for this signature in database
GPG Key ID: 7480C80C1BE43112
5 changed files with 83 additions and 15 deletions

@ -6180,8 +6180,25 @@ async function buldABC(curve, zkey, witness, coeffs) {
const concurrency = curve.tm.concurrency;
const sCoef = 4*3 + zkey.n8r;
let getUint32;
if (coeffs instanceof ffjavascript.BigBuffer) {
const coeffsDV = [];
const PAGE_LEN = coeffs[0].length;
for (let i=0; i< coeffs.buffers.length; i++) {
coeffsDV.push(new DataView(coeffs.buffers[i]));
}
getUint32 = function (pos) {
return coeffsDV[Math.floor(pos/PAGE_LEN)].getUint32(pos % PAGE_LEN, true);
};
} else {
const coeffsDV = new DataView(coeffs.buffer, coeffs.byteOffset, coeffs.byteLength);
getUint32 = function (pos) {
return coeffsDV.getUint32(pos, true);
};
}
const elementsPerChunk = Math.floor(zkey.domainSize/concurrency);
const coeffsDV = new DataView(coeffs.buffer, coeffs.byteOffset, coeffs.byteLength);
const promises = [];
const cutPoints = [];
@ -6239,10 +6256,10 @@ async function buldABC(curve, zkey, witness, coeffs) {
function getCutPoint(v) {
let m = 0;
let n = coeffsDV.getUint32(0, true);
let n = getUint32(0);
while (m < n) {
var k = (n + m) >> 1;
const va = coeffsDV.getUint32(4 + k*sCoef + 4, true);
const va = getUint32(4 + k*sCoef + 4);
if (va > v) {
n = k - 1;
} else if (va < v) {

@ -1668,8 +1668,25 @@ async function buldABC(curve, zkey, witness, coeffs) {
const concurrency = curve.tm.concurrency;
const sCoef = 4*3 + zkey.n8r;
let getUint32;
if (coeffs instanceof ffjavascript.BigBuffer) {
const coeffsDV = [];
const PAGE_LEN = coeffs[0].length;
for (let i=0; i< coeffs.buffers.length; i++) {
coeffsDV.push(new DataView(coeffs.buffers[i]));
}
getUint32 = function (pos) {
return coeffsDV[Math.floor(pos/PAGE_LEN)].getUint32(pos % PAGE_LEN, true);
};
} else {
const coeffsDV = new DataView(coeffs.buffer, coeffs.byteOffset, coeffs.byteLength);
getUint32 = function (pos) {
return coeffsDV.getUint32(pos, true);
};
}
const elementsPerChunk = Math.floor(zkey.domainSize/concurrency);
const coeffsDV = new DataView(coeffs.buffer, coeffs.byteOffset, coeffs.byteLength);
const promises = [];
const cutPoints = [];
@ -1727,10 +1744,10 @@ async function buldABC(curve, zkey, witness, coeffs) {
function getCutPoint(v) {
let m = 0;
let n = coeffsDV.getUint32(0, true);
let n = getUint32(0);
while (m < n) {
var k = (n + m) >> 1;
const va = coeffsDV.getUint32(4 + k*sCoef + 4, true);
const va = getUint32(4 + k*sCoef + 4);
if (va > v) {
n = k - 1;
} else if (va < v) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -3,7 +3,7 @@ import * as zkeyUtils from "./zkey_utils.js";
import * as wtnsUtils from "./wtns_utils.js";
import { getCurveFromQ as getCurve } from "./curves.js";
import { log2 } from "./misc.js";
import { Scalar, utils } from "ffjavascript";
import { Scalar, utils, BigBuffer } from "ffjavascript";
const {stringifyBigInts} = utils;
export default async function groth16Prove(zkeyFileName, witnessFileName, logger) {
@ -118,8 +118,25 @@ async function buldABC(curve, zkey, witness, coeffs) {
const concurrency = curve.tm.concurrency;
const sCoef = 4*3 + zkey.n8r;
let getUint32;
if (coeffs instanceof BigBuffer) {
const coeffsDV = [];
const PAGE_LEN = coeffs[0].length;
for (let i=0; i< coeffs.buffers.length; i++) {
coeffsDV.push(new DataView(coeffs.buffers[i]));
}
getUint32 = function (pos) {
return coeffsDV[Math.floor(pos/PAGE_LEN)].getUint32(pos % PAGE_LEN, true);
};
} else {
const coeffsDV = new DataView(coeffs.buffer, coeffs.byteOffset, coeffs.byteLength);
getUint32 = function (pos) {
return coeffsDV.getUint32(pos, true);
};
}
const elementsPerChunk = Math.floor(zkey.domainSize/concurrency);
const coeffsDV = new DataView(coeffs.buffer, coeffs.byteOffset, coeffs.byteLength);
const promises = [];
const cutPoints = [];
@ -177,10 +194,10 @@ async function buldABC(curve, zkey, witness, coeffs) {
function getCutPoint(v) {
let m = 0;
let n = coeffsDV.getUint32(0, true);
let n = getUint32(0);
while (m < n) {
var k = (n + m) >> 1;
const va = coeffsDV.getUint32(4 + k*sCoef + 4, true);
const va = getUint32(4 + k*sCoef + 4);
if (va > v) {
n = k - 1;
} else if (va < v) {