# Gobra

> Add specifications as comments to Go code; Gobra translates it to the Viper verifier, which proves memory safety, race freedom and your contracts.

- Kind: toolchain
- Verifies: Go (Gobra supports many Go features but not all; strings and some integer types such as rune have very limited support.)
- Effort: Auto-active — You write specifications and hints; a solver does the proving.
- Stage: 1 (Usable)
- Trust: Checker partial, Semantics weak, Frontend partial, Binary gap weak, Escape hatches partial
- Licence: open-source, MPL-2.0 (with listed exceptions)
- Latest release: v26.09 (2026-10-13) https://github.com/viperproject/gobra/releases/tag/v26.09
- Links: [homepage](https://www.pm.inf.ethz.ch/research/gobra.html), [repo](https://github.com/viperproject/gobra), [docs](https://github.com/viperproject/gobra/blob/master/docs/tutorial.md), [paper](https://doi.org/10.1007/978-3-030-81685-8_17), [tutorial](https://github.com/viperproject/gobra/blob/master/docs/tutorial.md)

## Use it if
- You want to prove memory safety, absence of crashes and data races, and functional properties of Go code.
- Your code uses goroutines, channels or sync.Mutex and you can describe what each goroutine owns.
- You need to prove that secrets do not leak, using Gobra's hyperproperty mode.

## Look elsewhere if
- You cannot add annotations for heap permissions; Gobra needs them for every pointer access.
- You rely on integer wrap-around; overflow is only checked with the --overflow flag, and without it Gobra treats integers as unbounded.
- Your code depends on many standard-library packages; only a few have specifications.

## How it works (pipeline)

| Step | Component | Assurance | Note |
|---|---|---|---|
| frontend | Gobra's own Go parser and type checker (ANTLR grammar) | trusted | Annotations live in // @ comments, so the same files still build with the normal Go compiler. |
| translation | Gobra encoding of Go into the Viper intermediate language | trusted |  |
| translation | Viper back end (Silicon symbolic execution by default; Carbon via Boogie as an option) | trusted |  |
| checker | Z3 (`z3`) | trusted |  |
| compiler | gc (the Go compiler) | trusted |  |

## Trust

| Axis | Level | Summary | Note |
|---|---|---|---|
| Checker | Partial (amber) | Viper's symbolic execution engine and the Z3 SMT solver decide; no proof certificates. |  [source](https://github.com/viperproject/gobra/blob/master/README.md) |
| Semantics | Weak (red) | Go model built into Gobra; ignores integer overflow unless --overflow is set. | By default Gobra does not check for integer overflow, and the bounds of Go's integer types are only added by the --overflow transformation. Without the flag, a proof can therefore hold for mathematical integers but not for a real Go run in which a value overflows and wraps around. With the flag, overflow is reported as an error. Otherwise the encoding is tested by Gobra's regression suite. [source](https://github.com/viperproject/gobra/blob/master/src/main/scala/viper/gobra/ast/internal/transform/OverflowChecksTransform.scala) |
| Frontend | Partial (amber) | Gobra's own Go parser and type checker, not the Go compiler's front end. |  [source](https://github.com/viperproject/gobra/tree/master/src/main/antlr4) |
| Binary gap | Weak (red) | The binary comes from the Go compiler, which is not verified. |  |
| Escape hatches | Partial (amber) | assume, trusted functions and bodiless functions are accepted; found by searching. | Functions marked trusted or written without a body are assumed to meet their specification. Library stubs are also assumed. [source](https://github.com/viperproject/gobra/blob/master/docs/tutorial.md) |

## What it can prove

| Property | Support |
|---|---|
| No undefined behavior | Partial — Proves memory safety (through permissions) and absence of runtime errors such as nil dereference and out-of-bounds access. Integer overflow is only checked with --overflow, which is off by default. ([source](https://github.com/viperproject/gobra/blob/master/src/main/scala/viper/gobra/frontend/Config.scala)) |
| Functional correctness | Supported — Pre- and postconditions, predicates, ghost code and pure functions. ([source](https://github.com/viperproject/gobra/blob/master/docs/tutorial.md)) |
| Equivalence | Partial — No dedicated equivalence mode. The hyperproperty mode relates two runs of the same program, but comparing two different versions needs a hand-written specification. |
| Information flow | Supported — A hyperproperty mode (--hyperMode, off by default) proves that secret (non-low) data does not affect public outputs, with a declassify statement for intended releases. ([source](https://github.com/viperproject/gobra/tree/master/src/test/resources/regressions/features/hyper_properties)) |
| Concurrency | Partial — Proves freedom from data races and properties of messages sent over channels and data guarded by locks. The tutorial does not cover deadlock freedom. ([source](https://github.com/viperproject/gobra/blob/master/docs/tutorial.md)) |
| Termination and liveness | Supported — Termination is proved with decreases clauses. It is required for pure and ghost functions and optional for other code. ([source](https://github.com/viperproject/gobra/blob/master/docs/tutorial.md)) |

## Common features

| Feature | Support |
|---|---|
| Machine integers | Partial — Without --overflow (the default) Gobra treats bounded integers as mathematical integers, so it neither checks overflow nor models wrap-around. The tutorial also says support for some integer types such as rune is very limited. ([source](https://github.com/viperproject/gobra/blob/master/src/main/scala/viper/gobra/ast/internal/transform/OverflowChecksTransform.scala)) |
| Floating point | Partial — Basic float32/float64 arithmetic appears in the regression tests; how closely IEEE 754 is modeled is not documented. ([source](https://github.com/viperproject/gobra/tree/master/src/test/resources/regressions/features/floats)) |
| Heap and pointers | Supported — Pointers and heap access use permissions (acc predicates), including fractional and quantified permissions. ([source](https://github.com/viperproject/gobra/blob/master/docs/tutorial.md)) |
| Arrays and buffers | Supported — Arrays and slices are supported. ([source](https://github.com/viperproject/gobra/blob/master/docs/tutorial.md)) |
| Loops | Supported — Loop invariants; decreases clauses for termination. ([source](https://github.com/viperproject/gobra/blob/master/docs/tutorial.md)) |
| Recursion | Supported ([source](https://github.com/viperproject/gobra/blob/master/docs/tutorial.md)) |
| Higher-order code | Supported — Closures are specified with specification types and proved to satisfy them. ([source](https://github.com/viperproject/gobra/tree/master/src/test/resources/regressions/features/closures)) |
| Threads and shared memory | Supported — Goroutines, channels and sync.Mutex, with permissions passed between goroutines. ([source](https://github.com/viperproject/gobra/blob/master/docs/tutorial.md)) |
| I/O and system calls | Partial — Some packages (for example net, fmt, time) have trusted specification stubs; other I/O needs hand-written specifications. ([source](https://github.com/viperproject/gobra/tree/master/src/main/resources/stubs)) |
| Standard library | Partial — Specification stubs exist for a few packages (bytes, encoding/binary, errors, fmt, net, strconv, strings, sync, time); they are assumed, not verified. ([source](https://github.com/viperproject/gobra/tree/master/src/main/resources/stubs)) |

## Go-specific features

| Feature | Support |
|---|---|
| Goroutines and channels | Supported — go statements and channels are verified with predicates that say which permissions travel with each message. ([source](https://github.com/viperproject/gobra/blob/master/docs/tutorial.md)) |
| Interfaces | Supported — Interfaces with specifications and implementation proofs. Gobra tracks whether interface values are comparable, because comparing incomparable values panics in Go. ([source](https://github.com/viperproject/gobra/blob/master/docs/tutorial.md)) |
| Slices and maps | Supported — Slices and maps are covered by the regression suite. ([source](https://github.com/viperproject/gobra/tree/master/src/test/resources/regressions/features/maps)) |
| defer, panic and recover | Partial — defer is supported (regression tests); support for panic and recover is not documented. ([source](https://github.com/viperproject/gobra/tree/master/src/test/resources/regressions/features/defer)) |

## Stage

**Stage 1: Usable.**

| Stage | Criterion | Met | Evidence / note |
|---|---|---|---|
| 0 | Publicly available | yes | [evidence](https://github.com/viperproject/gobra) |
| 0 | At least one published verification uses it | yes | [evidence](https://arxiv.org/abs/2405.06074) Formal verification of the SCION border router's Go implementation (VerifiedSCION). |
| 1 | Released or updated in the last 12 months | yes | [evidence](https://github.com/viperproject/gobra/releases/tag/v26.09) Latest release: v26.09, 2026-10-13. |
| 1 | Installs and runs on current platforms | yes | [evidence](https://github.com/viperproject/gobra/blob/master/README.md) Built from source with sbt and Java; needs Z3 (CI uses Z3 4.16.0). Releases are tagged about twice a year. |
| 1 | User documentation or tutorial | yes | [evidence](https://github.com/viperproject/gobra/blob/master/docs/tutorial.md) |
| 1 | Used by a group other than its authors | yes | [evidence](https://arxiv.org/abs/2507.00595) Engineers from Amazon Web Services, with ETH Zurich, used Gobra on a 100k+ line production Go codebase (Diodon). |
| 2 | Verified code in production at two or more independent organizations | no | None recorded. |
| 2 | Checker axis is not red | yes |  |
| 2 | Semantics axis is not red | no |  |
| 2 | Public channel for soundness bugs | yes | [evidence](https://github.com/viperproject/gobra/issues?q=label%3Asoundness) Public GitHub issues with a "soundness" label. |

Missing for Stage 2: Verified code in production at two or more independent organizations; Semantics axis is not red.

## Projects
- [VerifiedSCION (SCION border router data plane)](https://github.com/viperproject/VerifiedSCION)
- [Diodon (security of a large production Go key-exchange codebase)](https://arxiv.org/abs/2507.00595)
- [Go's extendedGCD in crypto/internal/fips140/bigmod](https://arxiv.org/abs/2606.05796)
- [Verified implementations of WireGuard and other security protocols](https://github.com/viperproject/SecurityProtocolImplementations)

## Sources
- [Gobra README](https://github.com/viperproject/gobra/blob/master/README.md)
- [A Tutorial on Gobra](https://github.com/viperproject/gobra/blob/master/docs/tutorial.md)
- [Gobra command-line options (overflow and hyperMode defaults)](https://github.com/viperproject/gobra/blob/master/src/main/scala/viper/gobra/frontend/Config.scala)
- [Gobra: Modular Specification and Verification of Go Programs (CAV 2021)](https://doi.org/10.1007/978-3-030-81685-8_17)
- [Protocols to Code: Formal Verification of a Next-Generation Internet Router](https://arxiv.org/abs/2405.06074)

---
Last checked 2026-11-26. Data: [JSON](/toolchains/gobra.json) · Page: [HTML](/toolchains/gobra/) · Methodology v0.1: [/methodology/](/methodology/) · Corrections: [/contribute/](/contribute/)
