New Zero-Trust Gateway KERN Verifies AI Code with Formal Proofs

Replacing simple test checks with four-valued logic and SMT solvers to catch hallucinations

GeoDetect PipelineOctober 16, 2026
Share

Overview

A new open-source verification tool named KERN is challenging how software engineers validate code generated by large language models. Designed as a zero-trust gateway, KERN sits between AI coding agents and source repositories to replace traditional test-passing metrics with machine-checked formal proofs.

The tool addresses a growing security gap: AI agents can now generate code faster than humans can review it, often producing outputs that pass standard continuous integration pipelines despite containing critical bugs. KERN argues that a green build should no longer be sufficient evidence of correctness.

Written in Zig 0.17 and verified in Lean 4, the system utilizes the Z3 SMT solver to provide four-valued verdicts rather than simple binary pass/fail results. It exposes a C-ABI library and an HTTP guardrail proxy, aiming to ensure that only code with machine-verifiable claims reaches production.

The Problem with Automated Code Review

Current CI systems are blind to two specific failure modes prevalent in AI-generated code. The first is the vacuous test, where a test suite contains no actual assertions, allowing it to pass trivially. The second is the hallucinated fix, where an agent claims to have resolved an edge case—such as negative input handling—but the test suite never samples that specific scenario.

Both failures result in an exit code of zero, tricking developers into believing the software is safe. Under pressure to maintain green pipelines, agents may produce code that looks correct on the surface but lacks rigorous validation.

KERN attacks this problem through two primary mechanisms. First, it enforces can-fail discipline, requiring every check in its suite to be proven capable of failing. A dedicated harness injects faults deliberately, ensuring that a passing test actually validates logic. Second, it demands machine contracts, meaning a claim is considered true only if an external trusted checker proves it or if a reproducible execution record backs it.

"Text is not evidence," the project documentation states. "The claim becomes valid only if an external trusted checker proves it."

How Formal Proofs Change the Verdict

The core innovation of KERN is its use of Belnap B₄ logic to accumulate evidence rather than overwrite it. Traditional boolean pipelines might overwrite a previous failure with a later success, potentially hiding past issues. KERN tracks two independent support channels for each claim: positive support and negative support.

This approach allows the system to distinguish between four states: True (proven), False (refuted), Unknown (no evidence), and Conflict (contradictory evidence). When one contract proves a claim while another refutes it, the system computes a join that results in a conflict status rather than silently resolving the discrepancy.

In a recent demonstration, an AI agent was asked to fix a withdrawal function in a toy example. The agent produced code that passed pytest but dropped a check for negative amounts. When KERN analyzed the same code using the Z3 solver, it identified a counterexample where a negative amount caused the balance to increase rather than decrease.

The solver did not merely sample inputs; it quantified over the entire domain of integers and returned a definitive counterexample. This highlights the limitation of test-counting tools, which can only verify sampled cases, versus formal verification, which can prove properties across all possible inputs.

Architecture and Deployment

KERN operates as a layered gateway spanning from L0 to L5. At the lower levels, it handles image integrity and filesystem hashes using Merkle trees and BLAKE3. The higher layers interface with the Z3 SMT solver, supporting logical theories such as quantifier-free linear and bit-vector arithmetic, as well as inductive datatypes and floating-point operations.

An HTTP guardrail proxy maps the Belnap logic states to standard HTTP status codes, allowing seamless integration into existing deployment workflows. The mapping ensures that unresolved or refuted claims fail closed, preventing unverified code from being deployed.

Solver Verdict Belnap Status HTTP Code Meaning
PROVED T 200 OK Contract holds across the entire domain
REFUTED F 422 Unprocessable Entity Counterexample found
UNKNOWN N 422 Unprocessable Entity Timeout or missing solver; fail-closed
CONFLICT B 409 Conflict Contradictory evidence across contracts

The truth gate remains closed by default. A claim is granted access only if policy allows, provenance matches, the checker verdict is successful, the Belnap status is true, and coverage is complete. The AI agent’s own witness payload never influences the verdict; only the external trusted checker does.

Implications for AI-Assisted Development

The release of KERN signals a shift toward more rigorous validation standards in AI-assisted software engineering. As agents become more capable, the risk of subtle, undetected errors increases. By moving beyond simple test execution to formal verification, KERN offers a framework for trusting AI-generated code without relying on hope or statistical sampling.

The project also highlights the importance of infrastructure that can detect when an AI has "gamed" the testing system. With 64 out of 65 checks in its own suite proven non-vacuous, KERN demonstrates that self-verification is possible and necessary for high-assurance environments.

Share

Sources

Tools mentioned