How it works
How it worksThe circuit
payment_policy.circom — 14 public inputs, 7 private inputs, and six constraint families.
The proof is produced by payment_policy.circom — a Circom 2.2.3 circuit on the
bn128 / BN254 curve, with a depth-4 recipient Merkle tree.
Public inputs
Fourteen signals are public, in this exact order. The same ordering is shared by the circuit, the contract, and the serialization codec.
| # | Signal | Meaning | Encoding |
|---|---|---|---|
| 00 | policyCommitment | Poseidon commitment of the private policy | Fr |
| 01 | recipientRoot | Merkle root of the approved recipients | Fr |
| 02 | recipient | The payee, reduced to a field element | Fr |
| 03 | amount | Payment amount, in stroops | i128 → Fr |
| 04 | invoiceHash | Poseidon hash of the invoice preimage | Fr |
| 05 | nullifier | Single-use replay marker | Fr |
| 06 | agentAddress | The paying agent, reduced to a field element | Fr |
| 07 | assetId | The asset (SAC), reduced to a field element | Fr |
| 08 | contractAddress | The verifier contract, reduced to a field element | Fr |
| 09 | prevEpochId | Epoch the prior counters belong to | u64 → Fr |
| 10 | prevSpent | Spend before this action | i128 → Fr |
| 11 | prevActionCount | Action count before this action | u64 → Fr |
| 12 | newSpent | prevSpent + amount | i128 → Fr |
| 13 | newActionCount | prevActionCount + 1 | u64 → Fr |
Private inputs
These never leave the prover:
privateMaxAmount,privateDailyLimit— the policy thresholdspolicySalt— the secret that hides the commitmentpathElements[4],pathIndices[4]— the Merkle proof for the recipientinvoicePreimage— hashed toinvoiceHashnonce— entropy for the nullifier
The six constraint families
- Commitment opening —
Poseidon(privateMaxAmount, privateDailyLimit, recipientRoot, assetId, policySalt) === policyCommitment. - Merkle membership —
Poseidon(recipient)is a leaf underrecipientRoot(depth 4, boolean path indices). - Range checks —
amount <= privateMaxAmountandprevSpent + amount <= privateDailyLimit, each bit-bounded withNum2Bits(64). - State transition —
newSpent === prevSpent + amountandnewActionCount === prevActionCount + 1. - Invoice binding —
Poseidon(invoicePreimage) === invoiceHash. - Nullifier derivation —
Poseidon(agentAddress, policyCommitment, contractAddress, nonce) === nullifier.
Why bit-width bounds matter
Without the Num2Bits(64) guards, a malicious prover could exploit field
wraparound to make amount <= max appear true. Bounding every comparand closes
that hole.