Omniscia rain protocol Audit

SaturatingMath Code Style Findings

SaturatingMath Code Style Findings

SMH-01C: Deviation of Comment Style

Description:

The functions denoted by SaturatingMath define their return data types as the "maximum" between two values yet the @return of saturatingSub is defined as a sentence.

Example:

contracts/math/SaturatingMath.sol
15/// Saturating addition.
16/// @param a_ First term.
17/// @param b_ Second term.
18/// @return Minimum of a_ + b_ and max uint256.
19function saturatingAdd(uint256 a_, uint256 b_)
20 internal
21 pure
22 returns (uint256)
23{
24 unchecked {
25 uint256 c_ = a_ + b_;
26 return c_ < a_ ? type(uint256).max : c_;
27 }
28}
29
30/// Saturating subtraction.
31/// @param a_ Minuend.
32/// @param b_ Subtrahend.
33/// @return a_ - b_ if a_ greater than b_, else 0.
34function saturatingSub(uint256 a_, uint256 b_)
35 internal
36 pure
37 returns (uint256)
38{
39 unchecked {
40 return a_ > b_ ? a_ - b_ : 0;
41 }
42}
43
44/// Saturating multiplication.
45/// @param a_ First term.
46/// @param b_ Second term.
47/// @return Minimum of a_ * b_ and max uint256.
48function saturatingMul(uint256 a_, uint256 b_)
49 internal
50 pure
51 returns (uint256)
52{
53 unchecked {
54 // Gas optimization: this is cheaper than requiring 'a' not being
55 // zero, but the benefit is lost if 'b' is also tested.
56 // https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
57 if (a_ == 0) return 0;
58 uint256 c_ = a_ * b_;
59 return c_ / a_ != b_ ? type(uint256).max : c_;
60 }
61}

Recommendation:

We advise the same paradigm to be utilized by stating that the minimum between a_ - b_ and 0 is yielded by the function.

Alleviation:

The linked documentation was updated in accordance with the documentation style of the rest of the contract.