
Our primary goal at FormalΒ LandΒ π² is to make Tezos the first crypto-currency with a formally verified implementation. With formal verification, thanks to mathematical methods, we can check that a program behaves as expected for all possible inputs. Formal verification goes beyond what testing can do, as testing can only handle a finite amount of cases. That is critical as cryptocurrencies hold a large amount of money (around $3B for Tezos today). The current result of our verification project is available on nomadic-labs.gitlab.io/coq-tezos-of-ocaml. Formal verification is also key to allowing Tezos to evolve constantly in a safe and backward compatible manner.
We proceed in two steps:
- we translate the code of Tezos, written in OCaml, to the proof language Coq using the translator coq-of-ocaml;
- we write our specifications and proofs in the Coq language.
We believe this is one of the most efficient ways to proceed, as we can work on an almost unmodified version of the codebase and use the full power of the mature proof system Coq. The code of Tezos is composed of around:
- 50,000 lines for the protocol (the kernel of Tezos), and
- 200,000 lines for the shell (everything else, including the peer-to-peer layer and the storage backend).
We are currently focusing on verifying the protocol for the following modules.
Data-encodingβ
The data-encoding library offers serialization and deserialization to binary and JSON formats. It is used in various parts of the Tezos protocol, especially on all the data types ending up in the storage system. In practice, many encodings are defined in the OCaml files named *_repr.ml. We verify that the data-encoding library is correctly used to define the encodings. We check that converting a value to binary format and from binary returns the initial value. We explicit the domain of validity of such conversions. This verification work generally reveals and propagates invariants about the data structures of the protocol. As an invariant example, all the account amounts should always be positive. Having these invariants will be helpful for the verification of higher-level layers of the protocol.