Gravita-Protocol / Gravita-SmartContracts

GNU General Public License v3.0
48 stars 31 forks source link

[PFD-01C] Ineffectual Usage of Safe Arithmetics #378

Closed 0xfornax closed 1 year ago

0xfornax commented 1 year ago

PFD-01C: Ineffectual Usage of Safe Arithmetics

Type Severity Location
Language Specific PriceFeed.sol:L173, L175

Description:

The linked mathematical operations are guaranteed to be performed safely by surrounding conditionals evaluated in either require checks or if-else constructs.

Example:

    if (_priceDigits > TARGET_DIGITS) {
        return _price / (10 ** (_priceDigits - TARGET_DIGITS));
    } else if (_priceDigits < TARGET_DIGITS) {
        return _price * (10 ** (TARGET_DIGITS - _priceDigits));
    }
    return _price;
}

Recommendation:

Given that safe arithmetics are toggled on by default in pragma versions of 0.8.X, we advise the linked statements to be wrapped in unchecked code blocks thereby optimizing their execution cost.

0xfornax commented 1 year ago

Fixed.