Developer tools

Using Gemini and Z3 to find Go bugs that fuzzing misses

A Google engineer combined Gemini 4 Argon and the Z3 constraint solver to detect runtime panics in Go code that standard fuzzing overlooked, revealing blind spots in slice capacity handling.

Illustration of code analysis with a glass cube and marked papers
Illustration generated for this article

A Google engineer leading the agent skills program developed a hybrid testing pipeline that combines large language models with formal constraint solving to uncover subtle bugs in Go applications. Published in mid-November 2026, this approach uses Gemini 4 Argon to translate compiled assembly into logical constraints for the Z3 solver, successfully identifying crashes that standard fuzzing tools missed due to runtime environment quirks.

What happened

The developer created skill-lint, a command-line interface written in Go designed to validate and edit SKILL.md files for AI agents. Despite having a comprehensive suite of unit and fuzz tests, the tool remained vulnerable to runtime panics caused by off-by-one errors or incorrect slice operations in its Markdown parsers. These bugs often remained dormant until specific, unusual input patterns triggered them in production, highlighting the limitations of traditional testing methods for complex parsing logic.

To address this, the engineer built a workflow that compiles key functions to RISC-V assembly and uses Gemini 4 Argon to analyze the surviving bounds checks. The model translates these checks into rules for the Z3 constraint solver, which then determines if any input can satisfy the conditions for a crash. This process identified three latent bugs in skill-lint and successfully detected all three artificial bugs planted for testing, including cases where the standard Go fuzzer failed to find the issue even after extended runs.

The investigation revealed that Go’s fuzzer often misses out-of-bounds errors because it typically passes slices with spare capacity. When a slice has extra capacity beyond its length, accessing indices past the length but within the capacity does not panic, masking the bug. By clipping the slice capacity to match its length during testing, the fuzzer was able to detect the same crashes immediately, but the solver approach provided a more systematic way to find these issues without relying on random chance.

How it works

Go’s compiler includes an optimization pass called SSA prove that eliminates bounds checks it can mathematically prove are safe. However, some checks remain in the compiled machine code as explicit traps that trigger a runtime panic if violated. The new workflow targets these surviving traps by compiling the Go code with specific flags to generate assembly listings and debug logs for bounds check elimination. This provides a precise map of where the compiler could not guarantee safety.

Gemini 4 Argon analyzes both the original Go source code and the generated RISC-V assembly. It identifies the path to each remaining bounds check trap and translates the logical conditions into a script for the Z3 constraint solver. Z3 then attempts to solve these constraints to find specific input values that would trigger the panic. If Z3 finds a solution, the workflow generates a concrete Go test case that reproduces the crash, confirming the bug exists.

This method leverages the LLM’s ability to understand code structure and the solver’s precision in logical deduction. While the LLM handles the complex task of translating assembly instructions into solver constraints, Z3 performs the heavy lifting of checking satisfiability. The entire process takes about a minute per function, with the LLM translation being the bottleneck and Z3 solving the constraints in milliseconds, making it feasible for targeted analysis of critical functions.

Key details

  • The workflow uses Gemini 4 Argon to translate Go assembly into Z3 constraints, focusing on surviving bounds checks after compiler optimization.
  • Standard Go fuzzing missed two planted bugs because it rarely creates slices where capacity equals length, allowing out-of-bounds reads to silently succeed.
  • Clipping slice capacity to length in fuzz tests (data[:len(data):len(data)]) allowed the fuzzer to detect the same crashes in under a second.
  • The solver identified three latent bugs in skill-lint, including overlapping chunk edits and incorrect line number accounting after deletions.
  • Z3 returns "sat" when a crashing input exists and "unsat" when no such input is found, providing a clear signal for potential bugs.
  • The approach is limited to pure functions and does not detect data races or deadlocks, which still require the Go race detector.

Why it matters

For developers building robust Go applications, especially those involving parsers or data transformation, this approach highlights a significant blind spot in standard testing practices. Relying solely on fuzzing may leave critical edge cases untested if the fuzzer’s input generation strategy does not align with the specific memory layout requirements of the bug. Understanding how slice capacity interacts with bounds checking is essential for writing secure and stable code.

Integrating LLMs with formal verification tools offers a practical middle ground between manual code review and full theorem proving. It allows engineers to apply rigorous logical analysis to specific high-risk functions without the overhead of modeling an entire application. This hybrid method can catch subtle integer overflows and logic errors that are difficult to spot in source code alone, improving the overall reliability of software systems.

The case study also demonstrates the importance of understanding the underlying machine code when debugging high-level language issues. By examining the assembly output, developers can see exactly how the compiler interprets their code, including any implicit type conversions or optimizations that might introduce vulnerabilities. This deeper insight can lead to better coding practices and more effective testing strategies.

What you can do

  • Clip slice capacity to length in your fuzz tests using data[:len(data):len(data)] to ensure out-of-bounds accesses trigger panics.
  • Use go build -gcflags="-S -d=ssa/check_bce/debug=1" to identify which bounds checks survive compiler optimization in critical functions.
  • Extract pure functions from your application logic for targeted analysis, leaving I/O and network calls to standard integration tests.
  • Consider using constraint solvers like Z3 for verifying complex logic in parsers or mathematical operations where random fuzzing is inefficient.
  • Review assembly output for unexpected type truncations or register movements that might affect bounds checking logic.
  • Combine static analysis tools with dynamic testing to cover both logical correctness and runtime behavior comprehensively.
  • #go
  • #testing
  • #ai
  • #security
  • #debugging

Tools from the Bytechap store

Keep reading

All stories