Increments/decrements can be unchecked in for-loops #27
Labels
Report Status: Recommended
Severity: Gas Optimization
Suggestion made by the team to improve protocol
Context
VaultBorrowRate::getBorrowRate()
LiquidationRouter::collaterals()
Description
In Solidity 0.8+, there's a default overflow check on unsigned integers. It's possible to uncheck this in for-loops and save some gas at each iteration, but at the cost of some code readability, as this uncheck cannot be made inline.
ethereum/solidity#10695
The change would be:
These save around 25 gas saved per instance.
The same can be applied with decrements (which should use
break
wheni == 0
).The risk of overflow is non-existent for
uint256
.The text was updated successfully, but these errors were encountered: