You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Lender.borrow() #232 for (uint256 i = 0; i < borrows.length; i++) {
Lender.repay() #292 for (uint256 i = 0; i < loanIds.length; i++) {
Lender.giveLoan() #355 for (uint256 i = 0; i < loanIds.length; i++) {
Lender.startAuction() #437 for (uint256 i = 0; i < loanIds.length; i++) {
Lender.seizeLoan() #548 for (uint256 i = 0; i < loanIds.length; i++) {
Lender.refinance() #591 for (uint256 i = 0; i < refinances.length; i++) {
Tools Used
Manual
Recommendations
The code would go from:
for (uint256 i = 0; i < [].length; i++) {
// ...
}
to
for (uint256 i = 0; i < [].length;) {
// ...
unchecked { i++; }
}
The text was updated successfully, but these errors were encountered:
Increments can be unchecked
Severity
Gas Optimization
Relevant GitHub Links
ethereum/solidity#10695
Summary
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.
Vulnerability Details
https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol
Instances included:
Tools Used
Manual
Recommendations
The code would go from:
to
The text was updated successfully, but these errors were encountered: