Skip to content

Commit 3790c59

Browse files
Enable some math tests to be run by halmos (#5824)
Co-authored-by: ernestognw <[email protected]>
1 parent 1412f92 commit 3790c59

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

.github/workflows/formal-verification.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,5 @@ jobs:
8484
run: pip install -r fv-requirements.txt
8585
- name: Run Halmos
8686
run: halmos --match-test '^symbolic|^testSymbolic' -vv
87+
env:
88+
HALMOS_ALLOW_DOWNLOAD: 1

test/utils/Bytes.t.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ contract BytesTest is Test {
1414
}
1515

1616
// INDEX OF
17-
function testIndexOf(bytes memory buffer, bytes1 s) public pure {
17+
function testSymbolicIndexOf(bytes memory buffer, bytes1 s) public pure {
1818
uint256 result = Bytes.indexOf(buffer, s);
1919

2020
if (buffer.length == 0) {
@@ -48,7 +48,7 @@ contract BytesTest is Test {
4848
}
4949
}
5050

51-
function testLastIndexOf(bytes memory buffer, bytes1 s) public pure {
51+
function testSymbolicLastIndexOf(bytes memory buffer, bytes1 s) public pure {
5252
uint256 result = Bytes.lastIndexOf(buffer, s);
5353

5454
if (buffer.length == 0) {

test/utils/math/Math.t.sol

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ contract MathTest is Test {
1212
}
1313

1414
// ADD512 & MUL512
15-
function testAdd512(uint256 a, uint256 b) public pure {
15+
function testSymbolicAdd512(uint256 a, uint256 b) public pure {
1616
(uint256 high, uint256 low) = Math.add512(a, b);
1717

1818
// test against tryAdd
@@ -60,7 +60,8 @@ contract MathTest is Test {
6060
}
6161

6262
// CEILDIV
63-
function testCeilDiv(uint256 a, uint256 b) public pure {
63+
/// @custom:halmos --solver cvc5-int
64+
function testSymbolicCeilDiv(uint256 a, uint256 b) public pure {
6465
vm.assume(b > 0);
6566

6667
uint256 result = Math.ceilDiv(a, b);
@@ -112,17 +113,18 @@ contract MathTest is Test {
112113
_testInvMod(value, p, true);
113114
}
114115

115-
function testInvMod2(uint256 seed) public pure {
116+
function testSymbolicInvMod2(uint256 seed) public pure {
116117
uint256 p = 2; // prime
117118
_testInvMod(bound(seed, 1, p - 1), p, false);
118119
}
119120

120-
function testInvMod17(uint256 seed) public pure {
121+
function testSymbolicInvMod17(uint256 seed) public pure {
121122
uint256 p = 17; // prime
122123
_testInvMod(bound(seed, 1, p - 1), p, false);
123124
}
124125

125-
function testInvMod65537(uint256 seed) public pure {
126+
/// @custom:halmos --solver bitwuzla-abs
127+
function testSymbolicInvMod65537(uint256 seed) public pure {
126128
uint256 p = 65537; // prime
127129
_testInvMod(bound(seed, 1, p - 1), p, false);
128130
}

test/utils/math/SignedMath.t.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ contract SignedMathTest is Test {
4747
assertEq(result, (a + b) / 2);
4848
}
4949

50-
// 2. more complex test, full int256 range
51-
function testAverage2(int256 a, int256 b) public pure {
50+
// 2. more complex test, full int256 range (solver timeout 0 = no timeout)
51+
/// @custom:halmos --solver-timeout-assertion 0
52+
function testSymbolicAverage2(int256 a, int256 b) public pure {
5253
(int256 result, int256 min, int256 max) = (
5354
SignedMath.average(a, b),
5455
SignedMath.min(a, b),

0 commit comments

Comments
 (0)