You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Soundness: integer / and % use Z3's Euclidean semantics, not Java's, for negative operands #564
Impact: wrong programs pass verification (unsound) when integer division or remainder has a negative operand.
Description
Java's / on integers rounds toward zero, and % takes the sign of the dividend. Z3's integer div/mod, which TranslatorToZ3.makeDiv/makeMod use, are Euclidean: the remainder is never negative.
Java
Z3
-7 / 2
-3
-4
-7 % 2
-1
1
Minimal reproducer
importliquidjava.specification.Refinement;
publicclassDiv {
publicstaticvoidmain(String[] args) {
@Refinement("_ == -4") intq = -7 / 2; // Java gives -3: should be rejected@Refinement("_ == 1") intr = -7 % 2; // Java gives -1: should be rejected
}
}
Result on main: Correct! Passed Verification.
Expected
Both lines are rejected. / and % in refinements and in code should follow Java's semantics for all signs (truncation toward zero, remainder with the dividend's sign). Division by zero stays as it is today.
Found while looking at #536. That report itself is not a bug, since its program really is wrong, but it led here.
Activity