Skip to content

Prove a rule (Groth16 predicates)

View Markdown

Use this when the verifier needs an answer, not the data: “over 21”, “income at least 50,000”, “credit score at least 650”, “resident of an approved country”.

The holder runs a small circuit on their own device. It checks that the data came from a trusted issuer, then checks the rule, and outputs a Groth16 proof. The verifier, an app or a Cardano validator, checks the proof against the issuer’s key and its own policy values. It learns that the rule holds, and nothing else.

Groth16 · step 1 / 3
Issuersigns once
issuer key (pkU, pkV)PUBLIC0x7ba4…a163
EdDSA-Jubjub signature overPoseidon(dobYear, country, roleId, salaryBracket, nameHash)
Holderidentity hidden
dobYearSECRETHIDDEN1995████████
countrySECRETHIDDEN840 · USA████████
roleIdSECRETHIDDEN2001 · engineer████████
salaryBracket, nameHash, signatureSECRETHIDDEN5 · 0x9bc2…0277 · σ████████
π for the adult-resident gateno valid proof for senior doctor
Gatesspending validators
Adult residentborn 2005 or earlier, and country on the approved list
seesPUBLICissuer key · 2026 · countryRoot · eligible = 1
born 1995, USA is approvedunlocked
Senior doctorrole is doctor (1001), born 1996 or earlier
seesPUBLICissuer key · 2026 · eligible = 1
role is engineer, not doctorstays locked

Approved: USA, UK, Germany, France, Japan, committed as a Merkle root.

1. Issue

The issuer signs a Poseidon hash of all five fields with EdDSA-Jubjub, once. Pick Alice, Bob or Charlie to load their credential.

2. Prove

For each gate, the holder runs that gate's circuit on their own device. It recomputes the hash, checks the issuer's signature and checks the gate's rule. When the rule is false, no valid proof exists.

3. Unlock

Each gate is a spending validator with the issuer key and the current year pinned as script parameters. It verifies the proof and releases the funds. Switch to Gate's view: the gate never learns the birth year, country, role or salary.

SECRET stays with the holderPUBLIC what the gate seesHash values are illustrative.
PartyLearns
IssuerThe data, once, at issuance
HolderTheir own data
VerifierThe rule’s answer, plus the public policy values it chose (the threshold, the current year)
Everyone elseThe same as the verifier, if the proof goes on-chain

The issuer signs a Poseidon hash of all the fields with EdDSA on Jubjub. The circuit recomputes the hash, checks the signature against the issuer’s public key, then applies the rule. This one, from the selective-disclosure demo, answers “a doctor, born at least 30 years before currentYear?” in its public eligible output and reveals nothing else. The verifier must require eligible = 1; a proof with eligible = 0 is a valid proof of “no”.

SeniorDoctorProof.java
import org.zeroj.circuit.annotation.*;
import org.zeroj.circuit.lib.poseidon.PoseidonParams;
import org.zeroj.circuit.lib.poseidon.PoseidonParamsBLS12_381T3;
import org.zeroj.circuit.lib.zk.ZkEdDSAJubjub;
import org.zeroj.circuit.lib.zk.ZkPoseidonN;
@ZKCircuit(name = "senior-doctor", version = 1)
public class SeniorDoctorProof {
private static final PoseidonParams POSEIDON = PoseidonParamsBLS12_381T3.INSTANCE;
private static final int MIN_AGE = 30;
private static final long DOCTOR_ROLE_ID = 1001L;
@Prove
ZkBool prove(ZkContext zk,
@Public ZkField pkU,
@Public ZkField pkV,
@Public @UInt(bits = 16) ZkUInt currentYear,
@Public ZkBool eligible,
@Secret @UInt(bits = 16) ZkUInt dobYear,
@Secret @UInt(bits = 16) ZkUInt country,
@Secret ZkField roleId,
@Secret @UInt(bits = 8) ZkUInt salaryBracket,
@Secret ZkField nameHash,
@Secret ZkField sigRU,
@Secret ZkField sigRV,
@Secret @UInt(bits = 252) ZkUInt sigS,
@Secret @UInt(bits = 252) ZkUInt kModL,
@Secret @UInt(bits = 4) ZkUInt kQuotient) {
// Every predicate recomputes the same signed message over all five fields
var claims = ZkPoseidonN.hash(zk, POSEIDON, dobYear.asField(), country.asField(),
roleId, salaryBracket.asField(), nameHash);
ZkEdDSAJubjub.verifyWithRegisteredKey(zk, pkU, pkV, claims, sigRU, sigRV, sigS, kModL, kQuotient);
// The predicate: role == doctor AND born no later than currentYear - 30
var maxDobYear = ZkUInt.wrap(zk, currentYear.asField().sub(zk.constant(MIN_AGE)).signal(), 16);
var roleOk = roleId.isEqual(zk.constant(DOCTOR_ROLE_ID));
return roleOk.and(eligible.isEqual(dobYear.lte(maxDobYear)));
}
}

This is the pattern of the age and KYC and selective disclosure demos. The tutorial Prove you’re over 18 builds one step by step, including setup, proving and verification.

Instead of a signature, an issuer can publish a Pedersen vector commitment to a whole profile: income, score, birth year and country in one 32-byte point. The holder gets the opening. A proof can then check a rule over any of the fields while all of them stay sealed:

CreditProfileCheck.java (core)
import org.zeroj.circuit.lib.zk.ZkPedersenVector;
// SCHEMA: income/64, credit_score/16, birth_year/16, country/16 bits
var binding = ZkPedersenVector.bindSchema(zk, SCHEMA, schemaDigest); // schemaDigest is @Public
ZkPedersenVector.commit(zk, binding, List.of(income, creditScore, birthYear, country), blinding)
.assertAffineEquals(zk, u, v); // (u, v) is the public commitment
income.gte(minIncome).assertTrue();
creditScore.gte(minScore).assertTrue();

The pedersen-commitments demo uses this as a credit gate: a bureau commits to Alice’s profile (income 85,000, score 720), and she proves “income ≥ 50,000 and score ≥ 650” to a lender, who mints her a badge on-chain. If Mallory copies Alice’s commitment and proof, the validator refuses, because the bureau’s issuance record names Alice, and Alice has to sign.

Two rules come with vector commitments: bind the public schema digest in every proof, and accept a commitment only with an authenticated issuance record. See Pedersen commitments.

Signed credentialCommitted credential
Issuer publishesA signature, held by the holderA commitment, often on-chain
Unlinkable across verifiersYes, if the proof hides the signatureNo: the same commitment is reused
Circuit sizeSignature check plus the ruleAbout 3,000 constraints for the credit gate
MaturityBetaExperimental
  • Age-restricted services. “Over 18” for a game, “over 21” for a venue. (use case)
  • Lending. “Income at least 50,000 and score at least 650” without a payslip or a credit report.
  • Professional access. “A doctor, licensed for 10 years or more”, from a medical board’s credential.
  • Allowlists. “My key is in this approved set”, with a Merkle proof. (tutorial)
  • The verifier must see the value itself. Use Reveal the value.
  • The value has to stay on-chain and be added up. Use Hide a number.
  • You can’t run a trusted setup per circuit. Every new rule is a new circuit; consider BBS if revealing is acceptable.
  • Pin the policy values. The verifier, not the prover, chooses the threshold and the current year. On Cardano, make them script parameters.
  • Replay. These proofs carry no nonce. Bind them to the UTxO being spent or to a session.
  • Trusted setup. Production keys come from a multi-party ceremony. See Trusted setup, explained.