chore: update scripts to download snark artifacts

Former-commit-id: d9c069784f
This commit is contained in:
cedoor
2022-06-06 12:01:24 +02:00
parent 68187531a5
commit e21ccedc15
11 changed files with 44 additions and 87 deletions

View File

@@ -0,0 +1,24 @@
import download from "download"
import fs from "fs"
import { config } from "../package.json"
async function main() {
const snarkArtifactsPath = config.paths.build["snark-artifacts"]
const url = `http://www.trusted-setup-pse.org/semaphore/${process.env.TREE_DEPTH}`
if (!fs.existsSync(snarkArtifactsPath)) {
fs.mkdirSync(snarkArtifactsPath, { recursive: true })
}
if (!fs.existsSync(`${snarkArtifactsPath}/semaphore.zkey`)) {
await download(`${url}/semaphore.wasm`, snarkArtifactsPath)
await download(`${url}/semaphore.zkey`, snarkArtifactsPath)
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})

View File

@@ -1,25 +0,0 @@
import download from "download"
import fs from "fs"
import { config } from "../package.json"
async function main() {
const buildPath = config.paths.build["zk-files"]
const url = "http://www.trusted-setup-pse.org/semaphore/semaphore.zip"
if (!fs.existsSync(buildPath)) {
fs.mkdirSync(buildPath, { recursive: true })
}
if (!fs.existsSync(`${buildPath}/16/semaphore.zkey`)) {
await download(url, buildPath, {
extract: true
})
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})

View File

@@ -1,37 +0,0 @@
import fs from "fs"
import logger from "js-logger"
import { zKey } from "snarkjs"
import { config } from "../package.json"
logger.useDefaults()
async function main() {
const buildPath = config.paths.build["zk-files"]
const contractsPath = config.paths.contracts
const templatesPath = config.paths["snarkjs-templates"]
const solidityVersion = config.solidity.version
if (fs.existsSync(`${buildPath}/16/semaphore.zkey`)) {
for (let treeDepth = 16; treeDepth <= 32; treeDepth++) {
let verifierCode = await zKey.exportSolidityVerifier(
`${buildPath}/${treeDepth}/semaphore.zkey`,
{ groth16: fs.readFileSync(`${templatesPath}/verifier_groth16.sol.ejs`, "utf8") },
logger
)
verifierCode = verifierCode.replace(
/pragma solidity \^\d+\.\d+\.\d+/,
`pragma solidity ^${solidityVersion}`
)
verifierCode = verifierCode.replace(/Verifier/, `Verifier${treeDepth}`)
fs.writeFileSync(`${contractsPath}/verifiers/Verifier${treeDepth}.sol`, verifierCode, "utf-8")
}
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})