diff --git a/src/prover/prover_helpers.js b/src/prover/prover_helpers.js index 2f4c708..d6ddd60 100644 --- a/src/prover/prover_helpers.js +++ b/src/prover/prover_helpers.js @@ -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) { @@ -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); @@ -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; @@ -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; diff --git a/src/witness/witnessCalculator.js b/src/witness/witnessCalculator.js index 907c5d3..64ec699 100644 --- a/src/witness/witnessCalculator.js +++ b/src/witness/witnessCalculator.js @@ -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; @@ -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) { @@ -103,6 +110,7 @@ class ColsPil2 { const pos = parseInt(prop, 10); const buffIndex = nCols * pos + symbolId; polBuffer[buffIndex] = value; + return true; }, get(target, prop) { diff --git a/test/state_machines/pil2/sm_fibonacci/main_exec_fibonacci.js b/test/state_machines/pil2/sm_fibonacci/main_exec_fibonacci.js index feaa65d..8dc3cd9 100644 --- a/test/state_machines/pil2/sm_fibonacci/main_exec_fibonacci.js +++ b/test/state_machines/pil2/sm_fibonacci/main_exec_fibonacci.js @@ -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"));