This repo demonstrates how to verify Groth16 and Plonk proofs in browser. We wrap the sp1-verifier
crate in wasm bindings, and invoke it from javascript.
verifier
: The rust sp1 verifier crate with wasm bindings.example/dob-program
: A SP1 program to verify date of birth offchain attestation .example/dob-script
: A simple script to generate proofs in a json format.example/wasm_example
: A short javascript example that verifies proofs in wasm.
First, generate the wasm library for the verifier. From the verifier
directory, run
wasm-pack build --target nodejs --dev
Next, run the script to generate DOB-Attestaion_groth16_proof.json
and DOB-Attestaion_plonk_proof.json
. From the example/dob-script
directory, run:
cargo run --release -- --mode groth16
cargo run --release -- --mode plonk
By default, this will not generate fresh proofs from the program in example/dob-program
. To generate fresh proofs, run:
SP1_PROVER=network SP1_PRIVATE_KEY=$SP1_PRIVATE_KEY cargo run --release -- --mode groth16 --prove
SP1_PROVER=network SP1_PRIVATE_KEY=$SP1_PRIVATE_KEY cargo run --release -- --mode plonk --prove
We used SP1 prover network in our example . You can also run it locally using the commands:
cargo run --release -- --mode groth16 --prove
cargo run --release -- --mode plonk --prove
To verify proofs in wasm, run the following command from the example/wasm_verifier
directory:
pnpm install
pnpm run test
- The system employs Succinct ZKVM to validate the attestation's integrity without exposing the actual data.
- The ZKVM re-generates the EIP712 signature by calculating:
- DomainHash
- MessageHash
This confirms the attestation is untampered.
- It checks specific conditions, such as verifying if the individual's date of birth shows they are above 18.
- This proof can be used anywhere where you want to prove that you are 18+ without actually revealing your actual Date of Birth.