Skip to content

Commit

Permalink
fuzzing
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Feb 4, 2025
1 parent c2cee62 commit 7f4f5e7
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/utils/math/Math.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,29 @@ contract MathTest is Test {
assertEq(Math.ternary(f, a, b), f ? a : b);
}

// ADD512 & MUL512
function testAdd512(uint256 a, uint256 b) public pure {
(uint256 high, uint256 low) = Math.add512(a, b);
(bool success, uint256 result) = Math.tryAdd(a, b);
if (success) {
assertEq(high, 0);
assertEq(low, result);
} else {
assertEq(high, 1);
}
}

function testMul512(uint256 a, uint256 b) public pure {
(uint256 high, uint256 low) = Math.mul512(a, b);
(bool success, uint256 result) = Math.tryMul(a, b);
if (success) {
assertEq(high, 0);
assertEq(low, result);
} else {
assertGt(high, 0);
}
}

// MIN & MAX
function testSymbolicMinMax(uint256 a, uint256 b) public pure {
assertEq(Math.min(a, b), a < b ? a : b);
Expand Down

0 comments on commit 7f4f5e7

Please sign in to comment.