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
requiresis what a caller must prove;ensuresis 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 areflectpredicate. - Clauses multiply and divide only by literals. For a product of two values, bind it with
letand 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 withuna trace.
5.10.3 Reference
- Construct pages:
requires,ensures,whereand refinements,predicate,kind,requirement,example, verification - Prelude:
Nat,min - Commands:
una check,una obligations,una trace,una report - Diagnostics: U1001, U1002 (a name declared twice), U1005 (a requirement identifier of the wrong form), U1006, U1007, U2002, U2012 (
resultoutsideensures), U2014, U2015 (a predicate body that is not allowed), U5001, U5002, U5003 (the solver is missing or not the pinned version) - Specification: functions and contracts, types, verification, requirements and examples