Documentation menu
Compiler

Checked, tested and assumed

Which guarantees the kernel checks on every program, which ones are proved in Omegyu, which ones tests support, and which ones are assumptions.

Find a section4 sections

Checking a program’s type is not the same as proving a property of its deployed bytecode. Here is what supports each claim.

Checked on every compilation

  • The kernel type-checks the term that the elaborator produces for every program, from scratch, before anything is printed, run or compiled (the pipeline). The definitions read from the cache are assumed instead, unless --recheck is given (the cache).

  • An assert holds when its two sides have the same normal form, so it is checked whenever its program is.

  • For a contract, the memory planning, scheduling, peephole optimisation and assembly of the generated code are checked on every compilation, by a validator that replays the code against the program and by the assembler's checks. These checkers are trusted.

Proved in Omegyu

Proofs are programs, which the kernel checks as it checks any other (dependent types and proofs). The library and the examples prove, among others:

  • the laws of the arithmetic of naturals, and of Word 256, in std:Arith, from the hypothesis NatFacts;

  • the laws of the list eliminators that list fusion uses, in std:List/Law;

  • the laws of the mappings of records and unions that reflection derives (reflection);

  • the validity of each storage layout of std:EVM/State/Layout, which its type requires (storage layout from types);

  • the reserve-product inequality in Pool’s SwapKeepsK type, for the natural-number swap calculation with a positive input-side reserve, assuming NatFacts.

Supported by tests

A test supports a claim for the cases that it runs, and not beyond.

SuiteWhat it tests
core-teststhe kernel alone
lang-testssyntax, elaboration, the tools, the golden files, the library and the examples
evm-teststhe EVM harness, the back end on IR, compiled contracts against independent models, and the benchmarks against solc
repo-teststhe layout of the repository
  • The words of the reference model of the EVM are compared with the opcodes, and its effects with those of hevm and geth.

  • The readback of staged terms, the optimisation passes and instruction selection are tested. The rewrite rules of the passes are proved by z3, which is trusted for them.

  • The benchmarks check that an example and its Solidity equivalent give the same status and return data on the same ABI call data, for the steps that they run.

  • The WebAssembly build of the compiler, which checks the examples of this site and runs the playground, is built from the same source as the native one. That the two builds agree is assumed: no test compares them.

Assumed

  • The kernel. It is correct, and its theory is consistent. The predicative fragment of the theory, with first-class levels, has mechanised proofs of consistency, canonicity and normalisation. An impredicative bottom universe with small inductive types is the logic of Coq before version 8.0, which is believed consistent. No published result covers their combination (docs/design.md).

  • The cache. An entry was written by an omegyu that checked it (the cache).

  • NatFacts. Multiplication, subtraction, division and remainder of naturals satisfy the six equations of std:Arith.NatFacts. Each is checked on literals. A false one would make the theorems that assume it vacuous, not the logic inconsistent.

  • Keccak. The hashed storage keys that a contract touches have pairwise distinct slots, outside its fixed slots and regions.

  • The EVM. The chain implements Osaka as the execution specifications say, and only the contract's own code runs on its account.

  • The compiler. The readback, the optimisation passes, instruction selection, the lowering of storage keys and the checkers that run on every compilation are correct.

Section 11 of docs/evm.md states the soundness claim of the EVM back end and these assumptions precisely.