Skip to content
AeneasVerifPublic

About

assembly-level instruction-set semantics in Lean

Resources

Contributing

Stars

97 stars

Watchers

5 watching

Forks

Repository files navigation

Kraken

Kraken is a Lean framework for verifying assembly programs, either hand-written (.S files), or disassembled from compiler output (.o files). We currently support x64, aarch64, and have plans for risc-v.

We emphasize careful design, well-audited semantics, and excellent proof automation. Our work on prover performance and automation has led to numerous improvements in upstream Lean, such as SymM, grind hom, and improvements in vcgen as well.

The largest program we have processed to date is over 10,000 instructions, and we continue to scale up.

Kraken is a joint project between the Lean FRO, Google, and INRIA.

Design

The distinguishing features of Kraken are as follows.

  • We verify code that is one level of abstraction above binary code, i.e., before the assembly and linking steps. This means we do not make any concrete assumptions about program layouts, instruction sizes, or memory addresses -- we can reason about a library in the abstract, without making assumptions about how it will be laid out in memory.
  • We emphasize proof efficiency: we investigate agent-generated proofs and tweak automation to leverage e.g. grind, rather than have low-level manual proofs that break at the slightest change in input ASM.
  • We evolve Lean to support better automation for program proof: SymM and grind hom are joint work between Google and the Lean FRO, and we are currently collaborating on connecting our semantics to mvcgen.
  • Our semantics are carefully designed, by hand, to support both efficient testing and theorem proving.

Status

We are currently connecting Kraken to mvcgen to leverage the automation and program proof facilities provided by Lean itself. The latest snapshot is on Sebastian Graf's branch, and this is where we managed to scale past 10,000 instructions -- using agents, of course.

X64 model scope

The x64 model is intended for verifying sequential software that performs computations using common registers and memory. Operating-systems and concurrency features currently out of scope.

Included

  • 64-bit mode, including 32-bit and smaller operations available in this mode
  • All 64-bit registers and partial-register access
  • Status flags
  • Memory access, including avoidance of faults
  • ADX, BMI, BMI2, and similar extensions
  • Assembler features: labels, arithmetic on immediates, rodata

Excluded

  • Handling of most exceptions and faults
  • Virtual memory
  • Segment registers
  • MSRs
  • Other execution modes, such as 32-bit and 16-bit modes
  • Mutable globals (bss and data)

Incidental extensions to x64

Kraken models assembly rather than machine encodings and may accept unencodable instructions, as long as every program that does assemble for real x64 hardware satisfies its proven specification. See Guidelines.md for the design rules and examples, and CONTRIBUTING.md for the semantics review checklist.

Using the embedded syntax

One is able to embed X64 and AArch64 assemlby into Lean by using the ⸨prog| ... ⸩ syntax (braces typed as \((), which gets transformed by the elaborator into the Lean model used internally by Kraken. To parameterize over parts of our program, it is useful to use antiquotations ❰...❱ (braces typed as \h<) to inject arbitrary values of our model into the syntax.

variable {w : Width} (r : Reg w)
def add_2  := ⸨prog| add $2, %❰r❱⸩ 
def add_2' := ⸨prog| inc %❰r❱; inc %❰r❱⸩

About

assembly-level instruction-set semantics in Lean

Resources

Contributing

Stars

97 stars

Watchers

5 watching

Forks

Releases

Packages

Contributors

Languages