Repository navigation
Avoid saturating method calls in contract clause depth helpers - #5093
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the contract-clause depth helper changes.
No open issues 🎉
What changed in this PR
This PR removes saturating method calls from Kani’s contract-clause depth helpers to avoid CBMC’s “not enough arguments” warning during function-contract verification. It addresses a related helper issue, not the broader loop-invariant method-call problem in #4796.
Changes:
- Replace saturating calls with bounds-checked arithmetic, preserving saturation behavior.
- Add a regression test requiring successful verification without missing-argument warnings.
- Update two expected check counts for the added overflow checks.
| File | Description |
|---|---|
library/kani_core/src/lib.rs |
Use guarded increments and decrements for contract-clause depth. |
tests/script-based-pre/contract_clause_write_set/write_set.sh |
Check verification succeeds without missing-argument warnings. |
tests/script-based-pre/contract_clause_write_set/write_set.expected |
Define the regression test’s success output. |
tests/script-based-pre/contract_clause_write_set/fixture.rs |
Provide a function-contract proof fixture. |
tests/script-based-pre/contract_clause_write_set/config.yml |
Register the regression script and expected output. |
tests/expected/function-contract/capture_load_user_deref_pass.expected |
Increase the expected check count from 58 to 60. |
tests/expected/function-contract/capture_load_checks_elided.expected |
Increase the expected check count from 34 to 36. |
Review effort: Balanced
feliperodri
left a comment
There was a problem hiding this comment.
Thanks @r-near. Inlining the bounded arithmetic is the right fix: these helpers are excluded from DFCC's instrumentation, so they must not call functions that DFCC instruments. With the base kani_core your new test shows both warnings, and with this change it passes; the contract suites (expected function-contract, kani FunctionContracts, expected loop-contract) also pass, including the two updated check counts.
One small request: please extend the comment above enter_contract_clause to say why the code avoids saturating_add/saturating_sub: DFCC does not instrument these __VERIFIER_ helpers but does instrument those methods, so calling them leaves out the write-set argument. Without that, someone may "simplify" it back.
Since model-checking/kani#5093, every contract harness fails under ESBMC on a `reachability_check` property, which Kani reads as "this assertion is reachable" rather than as a violation (esbmc/esbmc#10875). ESBMC v8.6 added `--ignore-property-class`, so the script now pins v8.7 and skips the `reachability_check` and `cover` classes. With this change, #766 can drop `--no-assertion-reach-checks`. ESBMC has read Kani's GOTO binaries directly since v8.4, so the docs, workflow and script now refer to ESBMC only: `goto-transcoder.yml` becomes `esbmc.yml`, `run-goto-transcoder.sh` becomes `run-esbmc.sh`, and `tools/goto-transcoder.html` redirects to `tools/esbmc.html`. Tested on the `checked_unchecked_mul_{i8,u8,i16,u16}` contracts built with `--keep-temps --only-codegen`: with Kani `c5e65fd` (main) and `53cb531` (#766), ESBMC v8.7 verifies all four, as v8.6 does. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses. --------- Co-authored-by: Felipe R. Monteiro <[email protected]>
__VERIFIER_kani_{enter,exit}_contract_clausearen't instrumented by DFCC but calledsaturating_add/saturating_sub, which are, so everyproof_for_contractharness printed CBMC's "not enough arguments" warning. This replaces the calls with a bounds-checked+ 1/- 1. The twocapture_load_*check counts go up by 2 for the new overflow checks.Adds
tests/script-based-pre/contract_clause_write_set, which fails before this change.Related to #4796
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.