zkcg-common 0.1.1

Shared types, errors, and utilities for the ZKCG protocol
Documentation

ZKCG Verifier

crates.io crates.io License: Apache-2.0 Sponsor


ZK-Verified Computation Gateway (ZKCG)

ZKCG enables non-ZK systems to replace trusted oracle logic with verifiable off-chain computation.
Instead of relying on a trusted backend or oracle signer, consumers (on-chain contracts or off-chain services) can accept results only if a zero-knowledge proof of correct computation and policy compliance is provided.

ZKCG is a protocol-first verification primitive β€” not a chain, not a zk-rollup, and not a signature oracle.
It is designed for systems that want trustless decision gating using provable off-chain logic.

Learn more below πŸ‘‡

Motivation

In many systems today (DeFi risk checks, compliance gating, permissioned access), off-chain computation results are submitted on-chain or to services using trusted oracles or signed responses. This creates a trust assumption:

  • Contracts must trust an oracle identity
  • Backends must be trusted not to lie
  • Private data often must be revealed for validation

ZKCG replaces this with verifiable computation β€” results accepted only if a zero-knowledge proof of correct execution plus policy compliance is provided.
This eliminates the need for trust in a specific oracle signer and enables stronger guarantees for privacy and correctness.

What ZKCG Replaces

Many systems today rely on trusted oracle services or backend signers to bring off-chain computation results on-chain or into critical decision paths.

ZKCG replaces trust in the computation provider with verifiable computation.

Today (Common Pattern) With ZKCG
Trusted oracle signer Zero-knowledge proof
Off-chain trust Cryptographic verification
Backend promises Enforced protocol policy
Revealed inputs Private inputs (ZK)
Ad-hoc validation Deterministic state transitions

Instead of trusting who produced a result, consumers verify how it was produced.

Overview

ZKCG Verifier is the public, auditable verification layer of the ZKCG protocol.

  • Phase 1: Halo2-based zk-SNARK verification
  • Phase 2: zkVM-based verification (RISC0)

This repository is intentionally verifier-only. Anyone can independently verify proofs, audit the logic, and run verifier nodes.


High-Level Architecture

Modern systems often rely on oracles or trusted services to bring off-chain results on-chain or into backend logic. ZKCG replaces those with verifiable proofs.

Here’s how a typical integration looks:

Off-chain computation
        ↓
   ZK proof generation
        ↓
   ZKCG Verifier
 (policy + proof check)
        ↓
Verified result consumed
(smart contract or service)
  • The prover executes private logic off-chain and outputs a proof + public result.
  • The verifier checks both correct computation and policy compliance.
  • No trusted signer or back-end oracle identity is required.

Example Integration: Oracle Replacement

Instead of:

// Trusted oracle pattern
require(msg.sender == trustedOracle);
price = oraclePrice;

You can do:

// Verifiable off-chain computation
require(verifyZKCG(proof, publicInputs));
price = publicInputs.price;

With ZKCG, the contract accepts the result only if a proof of correct computation and policy compliance is provided β€” no need to trust a specific oracle address.


Who Should Use ZKCG

ZKCG is built for systems that currently rely on externally computed results where:

  • Trusting a specific oracle signer is undesirable
  • Privacy of inputs must be preserved
  • Proof of correct logic matters
  • Existing systems already rely on oracles or trusted backends

Typical adopters include:

  • On-chain protocols replacing oracle signatures
  • Off-chain services needing strong correctness guarantees
  • Compliance and eligibility systems
  • Risk-based access gating

Use Case (Phase 1): Private Eligibility Check

A common pattern across many systems is:

β€œCan this user or entity execute some action only if their private data satisfies a condition?”

Examples include:

  • Credit score β‰₯ threshold
  • Age β‰₯ 18
  • Compliance metric below risk limit
  • Private reputation above requirement

ZKCG enables these decisions to be verified without revealing private inputs and without trusting an oracle signer.


Repository Structure

ZKCG/
β”œβ”€β”€ common/         # Shared types, errors, and protocol utilities (zkcg-common crate)
β”œβ”€β”€ verifier/       # Core verifier logic (zkcg-verifier crate)
β”œβ”€β”€ api/            # HTTP API for proof submission
β”œβ”€β”€ SPEC.md         # Full protocol specification
β”œβ”€β”€ CORE_FREEZE.md  # Frozen circuit parameters and commitments
β”œβ”€β”€ SECURITY.md     # Security assumptions and reporting
β”œβ”€β”€ LICENSE         # Apache-2.0
└── README.md       # This file

