zkp
import "github.com/ShywareLLC/core/protocol/zkp"
The ZK embodiment is the high-assurance optional tier. The preferred non-ZK tier uses a per-poll voter Ed25519 device keypair with Didit device attestation, which provides oracle prevention without ZK overhead and supports document-scoped identity re-derivation. Multi-device recovery requires explicit recovery-service integration; ZK does not reconstruct a lost secret. The current public commitment remains correlatable by an IDV that knows its enrollment record.
What the circuit proves
The NullifierCircuit is a Groth16 circuit over BN254 that proves two statements simultaneously.
person_secret is the private witness — it never leaves the voter's device.
witness (private): person_secret
public: commitment, nullifier, poll_id
constraints:
MiMC(person_secret) == commitment // Didit-attested binding
MiMC(person_secret, poll_id) == nullifier // per-poll dedup key
Current implementation (interim): commitment is a public circuit input, because
on-chain verification checks the Didit commitment signature outside the circuit, which requires
commitment in the transaction. This means Didit (or whoever holds the commitment-signing key)
can correlate commitment → nullifier → participation — a known, documented gap, not an
oversight. didit_commitment_sig is likewise a real transaction field
(tx.BallotCastData.DiditCommitmentSig), not a private witness, today.
Target design (preferred embodiment, pending circuit hardening): move the Ed25519 signature
check into the circuit (requires gnark/std/algebra/emulated for Edwards25519), making
commitment and didit_commitment_sig private witnesses that never appear in the transaction
payload or on-chain in any form — closing the correlation gap above entirely. Only nullifier,
the Groth16 proof bytes, voter_pub_key, voter_sig, ballot_nonce, and choices would travel
on-chain in that design. Not yet implemented — see protocol/zkp/nullifier.go's own doc comment.
Voter enrollment
// On voter device
commitment, err := zkp.ComputeCommitment(personSecret)
// commitment = MiMC(personSecret)
// Send commitment to Didit (via the enclave, acting as its attestation proxy —
// Didit itself has no signing API) for biometric attestation
// Enclave returns Ed25519 sig over SHA-256(commitment) -- note: poll-INDEPENDENT
// as of 2026-10-05 (previously SHA-256(commitment ‖ poll_id)). Minted once, at
// enrollment, and reused for every future poll -- no further contact with
// Didit or the enclave is needed after this. Deliberate tradeoff: this makes a
// stolen person_secret an unlimited-scope credential rather than one bounded
// to polls that already had a signature; the chosen mitigation is a
// device-local passcode/biometric gate plus a panic-wipe control on the
// cached person_secret, not periodic forced re-enrollment.
// Store didit_commitment_sig locally — it travels in the transaction today
// (see "Current implementation" above), and becomes a private circuit
// witness once the target design above is built.
Generating a proof
// On voter device, at vote time
nullifier, err := zkp.ComputeNullifier(personSecret, pollID)
// nullifier = MiMC(personSecret, pollID) -- still per-poll; this is the actual
// Sybil-resistance/dedup mechanism and is unaffected by the commitment
// signature becoming poll-independent above.
// Generate Groth16 proof
// private witness: personSecret
// public inputs: commitment, nullifier, pollID
// proving key loaded from nullifier_pk.bin
The proof, nullifier, commitment, and commitment signature are assembled into
tx.BallotCastData (ZKNullifier, ZKNullifierProof, ZKCommitment, DiditCommitmentSig) --
all four are real transaction fields today, per "Current implementation" above.
Verifying a proof (canonical runtime)
verifier, err := zkp.NewVerifier(vkFile) // load from nullifier_vk.bin
err = verifier.Verify(proofBytes, nullifierHex, commitmentHex, pollID)
verifier.Verify returns nil if the proof is valid, an error otherwise. Called by
services/identity.ZKVerifier.VerifyAndIdentify (which also separately checks the Ed25519
commitment signature against sha256(commitment)) before any ballot state mutation. The
canonical runtime sees commitment today (current implementation); it would not under the
target design above.
Trusted setup
# Development (single-party, NOT production)
go run ./cmd/zk-setup
# → nullifier_pk.bin (proving key)
# → nullifier_vk.bin (verifying key)
Production deployments must perform a Groth16 multi-party computation (MPC) ceremony to generate the proving and verifying keys. Single-party setup allows proof forgery by anyone who knows the toxic waste. Use snarkjs phase2 or the Hermez ceremony infrastructure.
Attested single-party setup (verified, still not a substitute for MPC)
As of 2026-10-06, the reference deployment's current pk/vk were generated by a
single-party run of cmd/zk-setup inside an ephemeral GCP Confidential VM
(n2d-standard-2, AMD SEV-SNP, launched/used/deleted within one session), with a SEV-SNP
hardware attestation report captured over the exact setup binary and output keys
(REPORT_DATA = sha256(zk-setup-binary‖pk‖vk)). This report verifies end-to-end — the
full AMD root→ASK→VCEK→report-signature chain checks out against AMD's real KDS,
confirmed independently via both go-sev-guest's own verifier and a from-scratch manual
signature check. This supersedes an earlier same-day run on OCI whose attestation could
not be verified (narrowed to a likely AMD KDS bug specific to that Genoa/OCI shape, not
resolved — see ShywareLLC/idv-enclave/README.md's "Attestation verification status" for
that diagnostic trail) — GCP is go-sev-guest's home platform, which is the more likely
reason verification succeeded there.
This is still single-party, not MPC — the operator who ran it held the toxic waste for
the run's duration regardless of the attestation verifying. Verified attestation and
multi-party setup are different properties: this run proves the claimed environment was
genuine, not that no single party ever held the full secret. It is the strongest
single-party tier achieved so far, but the ZK nullifier verifier is accordingly still
not wired into live vote-casting. Full artifact set:
ShywareLLC/core/zk-ceremony-2026-10-06-gcp/README.md (use this run's keys, not the
superseded OCI run's). See also threat-model.md T22.
Circuit compilation
cs, err := zkp.Compile()
// cs is the compiled R1CS constraint system over BN254
// used as input to the Groth16 trusted setup
Recovery trade-off
The ZK embodiment is device-bound: person_secret must be present to generate a proof.
If the voter loses their device, re-enrollment requires an out-of-band backup mechanism
(encrypted keychain export, hardware key backup, etc.).
The preferred device-keypair embodiment does not have this limitation — recovery is anchored to biometric re-authentication with the IDV provider on any device, with no secret to remember or backup.