Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Statement Annotations

Statement annotations express conditions at a particular point in a function body.

Syntax
ContractStatement :=
      Assertion
    | Assumption

ContractStatement syntax diagramContractStatementAssertionAssumption

Semantics

An assertion states a condition to establish at its location. An assumption supplies a condition for reasoning from that location. Both may refer to variables in scope and describe the state at the annotation.

Example

use trust2_contract::prelude::*;

pub fn check(x: u8) {
    contract_assume!(x < 16);
    contract_assert!(x <= 15);
}

The assertion follows from the preceding assumption. This does not prove that x < 16 holds for every call to check.

Implementation boundaries

  • Frontend rust-llbc: supports assertions and assumptions, retaining their conditions, kinds, and positions.
  • Backend llbc-why3: translates them to WhyML assert and assume, respectively.

See Assertions and Assumptions for specific uses and limitations.