zk402-facilitator
Facilitator implementation for verifying and settling zk402 payments.
Overview
This crate implements the server-side verification and settlement logic for the zk402 payment scheme. It provides the ZkSettleFacilitator which implements the Scheme trait, handling the five-step verification pipeline and on-chain settlement via Ethereum smart contracts.
Features
- Five-step verification - Structural, trust, cryptographic, freshness, and simulation checks
- On-chain settlement - Direct integration with ZkSettleVerifier smart contract
- Fail-closed design - Any verification failure immediately rejects the payment
- Configurable registry - Pluggable verifying key registry for trust management
- Ethereum integration - Built on ethers-rs for robust chain interaction
Verification Pipeline
The facilitator performs these checks in order:
- Structural match - Public inputs match payment requirements
- Trust check - Circuit ID is in the trusted verifying key registry
- Cryptographic verification - Zero-knowledge proof is valid
- Freshness - Payment is within valid time window
- Simulation (optional) - Dry-run settlement to catch errors early
Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
= "0.1.0"
= "0.1.0"
Example:
use ;
use ;
use Groth16ProofSystem;
// Set up verifying key registry
let mut registry = new;
registry.register;
// Configure settlement
let settlement_config = new.with_private_key;
// Create facilitator
let facilitator = new;
// Verify a payment
let verify_result = facilitator.verify.await?;
if !verify_result.is_valid
// Settle on-chain
let settle_result = facilitator.settle.await?;
if settle_result.success else
Settlement Configuration
The SettlementConfig requires:
- RPC URL - Ethereum JSON-RPC endpoint
- Verifier address - On-chain ZkSettleVerifier contract address
- Private key - (Optional) Facilitator signing key for transactions
let config = new;
Verifying Key Registry
The StaticRegistry loads trusted circuit verifying keys from configuration:
let mut registry = new;
// Register a trusted circuit
registry.register;
// Unknown circuits will be rejected
Future versions may support on-chain registries for decentralized trust.
Error Handling
All verification failures return structured errors:
StructuralMismatch- Public inputs don't match requirementsUnsupportedCircuit- Circuit ID not in registryCryptographicVerificationFailed- Invalid proofExpired- Payment outside valid time windowChainError- On-chain transaction or RPC failure
Security Invariants
The facilitator enforces these guarantees:
- I1: No redirection - Funds always go to
pay_toaddress - I2: No replay - Nonces are consumed on-chain
- I3: Atomicity - Verify and settle are atomic on-chain
- I4: Trusted circuits - Only registered verifying keys accepted
- I5: No custody - Facilitator never holds user funds
Related Crates
zk402-core- Core types and traitszk402-facilitator-http- HTTP/REST API wrapperzk402-groth16- Groth16 proof verificationethers- Ethereum client library
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.