Skip to content

Classify division-by-zero checks as distinct property type#514

Draft
tautschnig wants to merge 2 commits intomainfrom
tautschnig/classify-division-by-zero
Draft

Classify division-by-zero checks as distinct property type#514
tautschnig wants to merge 2 commits intomainfrom
tautschnig/classify-division-by-zero

Conversation

@tautschnig
Copy link
Contributor

Keeping in draft as this is meant to be just one extra commit over #510, but deserves an independent discussion.

Description of changes:

Extend PropertyType with a divisionByZero variant so that verification results from safe division/modulo preconditions are distinguishable from regular assertions. PrecondElim attaches a propertyType metadata tag based on the function name (Int.SafeDiv*, Int.SafeMod*), which CmdEval reads when creating proof obligations. The classification propagates to both text output (Property: division by zero check) and SARIF output (kind: division-by-zero).

Co-authored-by: Kiro kiro-agent@users.noreply.github.com

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

tautschnig and others added 2 commits March 4, 2026 20:55
…510)

Laurel division and modulo operations (/, %, /t, %t) now fail
verification when the divisor may be zero.

This is achieved by translating Laurel's division/modulo to Core's safe
operator variants (Int.SafeDiv, Int.SafeMod,
Int.SafeDivT, Int.SafeModT), which carry a built-in y ≠ 0 precondition.
The existing PrecondElim transform then
automatically generates the necessary verification conditions at each
use site — no Laurel-level instrumentation is
required.

*Description of changes:*

New Core operators — Int.SafeDivT and Int.SafeModT added to the Lambda
IntBoolFactory and Core Factory, mirroring the
existing Int.SafeDiv/Int.SafeMod. SMT encoding and AST-to-CST printing
updated accordingly.

Laurel-to-Core translator — Div/Mod/DivT/ModT now emit the safe operator
variants instead of the unchecked ones.

End-to-end tests — New DivisionByZeroCheckTest.lean verifies:
- Safe division with a known non-zero divisor passes ✅
- Division by an unconstrained parameter fails ❌
- A pure function with an explicit requires y != 0 precondition passes,
but callers that don't satisfy it fail ❌

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Extend PropertyType with a divisionByZero variant so that verification
results from safe division/modulo preconditions are distinguishable from
regular assertions. PrecondElim attaches a propertyType metadata tag
based on the function name (Int.SafeDiv*, Int.SafeMod*), which CmdEval
reads when creating proof obligations. The classification propagates to
both text output (Property: division by zero check) and SARIF output
(kind: division-by-zero).

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@tautschnig tautschnig force-pushed the tautschnig/classify-division-by-zero branch from 460165c to ed5408c Compare March 4, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant