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

`<x> += <y>` costs more gas than `<x> = <x> + <y>` for state variables

Summary

<x> += <y> costs more gas than <x> = <x> + <y> for state variables

Vulnerability Details

Using the addition/subtraction operator instead of plus-equals/minus-equals saves 113 gas

Impact

There are 14 instances of this issue:

File: 2023-07-beedle/src/Lender.sol

264: pools[poolId].outstandingLoans += debt;
315: pools[poolId].outstandingLoans -= loan.debt;
389: pools[poolId].outstandingLoans += totalDebt;
401: pools[oldPoolId].outstandingLoans -= loan.debt;
491: pools[poolId].outstandingLoans += totalDebt;
503: pools[oldPoolId].outstandingLoans -= loan.debt;
576: pools[poolId].outstandingLoans -= loan.debt;
634: pools[oldPoolId].outstandingLoans -= loan.debt;
638: pools[poolId].outstandingLoans += debt;
699: pools[poolId].poolBalance -= debt;
727: interest -= fees;

File: 2023-07-beedle/src/Staking.sol

41: balances[msg.sender] += _amount;
48: balances[msg.sender] -= _amount;
89: claimable[recipient] += _share;

Tools Used

Automated code review.

Recommendations

Consider using <x> = <x> + <y> or <x> = <x> - <y> instead.

Support

FAQs

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