@zk-kit/poseidon-proof v1.0.0-beta.3
This zero-knowledge library facilitates the demonstration of having a Poseidon hash pre-image while keeping the pre-image value confidential. Additionally, it offers a mechanism to prevent the same proof from being reused. The circuit that forms the foundation of this library is accessible via this link. |
---|
Originally developed for integration with Semaphore V4, this library also functions effectively as a standalone tool. Notable use cases in connection with Semaphore can be:
- allowing a Semaphore user to prove that they possess the secret value associated with the identity commitment of their Semaphore identity,
- unmasking the identity of zero-knowledge proofs earlier created using Semaphore.
The Snark artifacts (.wasm
and .zkey
files) can be specified or not in the generate
function parameters and can possibly be downloaded using the following URLs:
!WARNING
The Snark artifacts currently used to generate zero-knowledge proofs are the result of an unsecure trusted setup, and the library has not yet been audited. Therefore, it is advised not to use it in production.
🛠 Install
npm or yarn
Install the @zk-kit/poseidon-proof
package:
npm i @zk-kit/poseidon-proof
or yarn:
yarn add @zk-kit/poseidon-proof
📜 Usage
# generate( message: BigNumberish, scope: BigNumberish, snarkArtifacts?: SnarkArtifacts ): Promise\<PoseidonProof>
import { generate } from "@zk-kit/poseidon-proof"
const scope = 1
const message = 2
const fullProof = await generate(message, scope)
// If not specified, the Snark artifacts are downloaded automatically.
// You can also specify them.
const fullProof = await generate(message, scope, {
zkeyFilePath: "./poseidon-proof.zkey",
wasmFilePath: "./poseidon-proof.wasm"
})
console.log(fullProof)
/*
{
scope: '1',
hash: '8645981980787649023086883978738420856660271013038108762834452721572614684349',
nullifier: '7853200120776062878684798364095072458815029376092732009249414926327459813530',
proof: [
'8439157877715136449451128027974582198942685548176158240742469858289217640295',
'7742778415084033741154475792823260193410560424636243716622958831215275441500',
'19005176609208302398813682947612978224483117018101271134113308439452561466691',
'6209272538382784759793219866517186573065390524051102537220446165983489601194',
'12222537243697573476419214640884921904066033266502734603198915705889607365883',
'20066191345466355816238393590466176790809335456890624395337970890893401456064',
'4851746896803117511000878727783002155680855098198108089136166702412365578625',
'18391775232946751568173446051923718267369779168471637305003186214102154164036'
]
}
*/
# verify(poseidonProof: PoseidonProof): Promise\<boolean>
import { verify } from "@zk-key/poseidon-proof"
const response = await verifyProof(fullProof)
console.log(response) // true or false
// Eventually you may want to check the nullifier.
📈 Benchmarks
Benchmarks were run on an Intel Core i7-1165G7, 16 GB RAM machine, after initializing the BN128 curve with @zk-kit/groth16
-buildBn128
(~230ms).
Generate proof | Verify proof | Constraints |
---|---|---|
80ms | 10ms | 141 |
import { generate, verify } from "@zk-kit/poseidon-proof"
import { buildBn128 } from "@zk-kit/groth16"
await buildBn128()
console.time("generate")
const proof = await generate(1, 2)
console.timeEnd("generate")
console.time("verify")
console.log(await verify(proof))
console.timeEnd("verify")
1 day ago
1 day ago
1 day ago
28 days ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago