20,000 USDC
View results
Submission Details
Severity: gas
Valid

`x += y` Costs More Gas Than `x = x + y`

Summary

Instead of using += to add an amount to a value, it's better to make it like: x = x + y

Vulnerability Details

Instances:

File: Lender.sol

  • pools[poolId].outstandingLoans += debt;

  • pools[poolId].outstandingLoans += totalDebt;

File: Staking.sol

  • balances[msg.sender] += _amount;

  • claimable[recipient] += _share;

Tools Used

None

Recommendations

Use instead:

  • pools[poolId].outstandingLoans = pools[poolId].outstandingLoans + debt;

  • pools[poolId].outstandingLoans = pools[poolId].outstandingLoans + totalDebt;

  • balances[msg.sender] = balances[msg.sender] + _amount;

  • claimable[recipient] = claimable[recipient] + _share;

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.