Skip to content

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

Open
tautschnig wants to merge 6 commits intomainfrom
tautschnig/classify-division-by-zero
Open

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

Conversation

@tautschnig
Copy link
Contributor

@tautschnig tautschnig commented Mar 4, 2026

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.

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
@tautschnig tautschnig marked this pull request as ready for review March 4, 2026 21:25
@tautschnig tautschnig requested review from a team and Copilot March 4, 2026 21:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends Strata’s proof-obligation pipeline to distinguish division-by-zero precondition checks from ordinary assertions, and propagates that classification through verification and reporting (text + SARIF). It also introduces safe truncating division/mod operators and updates translation/parsing layers and tests accordingly.

Changes:

  • Add divisionByZero as a distinct PropertyType, and tag generated precondition asserts via metadata in PrecondElim, then decode it in CmdEval.
  • Emit the property classification in SARIF output and update SARIF-related tests/fixtures.
  • Add Int.SafeDivT / Int.SafeModT support across factories/SMT encoder/grammar/translation, and update expected outputs and end-to-end tests.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
StrataTest/Languages/Python/expected_laurel/test_arithmetic.expected Updates expected VC list to include SafeDiv precondition obligation.
StrataTest/Languages/Laurel/DivisionByZeroCheckTest.lean New end-to-end Laurel test covering safe vs unsafe division.
StrataTest/Languages/Core/SarifOutputTests.lean Updates expected SARIF JSON to include the new result classification field.
StrataTest/Languages/Core/ProgramTypeTests.lean Updates expected Core prelude/program types to include Int.SafeDivT/Int.SafeModT.
StrataTest/Languages/Core/ProcedureEvalTests.lean Updates expected procedure-eval environment/types for new safe truncating ops.
StrataTest/Languages/Core/Examples/NoFilterWFProc.lean Updates expected “Property:” rendering for SafeDiv-generated obligations.
StrataTest/Languages/Core/Examples/Loops.lean Updates expected property rendering for loop-related SafeDiv obligations.
StrataTest/Languages/Core/Examples/FunctionPreconditions.lean Updates expected property rendering for SafeDiv obligations in multiple examples.
StrataTest/DL/Lambda/TestGenTests.lean Updates expected operator factory list to include safe truncating ops.
Strata/Util/Sarif.lean Extends SARIF Result structure with a classification field (serialized as kind).
Strata/Transform/PrecondElim.lean Tags generated precondition asserts with propertyType metadata based on callee name.
Strata/Languages/Python/PythonToLaurel.lean Improves source-location propagation into translated Laurel statements/expressions.
Strata/Languages/Laurel/LaurelToCoreTranslator.lean Translates Laurel div/mod (incl. truncating) to Core safe operators.
Strata/Languages/Core/Verifier.lean Treats divisionByZero similarly to assert in preprocessing shortcuts.
Strata/Languages/Core/SarifOutput.lean Maps PropertyType to SARIF output classification string.
Strata/Languages/Core/SMTEncoder.lean Encodes Int.SafeDivT/Int.SafeModT using the same SMT encoding as truncating ops.
Strata/Languages/Core/Factory.lean Adds safe truncating ops to well-formedness factory and exposes operator expressions.
Strata/Languages/Core/DDMTransform/Translate.lean Adds translation support for truncating and safe truncating ops in the DDM layer.
Strata/Languages/Core/DDMTransform/Grammar.lean Extends grammar with /t, %t and explicit truncating operator forms.
Strata/Languages/Core/DDMTransform/ASTtoCST.lean Adds CST construction for the new truncating/safe truncating operator names.
Strata/DL/Lambda/IntBoolFactory.lean Defines Int.SafeDivT/Int.SafeModT with divisor-nonzero preconditions and registers them.
Strata/DL/Imperative/MetaData.lean Introduces propertyType metadata field + accessor.
Strata/DL/Imperative/EvalContext.lean Adds divisionByZero constructor to PropertyType and updates formatting.
Strata/DL/Imperative/CmdEval.lean Decodes propertyType metadata to set ProofObligation.property accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

tautschnig and others added 2 commits March 4, 2026 21:47
Move the property classification from the non-standard 'kind' field to
a SARIF-compliant 'properties' bag with a 'propertyType' entry. Rename
propertyTypeToRuleKind to propertyTypeToClassification to reflect its
updated purpose.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Use MetaData.getPropertyType in createUnreachableAssertObligations
instead of hardcoding PropertyType.assert, so that unreachable
division-by-zero checks retain their property classification.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@shigoel shigoel enabled auto-merge March 5, 2026 02:27
Copy link
Contributor

@shigoel shigoel left a comment

Choose a reason for hiding this comment

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

LGTM in general, but I'd like hard-coded/magic strings to go away.

tautschnig and others added 2 commits March 6, 2026 13:04
Add MetaData.divisionByZero constant and use MetaData.getPropertyType
accessor consistently across CmdEval, StatementEval, and PrecondElim,
eliminating magic strings for property type classification.

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

@shigoel shigoel left a comment

Choose a reason for hiding this comment

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

Thanks!

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.

3 participants