Home / Learn / 5 Contracts and the verifier

Release v0.4.0Edition 0.2

5.10 Recap and reference

Page 11 of 11

5.10.1 For agents

una --json check . gives each obligation that is not proven as a diagnostic with its obligation (id, kind, goal, status) and its counterexample as name and value pairs. For a coupon that can be worth more than the order:

json
{"schema":"una.diagnostics/1","diagnostics":[{"schema":"una.diagnostic/1","code":"U5001","severity":"error","domain":"verification","message":"postcondition of `discount` is refuted","primary":{"file":"src/billing.una","start":{"line":64,"col":25},"end":{"line":64,"col":28}},"related":[{"file":"src/billing.una","start":{"line":58,"col":11},"end":{"line":58,"col":27},"message":"ensures clause"}],"obligation":{"id":"ob-e0a2abc0bb6a","kind":"postcondition","goal":"result <= amount","status":"refuted"},"counterexample":{"bindings":[{"name":"amount","value":0},{"name":"coupon","value":"CentsOff"},{"name":"coupon.amount","value":1},{"name":"coupon.rate","value":101},{"name":"result","value":1}]},"repairs":[{"rank":1,"escape_cost":0,"description":"add a guard or an arm so that the failing path returns a value for which `result <= amount` holds","edit":null},{"rank":2,"escape_cost":0,"description":"adjust the `ensures` clause","edit":null}],"explain":"una explain U5001"}],"fixable":0}

The repairs of U5001 and U5002 carry no edit, since only the author knows whether the code or the contract is wrong, so una fix leaves them. una --json obligations . and una --json trace <ID> list every obligation, proven or not. The compact rule: every call proves the callee's requires, every return proves the ensures, every value that enters a refined kind proves its condition, and unknown is an error; clauses multiply and divide only by literals.

5.10.2 Recap

  • requires is what a caller must prove; ensures is what every return promises. Callers know a function by its header alone.
  • A counterexample shows where a contract breaks. Fix the code or the contract, and keep a real case as an example.
  • Put a rule that holds of every value on its kind, Int where it >= 0, and name a shared rule with a reflect predicate.
  • Clauses multiply and divide only by literals. For a product of two values, bind it with let and guard it.
  • una obligations . lists every question and its status. U5001 is refuted, U5002 unknown; both are errors.
  • Record business rules as requirements, tie functions to them with derived from, and follow them with una trace.

5.10.3 Reference

Next:6 Functions and their results