Skip to content

Commit a6c5b85

Browse files
GUIpspclaude
andcommitted
Add soundness-hole test: long division truncation
Verifier proves _ > 3 for 7L / 2L, but Java truncates to 3. Root: long is modeled as a Z3 Real (TranslatorContextToZ3.java:96; makeLongLiteral :106), so division is exact and rational (makeDiv:336). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6243c93 commit a6c5b85

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package testSuite;
2+
3+
import liquidjava.specification.Refinement;
4+
5+
// SOUNDNESS HOLE: Java `long` is modeled as a Z3 Real, so `/` becomes exact rational
6+
// division instead of truncating integer division. 7L / 2L == 3 in Java, but the verifier
7+
// models it as 3.5 and ACCEPTS "_ > 3". At runtime 3 > 3 is false. Should be rejected.
8+
@SuppressWarnings("unused")
9+
public class ErrorLongAsRealDivisionUnsound {
10+
public static void main(String[] args) {
11+
@Refinement("c == 7")
12+
long c = 7L;
13+
@Refinement("d == 2")
14+
long d = 2L;
15+
@Refinement("_ > 3")
16+
long e = c / d; // Refinement Error
17+
// runtime check mirrors the refinement; aborts under -ea because e == 3
18+
assert e > 3 : "e=" + e;
19+
}
20+
}

0 commit comments

Comments
 (0)