Skip to content

Commit 6243c93

Browse files
GUIpspclaude
andcommitted
Add soundness-hole test: int negative modulo
Verifier proves _ >= 0 for (-7) % 3, but Java yields -1. Root: makeMod uses Euclidean Z3 mkMod (TranslatorToZ3.java:344); Java % follows the sign of the dividend. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent f134911 commit 6243c93

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.Refinement;
4+
5+
// SOUNDNESS HOLE: integer `%` is translated to Z3's Euclidean modulo (result always >= 0),
6+
// but Java `%` takes the sign of the dividend. -7 % 3 == -1 in Java; the verifier models it as 2
7+
// and ACCEPTS "_ >= 0". At runtime -1 >= 0 is false. Should be rejected.
8+
@SuppressWarnings("unused")
9+
public class ErrorNegativeModuloUnsound {
10+
public static void main(String[] args) {
11+
@Refinement("a == -7")
12+
int a = -7;
13+
@Refinement("_ >= 0")
14+
int r = a % 3; // Refinement Error
15+
// runtime check mirrors the refinement; aborts under -ea because r == -1
16+
assert r >= 0 : "r=" + r;
17+
}
18+
}

0 commit comments

Comments
 (0)