Omniscia Astrolab DAO Audit

AsMaths Manual Review Findings

AsMaths Manual Review Findings

AMS-01M: Improper Absolute Function Implementation

Description:

The AsMaths::abs function is expected to yield the absolute value of the input int256 number in its uint256 representation, however, in doing so the function will not properly handle the value type(int256).min even though it is representable by the uint256 the conversion occurs to.

This is due to the fact that all signed integers have one less value in the positive range as a result of the bit signifying the polarity of the number.

Impact:

As the code would simply revert instead of yielding a corrupt value, we consider its severity to be informational.

Example:

src/libs/AsMaths.sol
242/**
243 * @notice Get the absolute value of a signed integer
244 * @param x The input signed integer
245 * @return The absolute value of the input
246 */
247function abs(int256 x) internal pure returns (uint256) {
248 return uint256(x > 0 ? x : -x);
249}

Recommendation:

We advise a conditional to be introduced, ensuring that uint256(type(int256).max) + 1 is yielded if the input x is equal to the type(int256).min value.

Alleviation (59b75fbee1d8f3dee807c928f18be41c58b904e1):

The case of x being equivalent to type(int256).min is now adequately handled by the AsMaths::abs function, ensuring that the value is calculated safely for all possible inputs.