Skip to main content

zkpClient (web)

warning

The ZK tier requires a Groth16 multi-party computation trusted-setup ceremony before production use. The single-party setup produced by go run ./cmd/zk-setup allows proof forgery and is development-only.

Import​

import {
initZKProver,
generatePersonSecret,
encryptPersonSecret,
decryptPersonSecret,
computeCommitment,
computeNullifier,
generateProof,
buildZKBallotEnvelope
} from '@shyware/sdk/protocol/zkp'

What the ZK tier adds​

The default Didit voting path uses an enclave-attested SHA-256(document_key ‖ scoping_id) identity. Device signatures and IDV enrollment remain separate from optional period-close signing.

The ZK tier uses MiMC(person_secret, scoping_id) as the identity hash and proves possession of the enrolled secret. In the current implementation the commitment is a public input and the IDV signature is verified outside the circuit. An IDV that knows the commitment can correlate it with the transaction; commitment blindness is a target design, not a current guarantee.

Both tiers retain device-signature validation. ZK enrollment still requires trustworthy IDV uniqueness enforcement and a production trusted setup.


Prover initialization​

Load the WASM prover and proving key binary. Must be called once before any proof generation.

const prover = await initZKProver(
'/static/shyware_zkp.wasm',
'/static/nullifier_pk.bin'
)

The WASM module signals readiness via globalThis.shywareZKReady = true. initZKProver waits for this signal before resolving.


Person secret lifecycle​

The person_secret is a 32-byte random value generated once per participant and retained for the lifetime of the deployment. It is the root of the ZK identity — losing it permanently severs the ability to prove commitment ownership.

Generate​

const personSecret = generatePersonSecret()
// → 32-byte hex string, e.g. "a3f8..."

Encrypt for biometric recovery​

const encSecret = encryptPersonSecret(personSecret, biometricKey)
// biometricKey: base64-encoded AES-256 key (re-derived by IDV on any device)
// → base64 ciphertext with prepended IV (AES-256-GCM)

Store encSecret in the receipt store alongside the commitment. The example requires a separately provided biometricKey; the SDK does not derive it from Didit automatically. Deploy and test the recovery service before promising multi-device secret recovery.

Decrypt (recovery)​

const recovered = decryptPersonSecret(encSecretBase64, biometricKey)
// → personSecret hex string

Recovery path: participant re-verifies with the IDV provider on any device → IDV re-derives biometricKey → decryptPersonSecret → participant re-derives nullifier for any poll.


Commitment and nullifier (without proof)​

Use these when you need the commitment or nullifier value but do not need a proof — for example, during enrollment or receipt verification.

const commitment = computeCommitment(personSecret)
// → MiMC(personSecret) hex — Didit attests this value

const nullifier = computeNullifier(personSecret, submissionId)
// → MiMC(personSecret, submissionId) hex — on-chain identity hash for this scoping period

Proof generation​

const { proofBytes, commitmentHex, nullifierHex } = await prover.generateProof(personSecret, submissionId)
// proofBytes: base64-encoded Groth16 proof
// The circuit proves:
// MiMC(personSecret) == commitmentHex (Didit binding)
// MiMC(personSecret, scopingId) == nullifierHex (per-period dedup)

Proof generation time: ~3–15 seconds in WASM depending on device. Generate proofs before the user reaches the submission screen to avoid perceived latency.


Full ballot envelope​

const envelope = await buildZKBallotEnvelope({
scopingId: 'proposal-42',
choices: ['yes'],
personSecret,
diditCommitmentSigBase64: diditSig, // Didit's Ed25519 sig over SHA-256(commitment) -- poll-independent as of 2026-10-05 (was SHA-256(commitment ‖ scopingId)); minted once at enrollment, reused for every future poll
encSecret, // pass-through for receipt store
timestamp: Math.floor(Date.now() / 1000)
})
// → {
// txJson, // TxTypeBallotCast payload — submit to /ballots
// submissionId, // H(submissionNonce) — direction-free public identifier
// submissionNonce, // random 32-byte hex — private receipt; do not expose
// nullifier, // MiMC(personSecret, scopingId)
// encSecret // pass-through
// }

What goes on-chain​

{
"type": 2,
"data": {
"scoping_id": "...",
"zk_nullifier": "...",
"zk_nullifier_proof": "...",
"choices": ["yes"],
"submission_nonce": "...",
"voter_pub_key": "...",
"voter_sig": "...",
"timestamp": 1700040000
}
}

Current disclosure boundary​

  • commitment — public circuit input and transaction field
  • didit_commitment_sig — transaction field, checked outside the circuit
  • person_secret — private witness; any encrypted recovery copy requires explicit integration
note

commitment and didit_commitment_sig are currently included in the transaction payload as interim fields pending Ed25519 circuit hardening. Once the circuit includes a constraint verifying the Didit signature over the commitment, both fields will become private witnesses and must be removed from the payload. See the TODO in protocol/zkp/nullifier.go.


Trusted setup​

Development (single-party — not for production)​

cd shyware
go run ./cmd/zk-setup
# → nullifier_pk.bin (proving key)
# → nullifier_vk.bin (verifying key)

Verified attested single-party setup (strongest tier so far, still not MPC)​

As of 2026-10-06, the reference deployment's pk/vk were generated by a single-party run of cmd/zk-setup inside an ephemeral GCP Confidential VM (AMD SEV-SNP, launched/used/deleted within one session), with a hardware attestation report captured over the exact binary and output keys. This report verifies end-to-end against AMD's real certificate chain — confirmed via both go-sev-guest's own verifier and an independent manual signature check, not just captured and assumed. An earlier same-day run on OCI could not be verified (narrowed to a likely AMD KDS-side issue specific to that Genoa/OCI shape, not resolved — see ShywareLLC/idv-enclave/README.md's "Attestation verification status"); this GCP run supersedes it. Still single-party, not MPC — the operator held the toxic waste for the run's duration regardless of verification succeeding — so the ZK verifier remains un-wired from live vote-casting. Details: ShywareLLC/core/zk-ceremony-2026-10-06-gcp/README.md (use these keys, not the superseded OCI run's); threat entry: threat-model.md T22.

Production (MPC ceremony required)​

Production deployments require a Groth16 multi-party computation ceremony (e.g., snarkjs phase2 or Hermez infrastructure). The single-party toxic waste from cmd/zk-setup allows any holder to forge valid proofs. It must never be used in a live deployment.

After the ceremony:

  1. Replace nullifier_pk.bin and nullifier_vk.bin with ceremony outputs
  2. Restart the ABCI node with the new verifying key: state.SetZKVerifier(zkp.NewVerifier(vkFile))
  3. Publish the verifying key publicly — any party can verify proofs independently

Circuit​

The Groth16 circuit (BN254 / EIP-197) over two constraints:

Current implementation (interim — commitment is a public input, see the note above):

private witness: person_secret
public inputs: scoping_id, nullifier, commitment

constraint 1: MiMC(person_secret) == commitment
constraint 2: MiMC(person_secret, scoping_id) == nullifier

Target design (pending Ed25519 circuit hardening):

private witnesses: person_secret, commitment, didit_commitment_sig
public inputs: scoping_id, nullifier

constraint 1: MiMC(person_secret) == commitment
constraint 2: MiMC(person_secret, scoping_id) == nullifier
constraint 3: Ed25519.Verify(diditPubKey, SHA-256(commitment), didit_commitment_sig) == true

Compiled in Go with gnark (BN254). See protocol/zkp/nullifier.go for circuit definition and Compile(), NewProver(), NewVerifier().