-
Notifications
You must be signed in to change notification settings - Fork 30
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 #63 from 0xPolygonHermez/develop
Merging changes Etrog to main
- Loading branch information
Showing
22 changed files
with
441 additions
and
213 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,8 +1,10 @@ | ||
const FGL = require("./src/f3g"); | ||
const F3g = require("./src/helpers/f3g"); | ||
|
||
|
||
module.exports.FGL = new FGL(); | ||
module.exports.starkSetup = require("./src/stark_setup.js"); | ||
module.exports.starkGen = require("./src/stark_gen.js"); | ||
module.exports.starkVerify = require("./src/stark_verify.js"); | ||
module.exports.r1cs2plonk = require("./src/r1cs2plonk"); | ||
module.exports.F3g = new F3g(); | ||
module.exports.pil2circom = require("./src/pil2circom.js"); | ||
module.exports.starkSetup = require("./src/stark/stark_setup.js"); | ||
module.exports.starkGen = require("./src/stark/stark_gen.js"); | ||
module.exports.starkVerify = require("./src/stark/stark_verify.js"); | ||
module.exports.r1cs2plonk = require("./src/r1cs2plonk"); | ||
module.exports.starkInfo = require("./src/stark/stark_info"); |
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,52 @@ | ||
const { newCommitPolsArray } = require("pilcom"); | ||
const { WitnessCalculatorBuilder } = require("circom_runtime"); | ||
const fs = require("fs"); | ||
|
||
module.exports.compressorExec = async function compressorExec(F, pil, wasm, input, exec) { | ||
const cmPols = newCommitPolsArray(pil); | ||
|
||
const nCols = cmPols.Compressor.a.length; | ||
|
||
const { nAdds, nSMap, addsBuff, sMapBuff } = exec; | ||
|
||
const wc = await WitnessCalculatorBuilder(wasm); | ||
const w = await wc.calculateWitness(input); | ||
|
||
for (let i=0; i<nAdds; i++) { | ||
w.push( F.add( F.mul( w[addsBuff[i*4]], addsBuff[i*4 + 2]), F.mul( w[addsBuff[i*4+1]], addsBuff[i*4+3] ))); | ||
} | ||
|
||
for (let i=0; i<nSMap; i++) { | ||
for (let j=0; j<nCols; j++) { | ||
if (sMapBuff[nCols*i+j] != 0) { | ||
cmPols.Compressor.a[j][i] = w[sMapBuff[nCols*i+j]]; | ||
} else { | ||
cmPols.Compressor.a[j][i] = 0n; | ||
} | ||
} | ||
} | ||
|
||
return cmPols; | ||
} | ||
|
||
|
||
module.exports.readExecFile = async function readExecFile(execFile, nCols) { | ||
|
||
const fd =await fs.promises.open(execFile, "r"); | ||
const buffH = new BigUint64Array(2); | ||
await fd.read(buffH, 0, 2*8); | ||
const nAdds= Number(buffH[0]); | ||
const nSMap= Number(buffH[1]); | ||
|
||
|
||
const addsBuff = new BigUint64Array(nAdds*4); | ||
await fd.read(addsBuff, 0, nAdds*4*8); | ||
|
||
const sMapBuff = new BigUint64Array(nSMap*nCols); | ||
await fd.read(sMapBuff, 0, nSMap*nCols*8); | ||
|
||
await fd.close(); | ||
|
||
return { nAdds, nSMap, addsBuff, sMapBuff }; | ||
|
||
} |
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,46 @@ | ||
const {readR1cs} = require("r1csfile"); | ||
const plonkSetupC18 = require("./compressor18_setup.js"); | ||
const plonkSetupC12 = require("./compressor12_setup.js"); | ||
|
||
module.exports.compressorSetup = async function compressorSetup(F, r1csFile, cols, options = {}) { | ||
const r1cs = await readR1cs(r1csFile, {F: F, logger:console }); | ||
|
||
if(![12,18].includes(cols)) throw new Error("Invalid number of cols"); | ||
|
||
let res; | ||
if(cols === 12) { | ||
res = await plonkSetupC12(F, r1cs, options); | ||
} else { | ||
res = await plonkSetupC18(F, r1cs, options); | ||
} | ||
|
||
const exec = await writeExecFile(res.plonkAdditions, res.sMap); | ||
|
||
return {exec, pilStr: res.pilStr, constPols: res.constPols}; | ||
} | ||
|
||
|
||
|
||
async function writeExecFile(adds, sMap) { | ||
|
||
const size = 2 + adds.length*4 + sMap.length*sMap[0].length; | ||
const buff = new BigUint64Array(size); | ||
|
||
buff[0] = BigInt(adds.length); | ||
buff[1] = BigInt(sMap[0].length); | ||
|
||
for (let i=0; i< adds.length; i++) { | ||
buff[2 + i*4 ] = BigInt(adds[i][0]); | ||
buff[2 + i*4 + 1 ] = BigInt(adds[i][1]); | ||
buff[2 + i*4 + 2 ] = adds[i][2]; | ||
buff[2 + i*4 + 3 ] = adds[i][3]; | ||
} | ||
|
||
for (let i=0; i<sMap[0].length; i++) { | ||
for (let c=0; c<sMap.length; c++) { | ||
buff[2 + adds.length*4 + sMap.length*i + c] = BigInt(sMap[c][i]); | ||
} | ||
} | ||
|
||
return buff; | ||
} |
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.