Installation

Add the crates to your project:

cargo add zkcg-verifier zkcg-common

Or manually in Cargo.toml:

[dependencies]

zkcg-verifier = "0.1.0"

zkcg-common   = "0.1.0"


Features

  • zk-halo2 β€” Enable Halo2 proof verification backend
  • zk-vm β€” Enable zkVM (RISC0) verification support

Example:

zkcg-verifier = { version = "0.1.0", features = ["zk-halo2"] }


🐳 Docker Setup (Optional)

Docker is optional.

  • Halo2 verification runs natively
  • zkVM verification can run natively or in Docker
  • Docker is recommended for reproducible environments and CI

Install Docker (Ubuntu / WSL2)

sudo apt update

sudo apt install docker.io -y

sudo usermod -aG docker $USER

newgrp docker

Verify:

docker --version


Build Docker Image

From the repository root:

docker build -t zkcg-verifier .

πŸ“Š Benchmarks

Environment

  • Platform: Windows (WSL2, Ubuntu)
  • CPU: Intel i5 (10th Gen)
  • RAM: 16 GB
  • Build: Release
  • Parallelism: Default (no tuning)

Halo2 (BN254, k = 6)

Use case: Interactive / near-real-time ZK policy verification

  • Prove: ~306–316 ms(before) -> ~75–80 ms(now)
  • Verify: ~9–10 ms(before) -> ~4–4.5 ms(now)
  • End-to-End: ~317–351 ms(before) -> 90-100ms(now)

zkVM (RISC0)

Use case: Audit-grade execution proofs

  • Prove: ~13.7 seconds
  • Verify: ~41–42 ns

Summary

Backend Prove Time Verify Time Intended Use
Halo2 ~ 92.665 ms ~4.3099 ms Interactive ZK policies
zkVM ~13–17 s ~40 ns Audit / attestation

End-to-End Simulation Results

Sequential Halo2 Simulation (1000 proofs)

Loans evaluated: 1000
Approvals: 128 (12.8%)

Prove total:   ~482.1 s
Verify total:  ~7.7 s
Throughput:    ~2.0 TPS

Parallel Halo2 Simulation (8 threads)

Loans evaluated: 1000
CPU threads: 8

Approvals: 130 (13.0%)

Prove total:   ~127.4 s
Verify total:  ~5.5 s
Throughput:    ~7.5 TPS

Summary

Backend Prove Cost Verify Cost Throughput Intended Use
Halo2 (seq) ~480 ms ~7 ms ~2 TPS Interactive ZK policies
Halo2 (8-core) ~127 ms ~5 ms ~7.5 TPS Batch / off-chain proving
zkVM ~13–17 s ~40 ns Prove-bound Audit & attestation

Real-World Integration Example

ZKCG can be integrated into DeFi protocols for privacy-preserving verifications (e.g., credit score checks without revealing scores). See this demo in the collateral_vault repository, which shows the full on-chain + off-chain pipeline:

  • Off-Chain Proof Generation: Generate a ZK proof using ZKCG's prover (Halo2 or zkVM) for conditions like "credit score > threshold".
  • Off-Chain Verification: Call ZKCG's API (/v1/submit-proof) to verify the proof trustlessly.
  • On-Chain Settlement: If verified, anchor the new state commitment on-chain (Solana program in collateral_vault) to approve loans or unlock collateral.

Run the demo: ts-node collateral_demo.ts (requires ZKCG API running locally).

This pipeline ensures fast off-chain processing (~340ms E2E for Halo2) with on-chain immutability.

Live Demo API (Stateless)

The ZKCG verifier exposes demo-only, stateless endpoints that allow anyone to try proof generation and verification without running the stack locally.

⚠️ These endpoints are for testing and demonstration only.
They do not persist protocol state and are rate-limited.

Base URL

https://zkcg-production.up.railway.app

1️⃣ Generate a Proof (/demo/prove)

Generate a zero-knowledge proof that a score satisfies a given threshold.

Request

