Skip to content

Commit

Permalink
Minor adjustment prover_helpers and generateWtnsCols
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerTaule committed Jun 13, 2024
1 parent 9f4e1b1 commit f9ea0e1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 48 deletions.
65 changes: 23 additions & 42 deletions src/prover/prover_helpers.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
const workerpool = require("workerpool");
const {BigBuffer} = require("ffjavascript");
const {BigBuffer} = require("pilcom");
const { starkgen_execute } = require("./stark_prover_worker");
const { fflonkgen_execute } = require("./fflonk_prover_worker");
const F3g = require("../helpers/f3g");

const maxNperThread = 1<<18;
const minNperThread = 1<<12;

module.exports.calculateExpression = function calculateExpression(ctx, expId, dom = "n") {
module.exports.calculateExpression = function calculateExpression(ctx, expId) {
const expressionCode = ctx.expressionsInfo.expressionsCode.find(e => e.expId === expId);
return module.exports.calculateExps(ctx, expressionCode.code, dom, false, true);
return module.exports.calculateExps(ctx, expressionCode.code, "n", false, true);
}

module.exports.calculateExpressionAtRow = function calculateExpressionAtRow(ctx, expId, row) {
Expand All @@ -30,7 +31,7 @@ module.exports.calculateExps = function calculateExps(ctx, code, dom, debug, ret
const retValue = debug || ret || false;
cEveryRow = new Function("ctx", "i", module.exports.compileCode(ctx, code.code, dom, retValue, global));

const N = dom=="n" ? ctx.N : ctx.extN;
const N = dom=="n" ? 1 << ctx.nBits : 1 << ctx.nBitsExt;

const pCtx = ctxProxy(ctx, global);

Expand All @@ -41,6 +42,7 @@ module.exports.calculateExps = function calculateExps(ctx, code, dom, debug, ret
}
} else {
let first, last;
pCtx.errors = [];
if(code.boundary === "everyRow") {
first = 0;
last = N;
Expand Down Expand Up @@ -540,56 +542,35 @@ module.exports.printPol = function printPol(buffer, Fr) {
console.log("---------------------------");
}

function ctxProxy(ctx, global) {
function ctxProxy(ctx, global, stark = true) {
const pCtx = {};

const stark = ctx.prover === "stark" ? true : false;

if(!global) {
createProxy("const_n", stark);
createProxy("const_ext", stark);
createProxy("const_coefs", stark);
for(let i = 0; i < ctx.pilInfo.nStages; i++) {
createProxy(`cm${i + 1}_n`, stark);
createProxy(`cm${i + 1}_ext`, stark);
if(!stark) createProxy(`cm${i + 1}_coefs`, stark);
}

createProxy("tmpExp_n", stark);
createProxy("x_n", stark);
createProxy("x_ext", stark);
createProxy("q_ext", stark);

if(stark) {
createProxy(`cm${ctx.pilInfo.nStages + 1}_ext`, stark);

createProxy("Zi_ext", stark);

createProxy("xDivXSubXi_ext", stark);

createProxy("f_ext", stark);
for(let i = 0; i < Object.keys(ctx).length; ++i) {
const key = Object.keys(ctx)[i];
if(ctx[key] instanceof BigBuffer) {
createProxy(key, stark);
}
}
}

pCtx.N = ctx.N;
pCtx.nBits = ctx.nBits;
pCtx.N = 1 << ctx.nBits;

pCtx.extN = ctx.extN;
pCtx.nBitsExt = ctx.nBitsExt;
if(ctx.nBitsExt) {
pCtx.nBitsExt = ctx.nBitsExt;
pCtx.extN = ctx.extN;
}

pCtx.tmp = ctx.tmp;

pCtx.pilInfo = ctx.pilInfo;

pCtx.F = ctx.F;

pCtx.publics = ctx.publics;
pCtx.challenges = ctx.challenges;
pCtx.challengesFRISteps = ctx.challengesFRISteps;
pCtx.subAirValues = ctx.subAirValues;
pCtx.evals = ctx.evals;
pCtx.F = new F3g();

pCtx.errors = ctx.errors;
if(ctx.publics) pCtx.publics = ctx.publics;
if(ctx.challenges) pCtx.challenges = ctx.challenges;
if(ctx.challengesFRISteps) pCtx.challengesFRISteps = ctx.challengesFRISteps;
if(ctx.subAirValues) pCtx.subAirValues = ctx.subAirValues;
if(ctx.evals) pCtx.evals = ctx.evals;

return pCtx;

Expand Down
18 changes: 13 additions & 5 deletions src/witness/witnessCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports.generateFixedCols = function generateFixedCols(symbols, degree) {
return fixedCols;
}

module.exports.generateWtnsCols = function generateWtnsCols(stage, symbols, degree) {
module.exports.generateWtnsCols = function generateWtnsCols(stage, symbols, degree, nCols, buffer) {
const witnessSymbols = [];
for (let i = 0; i < symbols.length; ++i) {
if(symbols[i].type !== 3 || symbols[i].stage !== stage) continue;
Expand All @@ -51,19 +51,26 @@ module.exports.generateWtnsCols = function generateWtnsCols(stage, symbols, degr
}
}

const wtnsCols = new ColsPil2(witnessSymbols, degree);
const wtnsCols = new ColsPil2(witnessSymbols, degree, nCols, buffer);
return wtnsCols;
}

class ColsPil2 {
constructor(symbols, degree) {
constructor(symbols, degree, nCols, buffer) {
this.$$def = {};
this.$$defArray = [];

if(!nCols) nCols = symbols.length;

this.F = new F3g();
this.$$n = degree;
this.$$nCols = symbols.length;
this.polBuffer = new BigBuffer(symbols.length*this.$$n);
this.$$nCols = nCols;

if(!buffer) {
this.polBuffer = new BigBuffer(this.$$nCols*this.$$n);
} else {
this.polBuffer = buffer;
}

this.symbols = symbols;
for(let i = 0; i < symbols.length; ++i) {
Expand Down Expand Up @@ -103,6 +110,7 @@ class ColsPil2 {
const pos = parseInt(prop, 10);
const buffIndex = nCols * pos + symbolId;
polBuffer[buffIndex] = value;
return true;
},

get(target, prop) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function run() {
const pil = pilout.subproofs[0].airs[0];
pil.symbols = pilout.symbols;

const cmPols = generateWtnsCols(1, pil.symbols, pil.numRows, F);
const cmPols = generateWtnsCols(1, pil.symbols, pil.numRows);

const input = JSON.parse(await fs.promises.readFile(inputFile, "utf8"));

Expand Down

0 comments on commit f9ea0e1

Please sign in to comment.