Assertions
Semantics
contract_assert!(P); requires the Boolean condition P to hold at that point. It introduces a proof obligation using the function’s preconditions, preceding assumptions, and the effects of the preceding program statements.
Example
use trust2_contract::prelude::*;
#[precondition(x < 16)]
pub fn bounded_square(x: u8) -> u8 {
let y = x * x;
contract_assert!(y <= 225);
y
}
The assertion describes the local value y after multiplication.
The frontend can extract local assertions of this form. It can also retain ordinary calls in conditions, such as contract_assert!(decuple(9) == 90).
Implementation boundaries
- Frontend
rust-llbc: extracts assertion conditions and retains their positions in function bodies, including within branches. - Backend
llbc-why3: translates them to WhyMLassert; further verification depends on the expressions and program operations involved.
Shared limitations are described under Logic Expressions. Ordinary builds remove contract assertions; runtime checks use Rust’s assert!.