Tool hosts shouldn't have to see the refund amount to know it's ≤ $50 and a valid currency.
FormProof is a Rust library that compiles a frozen JSON Schema subset into a Groth16 (BN254) circuit. An MCP/tool host can verify that private JSON data satisfies schema constraints—required keys present, enums in set, integers in range, string lengths bounded—without learning the actual field values.
A compiler + prover/verifier pipeline:
- Schema → Define constraints (max amounts, valid enums, required fields)
- Compile → Generate Groth16 proving/verifying keys for that schema
- Prove → Prover creates a proof from private JSON data
- Verify → Verifier checks proof against public commitment (never sees values)
use formproof::{FormProofSchema, CompiledSchema, Witness, Proof, verify};
// Schema: refund amount ≤50, valid currency
let schema = FormProofSchema::from_json(r#"{
"type": "object",
"properties": {
"amount": { "type": "integer", "minimum": 0, "maximum": 50 },
"currency": { "enum": ["USD", "EUR", "GBP"] }
},
"required": ["amount", "currency"]
}"#).unwrap();
// Compile schema to circuit
let compiled = CompiledSchema::compile(schema).unwrap();
// Prover: create witness with actual values (PRIVATE)
let mut witness = Witness::new();
witness.set_u64("amount", 25); // Actual amount - verifier never sees this
witness.set_enum("currency", "USD");
// Generate proof
let proof = Proof::create(&compiled, &witness).unwrap();
// Verifier: only sees commitment hash, proves amount ≤50 + valid currency
assert!(verify(&compiled, &proof).unwrap());Add to your Cargo.toml:
[dependencies]
formproof = { git = "https://github.com/kritarth1107/FormProof" }Or clone and build:
git clone https://github.com/kritarth1107/FormProof
cd FormProof
cargo build --release# Show schema constraints and fingerprint
formproof info --schema schemas/refund.json
# Compile schema to proving/verifying keys
formproof compile --schema schemas/refund.json --output ./keys
# Generate proof from private witness
formproof prove --schema schemas/refund.json --proving-key keys/proving_key.bin \
--witness witness.json --output proof.bin
# Verify proof (only needs commitment, never sees actual values)
formproof verify --schema schemas/refund.json --verifying-key keys/verifying_key.bin \
--proof proof.bin --commitment <hex-commitment>For easier transport, bundle proof + commitment + schema fingerprint into a single JSON file:
# Build a portable proof package
formproof package-build --schema schemas/refund.json \
--proving-key keys/proving_key.bin \
--witness witness.json --output proof_package.json
# Verify a package (checks fingerprint + proof)
formproof package-verify --schema schemas/refund.json \
--verifying-key keys/verifying_key.bin \
--package proof_package.jsonSee docs/PROOF_PACKAGE.md for format details.
Ready-made policies live in schemas/ (refund, age_gate, access_country, spend_cap, session_ttl, rate_limit, tool_allowlist, quota_budget, model_route, data_residency, purpose_bind, human_gate).
refund.json (schema):
{
"type": "object",
"properties": {
"amount": { "type": "integer", "minimum": 0, "maximum": 50 },
"currency": { "enum": ["USD", "EUR", "GBP"] }
},
"required": ["amount", "currency"]
}witness.json (private data):
{
"amount": 25,
"currency": "USD"
}This is an early version with intentionally limited scope.
- docs/SCHEMA_V0.md — Complete frozen schema specification
- docs/THREAT_MODEL.md — Security model and trust assumptions
- docs/HOST_INTEGRATION.md — MCP/tool host verify-only integration
- docs/DATA_RESIDENCY.md — Data residency / retention policy guide
- docs/PURPOSE_BIND.md — Purpose limitation / legal basis policy guide
- docs/HUMAN_GATE.md — Human-in-the-loop approval policy guide
- docs/WASM.md — WebAssembly verification path and caveats
- docs/RELEASE.md — Release preparation checklist
- docs/V0_1_0.md — v0.1.0 release notes
- SECURITY.md — Supported versions and vulnerability reporting
- Objects with ≤8 properties
- Types:
integer(u64) with optionalminimum/maximumenumwith ≤8 string variantsstringwithmaxLength≤64bytes32(32-byte hex strings, viaformat: "bytes32")
requiredfield validation- Payload hashes to public commitment
- ❌ Arbitrary JSON Schema (only the subset above)
- ❌ Regex patterns
- ❌ Nested objects or arrays
- ❌ Recursive schemas
- ❌ zkML or machine learning integration
- ❌ Hiding the schema/policy (schema is public; only payload is private)
- ❌ Large schemas (>8 properties)
- Schema Parsing: JSON Schema subset → internal constraint representation
- Circuit Compilation: Constraints → R1CS circuit → Groth16 keys (BN254 curve)
- Witness Commitment: Private data → SHA256 hash (public commitment)
- Proving: Witness + proving key → zkSNARK proof
- Verification: Proof + commitment + verifying key → accept/reject
The verifier learns nothing about the actual values—only that they satisfy the schema constraints.
MCP tool hosts often need to validate that agent requests meet policies without seeing sensitive data:
- Refunds: Verify amount ≤ $50 without seeing the exact amount
- Access control: Verify user is in allowed country list without revealing location
- Age verification: Prove age ≥ 18 without revealing exact age
- Data residency: Prove placement/retention policy without revealing the exact region tuple
This complements (does not replace) OAuth and standard authorization. OAuth proves who is making a request; FormProof proves the request content satisfies constraints.
formproof/ # Core library
├── src/
│ ├── schema.rs # JSON Schema subset parser
│ ├── circuit.rs # R1CS circuit generation
│ ├── prove.rs # Groth16 proving
│ ├── verify.rs # Groth16 verification
│ ├── package.rs # Portable proof packages
│ └── lib.rs # Public API
├── benches/
│ └── proof_bench.rs # Criterion benchmarks
├── examples/
│ ├── mcp_tool_host.rs # MCP integration example
│ ├── verify_only.rs # Host-side verify-only workflow
│ ├── spend_cap_demo.rs # Spend cap policy demonstration
│ ├── session_ttl_demo.rs # Session TTL policy demonstration
│ ├── quota_budget_demo.rs # Quota/budget policy demonstration
│ ├── model_route_demo.rs # Model routing policy demonstration
│ ├── proof_package_demo.rs # Proof package workflow
│ ├── rate_limit_demo.rs # Rate limit policy demonstration
│ ├── tool_allowlist_demo.rs # Tool allowlist policy demonstration
│ ├── age_gate_demo.rs # Age gate policy demonstration
│ ├── data_residency_demo.rs # Data residency policy demonstration
│ ├── purpose_bind_demo.rs # Purpose limitation policy demonstration
│ └── human_gate_demo.rs # Human-in-the-loop approval demonstration
└── tests/
└── golden.rs # Golden proofs + rejection corpus
formproof-cli/ # CLI binary (compile, prove, verify, package-build, package-verify)
└── src/main.rs
schemas/ # Reusable v0 policy fixtures
├── refund.json
├── age_gate.json
├── access_country.json
├── spend_cap.json
├── session_ttl.json
├── rate_limit.json # MCP rate-limit policy
├── tool_allowlist.json # MCP tool access policy
├── quota_budget.json # MCP quota/budget policy
├── model_route.json # MCP model-routing policy
├── data_residency.json # MCP data-residency policy
├── purpose_bind.json # MCP purpose-limitation policy
└── human_gate.json # MCP human-in-the-loop approval policy
docs/
├── SCHEMA_V0.md # Frozen schema specification
├── THREAT_MODEL.md # Security model and trust assumptions
├── HOST_INTEGRATION.md # Host verify-only integration
├── DATA_RESIDENCY.md # Data residency / retention policy
├── PURPOSE_BIND.md # Purpose limitation / legal basis policy
├── HUMAN_GATE.md # Human-in-the-loop approval policy
├── PROOF_PACKAGE.md # Portable proof package format
├── WASM.md # WebAssembly verification notes
├── RELEASE.md # Release preparation checklist
└── V0_1_0.md # v0.1.0 release notes
# Run all tests
cargo test
# Run golden proof tests specifically
cargo test --test golden
# Run property tests
cargo test --test proptest_schema
# Run fuzz-like tests
cargo test --test fuzz_schema
# Run CLI end-to-end tests (requires release build)
cargo build --release -p formproof-cli
cargo test --release -p formproof-cli --test cli_e2e
# Run with output
cargo test -- --nocaptureTests include:
- 3 golden proofs that verify
- Rejection corpus: wrong enum, out of range, missing required, invalid values
- Edge cases: boundary values, optional fields, bytes32
- Property tests: random valid/invalid schemas, witness/circuit satisfaction
- Fuzz tests: arbitrary JSON input, malformed schemas, edge cases
- CLI e2e tests: all CLI commands against real schemas (info, compile, prove, verify, package-build, package-verify)
See docs/FUZZING.md for property testing and fuzzing details.
Criterion benchmarks cover prove/verify for all 13 policy schemas. Sample timings on golden schemas (release build):
| Schema | Prove Time | Verify Time |
|---|---|---|
| Refund (2 props: amount, currency) | 2.35 ms | 1.13 ms |
| User (3 props: age, country, name) | 2.28 ms | 1.15 ms |
| Token (2 props: token_id, balance) | 5.82 ms | 1.14 ms |
Additional benches: rate_limit, session_ttl, age_gate, tool_allowlist, quota_budget, model_route, data_residency, purpose_bind, human_gate.
Run benchmarks yourself:
cargo bench --bench proof_bench- Circuit compilation (key generation) is slow (~seconds for small schemas)
- Proving time scales with schema complexity
- Verification is fast (constant time)
- For CI, tests use small circuits to keep runtime reasonable
MIT License - see LICENSE
GitHub Actions runs on every PR:
- Format:
cargo fmt --check - Clippy:
cargo clippy --all-targets -- -D warnings - Test:
cargo test - Docs:
cargo doc --no-deps -p formproofwith-D warnings - Build: Release build and CLI check
- CLI e2e: End-to-end tests for all CLI commands
- Examples smoke: Run all example programs
See CONTRIBUTING.md for detailed guidelines.
Quick checklist:
- Keep changes within v0 scope
- Add tests for new functionality
- Run
cargo fmtandcargo clippybefore submitting - No AI co-author trailers in commits