-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(poseidon): add verification key json files (#125)
* chore(poseidon): add verification key json files * chore(poseidon): bump version in package.json * chore: update .gitignore * chore(cli): update `start.cli` script * refactor * feat(poseidon): add verification keys * test(poseidon): check validity of artifacts (#143) * test(poseidon): verify proofs * test: update
- Loading branch information
Showing
54 changed files
with
1,895 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ dist | |
.envrc | ||
.tool-versions | ||
.DS_Store | ||
snark-artifacts |
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,71 +1,71 @@ | ||
{ | ||
"name": "@zk-kit/artifacts", | ||
"version": "2.0.1", | ||
"type": "module", | ||
"bin": { | ||
"snarkli": "./dist/cli/index.js" | ||
}, | ||
"description": "Utilities for downloading snark artifacts", | ||
"scripts": { | ||
"build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript", | ||
"test": "jest -c test/jest.config.ts", | ||
"prepublishOnly": "pnpm run build", | ||
"start.cli": "[ ! -f dist/cli/index.js ] && pnpm run build; node dist/cli", | ||
"typecheck": "tsc" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/privacy-scaling-explorations/snark-artifacts.git" | ||
}, | ||
"keywords": [ | ||
"snark", | ||
"artifacts", | ||
"circom", | ||
"zk" | ||
], | ||
"contributors": [ | ||
"cedoor <[email protected]>", | ||
"sripwoud <[email protected]" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/privacy-scaling-explorations/snark-artifacts/issues" | ||
}, | ||
"homepage": "https://github.com/privacy-scaling-explorations/snark-artifacts/tree/main/packages/artifacts", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "./dist/index.node.js", | ||
"types": "./dist/types/index.node.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/types/index.browser.d.ts", | ||
"node": { | ||
"types": "./dist/types/index.node.d.ts", | ||
"import": "./dist/index.node.js", | ||
"require": "./dist/index.node.cjs", | ||
"default": "./dist/index.node.cjs" | ||
}, | ||
"browser": "./dist/index.browser.js", | ||
"default": "./dist/index.browser.js" | ||
} | ||
}, | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"devDependencies": { | ||
"@rollup/plugin-typescript": "^11.1.6", | ||
"@types/node": "^20.12.10", | ||
"rimraf": "^5.0.5", | ||
"rollup": "^4.18.1" | ||
}, | ||
"dependencies": { | ||
"@commander-js/extra-typings": "^12.1.0", | ||
"@inquirer/input": "^2.1.8", | ||
"@inquirer/select": "^2.3.4", | ||
"circomkit": "^0.2.1", | ||
"ora": "^5.4.1", | ||
"snarkjs": "^0.7.4" | ||
"name": "@zk-kit/artifacts", | ||
"version": "2.0.1", | ||
"type": "module", | ||
"bin": { | ||
"snarkli": "./dist/cli/index.js" | ||
}, | ||
"description": "Utilities for downloading snark artifacts", | ||
"scripts": { | ||
"build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript", | ||
"test": "jest -c test/jest.config.ts", | ||
"prepublishOnly": "pnpm run build", | ||
"start.cli": "pnpm run build && node dist/cli", | ||
"typecheck": "tsc" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/privacy-scaling-explorations/snark-artifacts.git" | ||
}, | ||
"keywords": [ | ||
"snark", | ||
"artifacts", | ||
"circom", | ||
"zk" | ||
], | ||
"contributors": [ | ||
"cedoor <[email protected]>", | ||
"sripwoud <[email protected]" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/privacy-scaling-explorations/snark-artifacts/issues" | ||
}, | ||
"homepage": "https://github.com/privacy-scaling-explorations/snark-artifacts/tree/main/packages/artifacts", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "./dist/index.node.js", | ||
"types": "./dist/types/index.node.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/types/index.browser.d.ts", | ||
"node": { | ||
"types": "./dist/types/index.node.d.ts", | ||
"import": "./dist/index.node.js", | ||
"require": "./dist/index.node.cjs", | ||
"default": "./dist/index.node.cjs" | ||
}, | ||
"browser": "./dist/index.browser.js", | ||
"default": "./dist/index.browser.js" | ||
} | ||
}, | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"devDependencies": { | ||
"@rollup/plugin-typescript": "^11.1.6", | ||
"@types/node": "^20.12.10", | ||
"rimraf": "^5.0.5", | ||
"rollup": "^4.18.1" | ||
}, | ||
"dependencies": { | ||
"@commander-js/extra-typings": "^12.1.0", | ||
"@inquirer/input": "^2.1.8", | ||
"@inquirer/select": "^2.3.4", | ||
"circomkit": "^0.2.1", | ||
"ora": "^5.4.1", | ||
"snarkjs": "^0.7.4" | ||
} | ||
} |
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,67 @@ | ||
import { generate } from '@zk-kit/poseidon-proof' | ||
import { unpackGroth16Proof } from '@zk-kit/utils/proof-packing' | ||
import { keccak256 } from 'ethers/crypto' | ||
import { toBeHex } from 'ethers/utils' | ||
import { getCurveFromName } from 'ffjavascript' | ||
import assert from 'node:assert/strict' | ||
import { readFileSync } from 'node:fs' | ||
import { dirname, join } from 'node:path' | ||
import { after, before, describe, test } from 'node:test' | ||
import * as poseidons from 'poseidon-lite' | ||
import { groth16 } from 'snarkjs' | ||
|
||
function hash(message) { | ||
return (BigInt(keccak256(toBeHex(message, 32))) >> BigInt(8)).toString() | ||
} | ||
|
||
const PWD = dirname(import.meta.url.replace('file://', '')) | ||
const SCOPE = 'scope' | ||
const INPUTS = Array.from({ length: 16 }, (_, i) => i + 1).map(i => Array.from({ length: i }, (_, j) => j + 1)) | ||
|
||
async function generateProof(inputs) { | ||
const numParams = inputs.length | ||
|
||
return generate(inputs, SCOPE, { | ||
wasm: join(PWD, `poseidon-${numParams}.wasm`), | ||
zkey: join(PWD, `poseidon-${numParams}.zkey`), | ||
}) | ||
} | ||
|
||
async function verifyProof({ digest, numberOfInputs, proof, scope }) { | ||
const verifKey = JSON.parse(readFileSync(join(PWD, `poseidon-${numberOfInputs}.json`))) | ||
return groth16.verify(verifKey, [digest, hash(scope)], unpackGroth16Proof(proof)) | ||
} | ||
|
||
describe('poseidon', () => { | ||
const scope = 'scope' | ||
let curve | ||
let digest | ||
const proofs = [] | ||
|
||
before(async () => { | ||
curve = await getCurveFromName('bn128') | ||
|
||
for (const inputs of INPUTS) { | ||
const proof = await generateProof(inputs) | ||
proofs.push(proof) | ||
} | ||
}, 30_000) | ||
|
||
after(async () => { | ||
await curve.terminate() | ||
}) | ||
|
||
test('Should verify all Poseidon proofs', async (t) => { | ||
for (const proof of proofs) { | ||
const { numberOfInputs } = proof | ||
await t.test(`Should verify a Poseidon proof with ${numberOfInputs} parameter(s)`, async (t) => { | ||
const result = await verifyProof(proof) | ||
assert.strictEqual( | ||
result, | ||
true, | ||
`Proof verification failed for ${numberOfInputs} parameter${numberOfInputs > 1 ? 's' : ''}`, | ||
) | ||
}) | ||
} | ||
}) | ||
}) |
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,99 @@ | ||
{ | ||
"protocol": "groth16", | ||
"curve": "bn128", | ||
"nPublic": 2, | ||
"vk_alpha_1": [ | ||
"20491192805390485299153009773594534940189261866228447918068658471970481763042", | ||
"9383485363053290200918347156157836566562967994039712273449902621266178545958", | ||
"1" | ||
], | ||
"vk_beta_2": [ | ||
[ | ||
"6375614351688725206403948262868962793625744043794305715222011528459656738731", | ||
"4252822878758300859123897981450591353533073413197771768651442665752259397132" | ||
], | ||
[ | ||
"10505242626370262277552901082094356697409835680220590971873171140371331206856", | ||
"21847035105528745403288232691147584728191162732299865338377159692350059136679" | ||
], | ||
[ | ||
"1", | ||
"0" | ||
] | ||
], | ||
"vk_gamma_2": [ | ||
[ | ||
"10857046999023057135944570762232829481370756359578518086990519993285655852781", | ||
"11559732032986387107991004021392285783925812861821192530917403151452391805634" | ||
], | ||
[ | ||
"8495653923123431417604973247489272438418190587263600148770280649306958101930", | ||
"4082367875863433681332203403145435568316851327593401208105741076214120093531" | ||
], | ||
[ | ||
"1", | ||
"0" | ||
] | ||
], | ||
"vk_delta_2": [ | ||
[ | ||
"3157975945221760019780653021768983303240570188057358198718286948576293769637", | ||
"1168852709034697964767879935082196399493566161364132837006457069681024105649" | ||
], | ||
[ | ||
"16163470123996341422922694561925306221648024098447326302911331111121753640584", | ||
"9276021473371070258982295893437827370362831845456822584750788309275437040607" | ||
], | ||
[ | ||
"1", | ||
"0" | ||
] | ||
], | ||
"vk_alphabeta_12": [ | ||
[ | ||
[ | ||
"2029413683389138792403550203267699914886160938906632433982220835551125967885", | ||
"21072700047562757817161031222997517981543347628379360635925549008442030252106" | ||
], | ||
[ | ||
"5940354580057074848093997050200682056184807770593307860589430076672439820312", | ||
"12156638873931618554171829126792193045421052652279363021382169897324752428276" | ||
], | ||
[ | ||
"7898200236362823042373859371574133993780991612861777490112507062703164551277", | ||
"7074218545237549455313236346927434013100842096812539264420499035217050630853" | ||
] | ||
], | ||
[ | ||
[ | ||
"7077479683546002997211712695946002074877511277312570035766170199895071832130", | ||
"10093483419865920389913245021038182291233451549023025229112148274109565435465" | ||
], | ||
[ | ||
"4595479056700221319381530156280926371456704509942304414423590385166031118820", | ||
"19831328484489333784475432780421641293929726139240675179672856274388269393268" | ||
], | ||
[ | ||
"11934129596455521040620786944827826205713621633706285934057045369193958244500", | ||
"8037395052364110730298837004334506829870972346962140206007064471173334027475" | ||
] | ||
] | ||
], | ||
"IC": [ | ||
[ | ||
"19490069286251317200471893224761952280235157078692599655063040494106083015102", | ||
"15613730057977833735664106983317680013118142165231654768046521650638333652991", | ||
"1" | ||
], | ||
[ | ||
"1563543155852853229359605494188815884199915022658219002707722789976065966419", | ||
"858819375930654753672617171465307097688802650498051619587167586479724200799", | ||
"1" | ||
], | ||
[ | ||
"3808889614445935800597561392085733302718838702771107544944545050886958022904", | ||
"13293649293049947010793838294353767499934999769633605908974566715226392122400", | ||
"1" | ||
] | ||
] | ||
} |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.