Tekko

Language

Get in Touch →

Usually respond within 24 hours

Back to BlogAI & ML

Verifiable AI: Proving Model Integrity with zkML and EZKL

7 min read
zkMLEZKLZero-Knowledge ProofsAI SecurityCryptography
Verifiable AI: Proving Model Integrity with zkML and EZKL

As AI moves from experimental chatbots to the core of regulated industries—think credit scoring, medical diagnostics, and autonomous legal systems—we face a fundamental trust crisis. If a model denies a loan or flags a suspicious lesion in an MRI, how can the user, the regulator, or the auditor be certain that the specific, approved model was actually used? How do we know the service provider didn't swap the high-performance model for a cheaper, less accurate one to save on compute costs, or worse, manipulate the output for a specific user?

In the traditional software world, we use checksums and digital signatures. In the AI world, we need something more robust. We need Verifiable AI. This is where Zero-Knowledge Machine Learning (zkML) and tools like EZKL come into play.

The Black Box Problem in Regulated Environments

In a standard inference setup, the process is opaque. You send data to an API, and it returns a result. You have zero visibility into the computation. For a Netflix recommendation, this doesn't matter. For a bank determining a mortgage rate under the Fair Housing Act, it matters immensely.

Regulators are increasingly demanding "Model Integrity." This means proving that:

  1. The model architecture and weights used during inference are exactly what was audited and approved.
  2. The computation was performed correctly on the provided input data.
  3. The result hasn't been tampered with in transit.

Historically, the only way to achieve this was to run the model on-premises or trust a third-party auditor. zkML offers a third way: mathematical proof.

What is zkML?

Zero-Knowledge Machine Learning (zkML) combines Zero-Knowledge Proofs (ZKPs) with ML inference. A ZKP allows one party (the Prover) to prove to another party (the Verifier) that a statement is true without revealing any information beyond the validity of the statement itself.

In the context of ML, a zkML proof asserts: "I ran this specific model (M) on this specific input (x), and it produced this output (y)."

The beauty of this approach is that the proof is significantly smaller than the computation itself and can be verified in milliseconds, even if the original inference took seconds or minutes on a powerful GPU.

Introducing EZKL: The Bridge Between ML and Cryptography

For most software engineers, writing a Zero-Knowledge circuit from scratch is a nightmare involving complex polynomial math and low-level cryptographic primitives. EZKL (pronounced "E-Z-K-L") is an open-source library that abstracts this complexity away. It allows developers to convert standard Open Neural Network Exchange (ONNX) models into a format that can generate ZK proofs.

EZKL sits on top of Halo2, a high-performance ZK proving system. It handles the difficult task of "quantization"—converting the floating-point numbers used in ML into the fixed-point integers required for cryptographic circuits—while maintaining model accuracy.

The EZKL Workflow

Implementing a verifiable AI pipeline with EZKL generally follows these five steps:

  1. Model Export: Train your model in PyTorch, TensorFlow, or JAX, and export it to the ONNX format.
  2. Calibration: Use EZKL to determine the optimal scale and parameters for quantization. This ensures the fixed-point representation doesn't degrade the model's performance.
  3. Setup: Generate the "proving key" and "verifying key." The verifying key is what you’ll give to your users or deploy to a smart contract.
  4. Proving: When an inference is made, the Prover runs the model through EZKL to generate a proof file (a .proof or .json).
  5. Verification: The Verifier uses the verifying key and the proof to confirm the computation was valid.

Real-World Example: Verifiable Credit Scoring

Imagine a FinTech company, TrustLend, that uses a proprietary neural network to score credit applications. To comply with transparency regulations, they need to prove they aren't using prohibited variables (like race or gender) and that they are using their officially filed model.

Step 1: The Model

TrustLend has a PyTorch model. They export it:

import torch # ... model definition ... dummy_input = torch.randn(1, 20) # 20 features torch.onnx.export(model, dummy_input, "credit_model.onnx")

Step 2: EZKL Configuration

