-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from 0xPolygonHermez/develop
Merging develop to main
- Loading branch information
Showing
47 changed files
with
3,835 additions
and
1,349 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,7 @@ class ExpressionOps { | |
number(n) { | ||
return { | ||
op: "number", | ||
value: BigInt(n) | ||
value: n.toString() | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const { generateParser, getAllOperations } = require("./stark/chelpers/generateParser"); | ||
const fs = require("fs"); | ||
|
||
const version = require("../package").version; | ||
|
||
const argv = require("yargs") | ||
.version(version) | ||
.usage("node main_buildchelpers_generic.js -c <chelpers.cpp>") | ||
.alias("c", "chelpers") | ||
.string("parserType") | ||
.argv; | ||
|
||
async function run() { | ||
const cHelpersFile = typeof (argv.chelpers) === "string" ? argv.chelpers.trim() : "mycircuit.chelpers"; | ||
|
||
let operations = getAllOperations(); | ||
|
||
let parserType = "avx"; | ||
|
||
if(argv.parserType) { | ||
if(!["avx", "avx512","pack"].includes(argv.parserType)) throw new Error("Invalid parser type"); | ||
parserType = argv.parserType; | ||
} | ||
|
||
const parser = generateParser(operations, undefined, parserType); | ||
|
||
const cHelpersStepsName = parserType === "avx" ? `CHELPERS_STEPS_HPP` : parserType === "avx512" ? "CHELPERS_STEPS_AVX512_HPP" : "CHELPERS_STEPS_PACK_HPP"; | ||
|
||
const cHelpersStepsClassName = parserType === "avx" ? `CHelpersSteps` : parserType === "avx512" ? "CHelpersStepsAvx512 : public CHelpersSteps" : "CHelpersStepsPack : public CHelpersSteps"; | ||
|
||
const cHelpersStepsHpp = [ | ||
`#ifndef ${cHelpersStepsName}`, | ||
`#define ${cHelpersStepsName}`, | ||
`#include "chelpers.hpp"`, | ||
`${parserType !== "avx" ? `#include "chelpers_steps.hpp"` : ""}`, | ||
`#include "steps.hpp"\n`, | ||
`class ${cHelpersStepsClassName} {`, | ||
"public:", | ||
]; | ||
|
||
cHelpersStepsHpp.push(parser); | ||
cHelpersStepsHpp.push("};\n"); | ||
cHelpersStepsHpp.push("#endif") | ||
|
||
await fs.promises.writeFile(cHelpersFile, cHelpersStepsHpp.join("\n"), "utf8"); | ||
|
||
console.log("Generic parser generated correctly"); | ||
} | ||
|
||
run().then(() => { | ||
process.exit(0); | ||
}, (err) => { | ||
console.log(err.message); | ||
console.log(err.stack); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const fs = require("fs"); | ||
const version = require("../package").version; | ||
|
||
const { calculateIntermediatePolynomials } = require("./pil_info/imPolsCalculation/imPolynomials"); | ||
|
||
const argv = require("yargs") | ||
.version(version) | ||
.usage("node main_calculateimpols.js -f <infopil.json> -m <impols.json>") | ||
.alias("f", "infopil") | ||
.alias("m", "impols") | ||
.argv; | ||
|
||
async function run() { | ||
const infoPilFile = typeof(argv.infopil) === "string" ? argv.infopil.trim() : "mycircuit.infopil.json"; | ||
const imPolsFile = typeof(argv.impols) === "string" ? argv.impols.trim() : "mycircuit.impols.json"; | ||
|
||
const infoPil = JSON.parse(await fs.promises.readFile(infoPilFile, "utf8")); | ||
|
||
const expressions = infoPil.expressions; | ||
const maxDeg = infoPil.maxDeg; | ||
const cExpId = infoPil.cExpId; | ||
const qDim = infoPil.qDim; | ||
|
||
const imPols = calculateIntermediatePolynomials(expressions, cExpId, maxDeg, qDim); | ||
|
||
await fs.promises.writeFile(imPolsFile, JSON.stringify(imPols, null, 1), "utf8"); | ||
|
||
console.log("files Generated Correctly"); | ||
} | ||
|
||
run().then(()=> { | ||
process.exit(0); | ||
}, (err) => { | ||
console.log(err.message); | ||
console.log(err.stack); | ||
process.exit(1); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const fs = require("fs"); | ||
const version = require("../package").version; | ||
|
||
const { generatePilCode } = require("./pil_info/generatePilCode"); | ||
const { addIntermediatePolynomials } = require("./pil_info/imPolsCalculation/imPolynomials"); | ||
const map = require("./pil_info/map"); | ||
const { compile } = require("pilcom"); | ||
const F3g = require("./helpers/f3g"); | ||
|
||
const argv = require("yargs") | ||
.version(version) | ||
.usage("node main_genpilcode.js -f <infopil.json> -p <pil.json> -m <impols.json> -i <starkinfo.json>") | ||
.alias("p", "pil") | ||
.alias("f", "infopil") | ||
.alias("m", "impols") | ||
.alias("i", "starkinfo") | ||
.argv; | ||
|
||
async function run() { | ||
const F = new F3g(); | ||
|
||
const infoPilFile = typeof(argv.infopil) === "string" ? argv.infopil.trim() : "mycircuit.infopil.json"; | ||
const imPolsFile = typeof(argv.impols) === "string" ? argv.impols.trim() : "mycircuit.impols.json"; | ||
|
||
const pilFile = typeof(argv.pil) === "string" ? argv.pil.trim() : "mycircuit.pil"; | ||
const pil = await compile(F, pilFile); | ||
|
||
const starkInfoFile = typeof(argv.starkinfo) === "string" ? argv.starkinfo.trim() : "mycircuit.starkinfo.json"; | ||
|
||
const infoPil = JSON.parse(await fs.promises.readFile(infoPilFile, "utf8")); | ||
const imPols = JSON.parse(await fs.promises.readFile(imPolsFile, "utf8")); | ||
|
||
const res = infoPil.res; | ||
const expressions = imPols.newExpressions; | ||
const qDeg = imPols.qDeg; | ||
const imExps = imPols.imExps; | ||
|
||
addIntermediatePolynomials(res, expressions, imExps, qDeg); | ||
|
||
generatePilCode(res, pil, expressions); | ||
|
||
map(res, expressions); | ||
|
||
console.log("--------------------- POLINOMIALS INFO ---------------------") | ||
console.log(`Columns stage 1: ${res.nCm1} -> Columns in the basefield: ${res.mapSectionsN.cm1_2ns}`); | ||
console.log(`Columns stage 2: ${res.nCm2} -> Columns in the basefield: ${res.mapSectionsN.cm2_2ns}`); | ||
console.log(`Columns stage 3: ${res.nCm3} (${res.nImPols} intermediate polinomials) -> Columns in the basefield: ${res.mapSectionsN.cm3_2ns}`); | ||
console.log(`Columns stage 4: ${res.nCm4} -> Columns in the basefield: ${res.mapSectionsN.cm4_2ns}`); | ||
console.log(`Total Columns: ${res.nCm1 + res.nCm2 + res.nCm3 + res.nCm4} -> Total Columns in the basefield: ${res.mapSectionsN.cm1_2ns + res.mapSectionsN.cm2_2ns + res.mapSectionsN.cm3_2ns + res.mapSectionsN.cm4_2ns}`); | ||
console.log(`Total Constraints: ${res.nConstraints}`) | ||
console.log(`Number of evaluations: ${res.evMap.length}`) | ||
console.log("------------------------------------------------------------") | ||
|
||
await fs.promises.writeFile(starkInfoFile, JSON.stringify(res, null, 1), "utf8"); | ||
|
||
console.log("files Generated Correctly"); | ||
} | ||
|
||
run().then(()=> { | ||
process.exit(0); | ||
}, (err) => { | ||
console.log(err.message); | ||
console.log(err.stack); | ||
process.exit(1); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const fs = require("fs"); | ||
const version = require("../package").version; | ||
|
||
const F3g = require("./helpers/f3g.js"); | ||
const { compile } = require("pilcom"); | ||
const { preparePil } = require("./pil_info/preparePil"); | ||
|
||
const argv = require("yargs") | ||
.version(version) | ||
.usage("node main_preparepil.js -p <pil.json> [-P <pilconfig.json] -s <starkstruct.json> -f <infopil.json>") | ||
.alias("p", "pil") | ||
.alias("P", "pilconfig") | ||
.alias("s", "starkstruct") | ||
.alias("f", "infopil") | ||
.argv; | ||
|
||
async function run() { | ||
const F = new F3g(); | ||
|
||
const pilFile = typeof(argv.pil) === "string" ? argv.pil.trim() : "mycircuit.pil"; | ||
const pilConfig = typeof(argv.pilconfig) === "string" ? JSON.parse(fs.readFileSync(argv.pilconfig.trim())) : {}; | ||
|
||
const starkStructFile = typeof(argv.starkstruct) === "string" ? argv.starkstruct.trim() : "mycircuit.stark_struct.json"; | ||
|
||
const infoPilFile = typeof(argv.infopil) === "string" ? argv.infopil.trim() : "mycircuit.infopil.json"; | ||
|
||
let pil = await compile(F, pilFile, null, pilConfig); | ||
|
||
const starkStruct = JSON.parse(await fs.promises.readFile(starkStructFile, "utf8")); | ||
|
||
const infoPil = preparePil(F, pil, starkStruct); | ||
|
||
let maxDeg = (1 << (starkStruct.nBitsExt - starkStruct.nBits)) + 1; | ||
|
||
const infoPilJSON = { maxDeg, cExpId: infoPil.res.cExpId, qDim: infoPil.res.qDim, ...infoPil }; | ||
|
||
console.log("Writing file..."); | ||
|
||
await fs.promises.writeFile(infoPilFile, JSON.stringify(infoPilJSON, null, 1), "utf8"); | ||
|
||
console.log("files Generated Correctly"); | ||
} | ||
|
||
run().then(()=> { | ||
process.exit(0); | ||
}, (err) => { | ||
console.log(err.message); | ||
console.log(err.stack); | ||
process.exit(1); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.