Semaphore Protocol
Last updated
Last updated
This example uses TypeScript and the Snarkyjs zk library developed by the O(1) Labs team. You can pull a pre-built dockerfile will all required environment dependencies:
and run it like this:
This will start a bash session in the playground environment. Next cd to the directory containing this example:
Once you are in the example folder called snickerdoodle-semaphore
, you need to install dependencies and build the project:
Now you are ready to experiment.
The Semaphore circuit itself is contained in . This file exports three things:
A Merkle Tree Witness object called MyMerkleWitness
that is configured for an arity of 16 (i.e. 2^16 possible leaves). This will be used to compute the secret membership path belonging to a prover.
A special identity structure that takes an identityNullifier
and an identityTrapdoor
, both of which are random Field elements that must be kept secret. Taking the Poseidon hash of these two quantities and then hashing that value again results in a public identity commitment.
The Semaphore circuit implementation which allows a prover to prove their membership to a group while preventing replays and message tampering.
The verification key can be extracted from the keypair object by calling .verificationKey()
on the keypair. The verification key is one of the inputs needed for proof verification.
If you've already run npm run build
, you can run the example script like this:
The usage of the Semaphore circuit is demonstrated in . First a kaypair object must be created for the circuit by calling .generateKeypair()
on the circuit object. This keypair is used in its entirety to compute a proof.