Omniscia Native Audit

SafeCast Code Style Findings

SafeCast Code Style Findings

SCT-01C: Optimization of Check Legibility

TypeSeverityLocation
Code StyleSafeCast.sol:L25

Description:

The check is meant to evaluate that the y value can be retained within the bounds of the int256 data type, however, it performs this validation using value literals.

Example:

contracts/libraries/SafeCast.sol
21/// @notice Cast a uint256 to a int256, revert on overflow
22/// @param y The uint256 to be casted
23/// @return z The casted integer, now type int256
24function toInt256(uint256 y) internal pure returns (int256 z) {
25 require(y < 2 ** 255);
26 z = int256(y);
27}

Recommendation:

We advise the type(int256).max specification to be utilized instead and a less-than-or-equal-to (<=) comparator, optimizing the legibility of the contract.

Alleviation:

The referenced require check was enhanced to utilize the type(int256).max value and now contains an adequate error message, alleviating this exhibit.