Module @zk-kit/poseidon-proof

Poseidon proof

A library to generate and verify Poseidon proofs.

NPM license NPM version Downloads npm bundle size (scoped) Linter eslint Code style prettier

🗣️ Chat & Support   |   📘 Docs

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:

The Snark artifacts currently used to generate zero-knowledge proofs are the result of an insecure 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

import { generate, verify } from "@zk-kit/poseidon-proof"

// A public value used to contextualize the cryptographic proof and calculate the nullifier.
const scope = 1
// The message (preimage) to prove (secret).
const message = 2

// Generate the proof.
const fullProof = await generate(message, scope)

nb. scope, digest and nullifier are always the same - proof is variable.
scope: '2',
digest: '13713635907739611880977640264956372443229506353728466835599871320028961887800',
nullifier: '4995263610384888704435371233168916617325583088652670186865584118891394144999',
proof: [

// If not specified, the Snark artifacts are downloaded automatically.
// You can specify them as follows.

// const fullProof = await generate(message, scope, {
// wasmFilePath: "<your-path>/poseidon-proof.wasm",
// zkeyFilePath: "<your-path>/poseidon-proof.zkey"
// })

// Verify the proof.
const response = await verify(fullProof)

// true.

// 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()


const proof = await generate(1, 2)



console.log(await verify(proof))



Type Aliases


Generated using TypeDoc