Skip to content

Avoid saturating method calls in contract clause depth helpers - #5093

Merged
feliperodri merged 1 commit into
model-checking:mainfrom
r-near:fix-contract-clause-writeset
Nov 13, 2026
Merged

feliperodri merged 1 commit into
model-checking:mainfrom
r-near:fix-contract-clause-writeset

Conversation

@r-near

@r-near r-near commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

__VERIFIER_kani_{enter,exit}_contract_clause aren't instrumented by DFCC but called saturating_add/saturating_sub, which are, so every proof_for_contract harness printed CBMC's "not enough arguments" warning. This replaces the calls with a bounds-checked + 1/- 1. The two capture_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.

@r-near
r-near marked this pull request as ready for review October 28, 2026 17:00
@r-near
r-near requested review from a team as code owners October 28, 2026 17:00
@github-actions github-actions Bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Oct 28, 2026
@feliperodri
feliperodri requested a balanced review from Copilot October 31, 2026 00:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 feliperodri self-assigned this Nov 13, 2026

@feliperodri feliperodri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@feliperodri feliperodri added Z-Contracts Issue related to code contracts [E] User Experience An UX enhancement for an existing feature. Including deprecation of an existing one. labels Nov 13, 2026
@feliperodri feliperodri removed their assignment Nov 13, 2026
@feliperodri
feliperodri added this pull request to the merge queue Nov 13, 2026
Merged via the queue into model-checking:main with commit 2ec6953 Nov 13, 2026
33 checks passed
feliperodri added a commit to model-checking/verify-rust-std that referenced this pull request Nov 20, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[E] User Experience An UX enhancement for an existing feature. Including deprecation of an existing one. Z-CompilerBenchCI Tag a PR to run benchmark CI Z-Contracts Issue related to code contracts Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants