Policy System
The policy system lets you attach enforceable on-chain conditions to commitments. Policies are checked during reveal — if the policy's validate() function returns false, the reveal is rejected.
How policies work
- Commit with policy — When committing, specify a policy contract address and parameters hash
- Policy is bound — The
policyIdandpolicyParamsHashare included in the Poseidon commitment hash and verified inside the ZK circuit. You cannot change the policy after commit. - Reveal checks policy — During reveal, the vault calls
policy.validate()viastaticcallwith a 100K gas cap - Policy validates — The policy contract checks conditions (time, destination, witnesses, etc.) and returns
trueorfalse
Built-in policies
| Policy | Address | Description |
|---|---|---|
| TimelockExpiry | 0xae2307...39d6 | Reveals only allowed after/before certain timestamps |
| DestinationRestriction | 0x899E9f...9A3ee00 | Reveals restricted to specific recipient addresses |
| ThresholdWitness | 0xa89638...fEBD7 | Requires M-of-N witness signatures to reveal |
Policy validation call
The vault calls:
(bool valid) = policy.staticcall{gas: 100_000}(
abi.encodeCall(IRevealPolicy.validate, (
commitment, nullifier, recipient, amount, token, policyParams
))
);
Key properties:
- Read-only —
staticcallprevents state changes - Gas-limited — 100K gas cap prevents griefing
- ABI-encoded params —
policyParamscarries arbitrary encoded data
Example: commit with a timelock
const timeLockPolicy = '0xae2307620840916a06A862A61BF2101d694539d6';
const unlockTime = Math.floor(Date.now() / 1000) + 3600; // 1 hour from now
const policyParams = ethers.AbiCoder.defaultAbiCoder().encode(
['uint256', 'uint256'],
[unlockTime, 0] // [notBefore, notAfter]
);
const policyParamsHash = poseidon([...policyParamsFields]);
const tx = await vault.commitNativeWithPolicy(
commitment,
ethers.ZeroHash,
timeLockPolicy,
policyParamsHash,
{ value: amount, gasPrice: 1_000_000_000n }
);
Next steps
- IRevealPolicy Interface — implement your own policy
- Custom Policies — tutorial for writing a custom policy