-
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.
test(poseidon): use
jest
instead of built in node test runner (#144)
* test: check validity of poseidon artifacts * chore: define `test` util package * test: use local test package for poseidon test * chore: fmt * refactor * chore: remove test package * fix: update deps * chore: update tsconfig `includes` * test: update snapshot
- Loading branch information
Showing
11 changed files
with
88 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,7 @@ Commands: | |
"poseidon | ||
1.0.0 | ||
1.0.0-beta.1 | ||
1.0.0-beta.4 | ||
semaphore | ||
1.0.0 | ||
4.0.0-beta.9 | ||
|
This file was deleted.
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
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,34 @@ | ||
import { Project } from '@zk-kit/artifacts' | ||
import { generate } from '@zk-kit/poseidon-proof' | ||
import { getCurveFromName } from 'ffjavascript' | ||
import { join } from 'node:path' | ||
import { SCOPE, verifyPoseidonProof } from './utils' | ||
|
||
const INPUTS = Array.from({ length: 16 }, (_, i) => i + 1).map(i => ({ | ||
inputs: Array.from({ length: i }, (_, j) => j + 1), | ||
numberOfInputs: i, | ||
})) | ||
|
||
describe('poseidon', () => { | ||
let curve: any | ||
|
||
beforeAll(async () => { | ||
curve = await getCurveFromName('bn128') | ||
}, 30_000) | ||
|
||
afterAll(async () => { | ||
await curve.terminate() | ||
}) | ||
|
||
it.each(INPUTS)( | ||
'Should verify a poseidon proof with $numberOfInputs input(s)', | ||
async ({ inputs, numberOfInputs }) => { | ||
const proof = await generate(inputs, SCOPE, { | ||
wasm: join(__dirname, '..', `${Project.POSEIDON}-${numberOfInputs}.wasm`), | ||
zkey: join(__dirname, '..', `${Project.POSEIDON}-${numberOfInputs}.zkey`), | ||
}) | ||
const result = await verifyPoseidonProof(proof) | ||
expect(result).toBe(true) | ||
}, | ||
) | ||
}) |
6 changes: 3 additions & 3 deletions
6
packages/artifacts/test/cli/jest.config.ts → packages/poseidon/test/jest.config.ts
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,12 +1,12 @@ | ||
import type { JestConfigWithTsJest } from 'ts-jest' | ||
import _sharedJestConf from '../../../../jest.config' | ||
import _sharedJestConf from '../../../jest.config' | ||
|
||
const { collectCoverage, projects, ...sharedJestConf } = _sharedJestConf | ||
|
||
const config: JestConfigWithTsJest = { | ||
...sharedJestConf, | ||
displayName: 'cli', | ||
rootDir: '../..', | ||
displayName: 'poseidon', | ||
rootDir: '..', | ||
} | ||
|
||
export default config |
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,20 @@ | ||
import { Project } from '@zk-kit/artifacts' | ||
import type { PoseidonProof } from '@zk-kit/poseidon-proof' | ||
import { unpackGroth16Proof } from '@zk-kit/utils' | ||
import { keccak256, toBeHex } from 'ethers' | ||
import { readFileSync } from 'node:fs' | ||
import { join } from 'node:path' | ||
import { groth16 } from 'snarkjs' | ||
|
||
export const SCOPE = 'scope' | ||
|
||
const hash = (message: string) => (BigInt(keccak256(toBeHex(message, 32))) >> BigInt(8)).toString() | ||
|
||
export const verifyPoseidonProof = ( | ||
{ digest, numberOfInputs, proof, scope }: PoseidonProof, | ||
) => { | ||
const verifKey = JSON.parse( | ||
readFileSync(join(__dirname, '..', `${Project.POSEIDON}-${numberOfInputs}.json`), 'utf8'), | ||
) | ||
return groth16.verify(verifKey, [digest, hash(scope)], unpackGroth16Proof(proof)) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,3 @@ | ||
declare module 'ffjavascript' { | ||
export function getCurveFromName(name: any, singleThread?: any, plugins?: any): any | ||
} |