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> will cost more gas than <x> = <x> + <y> for state variables. Similarly, <x> -= <y> will cost more than <x> = <x> - <y>.

Vulnerability Details

Instances:

https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol#L263

        pools[poolId].outstandingLoans += debt;

https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol#L388

        pools[poolId].outstandingLoans += totalDebt;

https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol#L490

    pools[poolId].outstandingLoans += totalDebt;

https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol#L637

        pools[poolId].outstandingLoans += debt;

Impact

<x> = <x> + <y> saves more gas than <x> += <y>.

Tools Used

Manual review

Recommendations

Use <x> = <x> + <y> wherever possible instead of using <x> += <y>.

Support

FAQs

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