Skip to content

Commit

Permalink
docs: document integer overflow in MathExt
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhwu committed Oct 3, 2024
1 parent ac1d68e commit 9592956
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/MathExt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ library MathExt {
/// @param min The minimum bound for the result.
/// @param max The maximum bound for the result.
/// @return r The result of the bounded addition.
/// @dev This function reverts when `b == type(int256).min` due to integer overflow.
function boundedAdd(uint256 a, int256 b, uint256 min, uint256 max) internal pure returns (uint256 r) {
r = boundedSub(a, 0 - b, min, max);
}
Expand All @@ -33,6 +34,7 @@ library MathExt {
/// @param min The minimum bound for the result.
/// @param max The maximum bound for the result.
/// @return r The result of the bounded subtraction.
/// @dev This function reverts when `b == type(int256).min` due to integer overflow.
function boundedSub(uint256 a, int256 b, uint256 min, uint256 max) internal pure returns (uint256 r) {
if (b < 0) {
// If b is negative, add its absolute value to a
Expand Down

0 comments on commit 9592956

Please sign in to comment.