curl -X POST https://zkcg-production.up.railway.app/demo/prove \

  -H "Content-Type: application/json" \

  -d '{
    "score": 90,
    "threshold": 100
  }'

Response

{
  "proof": "<PROOF>",
  "proof_size_bytes": 64,
  "note": "Demo-only stateless proof"
}
  • proof is a base64-encoded ZK proof
  • proof_size_bytes shows the compact proof size
  • The proof is not stored server-side

2️⃣ Verify a Proof (/demo/verify)

Verify a previously generated proof against a threshold.

Request

curl -X POST https://zkcg-production.up.railway.app/demo/verify \

  -H "Content-Type: application/json" \

  -d '{
    "proof": "<YOUR_PROOF>",
    "threshold": 100
  }'

Response

{
  "verified": true
}

Proof-Based Compliance Evaluation API (For Sponsers Only)

This endpoint exposes a deterministic, proof-backed compliance oracle.
It evaluates a predefined policy over supplied inputs and returns:

  • The policy decision
  • The reasons for failure (if any)
  • A cryptographic proof that the policy was evaluated correctly

⚠️ Important
This service does not source data, perform KYC, or assess fraud.
It proves correct execution of policy logic over caller-supplied claims.


Endpoint

POST /v1/compliance/evaluate
Content-Type: application/json

Request Schema

{
  "applicant_id": "string",
  "risk_score": "number (0–100)",
  "threshold": "number (0–100)",
  "monthly_income_cents": "number (> 0)",
  "monthly_debt_cents": "number (>= 0)",
  "requested_credit_cents": "number (>= 0)"
}

Field Semantics

Field Description
applicant_id Caller-defined identifier for the subject being evaluated
risk_score Precomputed risk score supplied by the caller
threshold Maximum acceptable risk score
monthly_income_cents Claimed monthly income (in cents)
monthly_debt_cents Claimed monthly debt obligations (in cents)
requested_credit_cents Credit amount being evaluated (in cents)

All numeric values are treated as claims and are not independently verified.


Deterministic Policy Rules

The following rules are evaluated:

  1. Risk Score Policy

    risk_score ≀ threshold
    
  2. Debt-to-Income (DTI) Policy

    (monthly_debt / monthly_income) ≀ 45%
    
  3. Credit-to-Income Policy

    (requested_credit / monthly_income) ≀ 300%
    

All calculations use fixed-point basis points (bps) for deterministic execution.


Example Request

curl -sS -X POST http://127.0.0.1:8080/v1/compliance/evaluate \

  -H 'content-type: application/json' \

  -d '{
    "applicant_id":"cust_001",
    "risk_score":35,
    "threshold":50,
    "monthly_income_cents":500000,
    "monthly_debt_cents":150000,
    "requested_credit_cents":1000000
  }'


Example Response

{
  "application_id": "cust_001-35",
  "decision": "approved",
  "policy_passed": true,
  "risk_band": "medium",
  "reasons": [],
  "proof_verified": true,
  "proof": "<PROOF>"
}

Proof Semantics (Oracle Replacement)

The returned proof attests that:

The declared policy rules were evaluated correctly over the supplied inputs and resulted in the reported outcome.

The proof guarantees:

  • Deterministic policy execution
  • Correct rule evaluation
  • No reliance on trusted oracles

The proof does not guarantee:

  • Correctness of inputs
  • Identity validity
  • Data freshness
  • Absence of fraud

These are intentionally out of scope.


Notes

  • Demo endpoints are stateless
  • No protocol state is mutated
  • Intended for:
    • quick testing
    • integration experiments
    • understanding the proof flow
  • Production / protocol endpoints are gated separately

What This Demonstrates

  • End-to-end proof generation
  • Compact proof size
  • Deterministic verification
  • Clean HTTP boundary for ZK systems

Contact

For questions, collaborations, or sponsorships, reach out:

  • X (Twitter): @sujyot
  • GitHub Issues: Open in this repo for discussions

Anyone can:

  • Audit the verifier
  • Run a verifier node
  • Independently verify published proofs

Proof generation requires access to private components β€” contact @MRSKYWAY for collaboration or sponsored access.


License

Apache-2.0


Support the Project

ZKCG is built and maintained by a single developer.

πŸ‘‰ Sponsor: https://github.com/sponsors/MRSKYWAY