Using the EZKL Python API, they define the precision:

import ezkl # Configure the settings for the ZK circuit res = ezkl.gen_settings("credit_model.onnx", "settings.json") ezkl.calibrate_settings("data.json", "credit_model.onnx", "settings.json", "resources")

Step 3: Generating the Proof

When a user applies, TrustLend runs the inference and generates a proof simultaneously:

ezkl.compile_circuit("credit_model.onnx", "compiled_model.ezkl", "settings.json") ezkl.get_srs("settings.json") ezkl.gen_witness("input.json", "compiled_model.ezkl", "witness.json") ezkl.prove("witness.json", "compiled_model.ezkl", "pk.key", "proof.json", "srs")

Now, TrustLend provides the user with the result and proof.json. The user (or a regulator) can verify this proof using the publicly available vk.key. If a single weight in the model was changed, the verification would fail.

The Technical Challenges: The "Prover Tax"

While zkML is revolutionary, it is not a free lunch. As a senior engineer, you must account for the Prover Tax—the computational overhead of generating a proof.

  1. Compute Intensity: Generating a ZK proof for a medium-sized model can be 100x to 1000x slower than the inference itself. While inference takes milliseconds, proving might take seconds or even minutes for large models.
  2. Memory Constraints: Proving requires significant RAM. Large language models (LLMs) are currently beyond the reach of standard zkML because the resulting cryptographic circuits would require terabytes of memory to generate proofs.
  3. Quantization Loss: Converting float32 to fixed-point can lead to "drift." You must rigorously test your model's accuracy after it has been processed by EZKL.

Architecture Patterns for Verifiable AI

When designing these systems, I recommend two primary patterns depending on your trust requirements:

1. Off-chain Verification

In this pattern, the Prover (the AI service) sends the result and the proof to a client-side application (e.g., a mobile app or a secure dashboard). The client verifies the proof locally. This is excellent for privacy-preserving health apps where the model is proprietary, but the user needs to know the diagnosis is legitimate.

2. On-chain Verification

For decentralized finance (DeFi) or automated governance, the proof is submitted to a blockchain smart contract. The contract acts as the Verifier. If the proof is valid, the contract executes a transaction (e.g., releasing funds). EZKL simplifies this by being able to generate a Solidity verifier contract automatically:

ezkl.create_evm_verifier("vk.key", "settings.json", "Verifier.sol")

Strategic Considerations for Decision Makers

If you are evaluating zkML for your roadmap, consider the following:

  • Start Small: Don't try to prove a GPT-4 inference. Start with tabular data models, simple CNNs, or decision trees. These are highly efficient in EZKL.
  • Identify the Trust Gap: Use zkML where the cost of a "wrong" or "tampered" result is high. If a manual audit is your current solution, zkML will likely be cheaper and faster in the long run.
  • Hardware Acceleration: Proving is a highly parallelizable task. Look into using GPUs or specialized hardware (ASICs/FPGAs) if you need to generate proofs at scale.

The Future: Beyond Integrity

While this article focuses on model integrity (proving the model was run correctly), zkML also opens the door to Data Privacy. You can prove that you have a certain credit score or a clean bill of health without ever revealing the underlying sensitive data to the model provider. The computation happens on your data, and you only provide the proof of the result.

Actionable Conclusion

Verifiable AI is no longer a theoretical branch of cryptography; it is a deployable technology. To move forward:

  1. Audit your pipeline: Identify where "trust me" is currently a bottleneck or a regulatory risk.
  2. Standardize on ONNX: Ensure your ML team is comfortable exporting and validating models in the ONNX format.
  3. Prototype with EZKL: Use the EZKL Python bindings to run a proof-of-concept on a small, business-critical model. Measure the proving time and accuracy impact.
  4. Evaluate the Verifier: Decide if your verification needs to be decentralized (on-chain) or simply client-side.

By implementing zkML today, you aren't just checking a compliance box; you are building a foundation of mathematical certainty in an era of AI uncertainty.