code-423n4 / 2021-10-tempus-findings

0 stars 0 forks source link

unchecked operations #35

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Handle

pauliax

Vulnerability details

Impact

Using the unchecked keyword to avoid redundant arithmetic underflow/overflow checks to save gas when an underflow/overflow cannot happen. E.g. 'unchecked' can be applied in the following lines of code since there are require statements before to ensure the arithmetic operations would not cause an integer underflow or overflow:

require(underlyingDecimals <= 18, "underlying decimals must be <= 18"); exchangeRateToBackingPrecision = 10**(18 - underlyingDecimals);

or if (sharesUsed[0] < mintedShares) { ammTokens[0].safeTransfer(msg.sender, mintedShares - sharesUsed[0]); } if (sharesUsed[1] < mintedShares) { ammTokens[1].safeTransfer(msg.sender, mintedShares - sharesUsed[1]); }

Recommended Mitigation Steps

Consider if you want to apply this keyword and then carefully select where it is safe to do this.

RedFox20 commented 2 years ago

The gas saving is very small, only ended up adding the one in AaveTempusPool Fixed in https://github.com/tempus-finance/tempus-protocol/pull/380

0xean commented 2 years ago

duplicate of #30