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

Gas Optimizations

Unnecessary ERC20 transfer of fee to Fees.sol

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

Paying the protocol fee requires an ERC20 transfer. This modifies state and costs a considerable amount of gas. The Fee contract should be inherited by the Lender contract to reduce the necessary ERC20 transfers needed.

sellProfit() has unnecessary ERC20 transfer

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

The final ERC20 transfer to the staking contract in sellProfits can be removed. This is possible by setting the recipient of the Uniswap v3 router swap to the staking contract.

Redundant check in claim()

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

if (_diff > 0) is strictly unnecessary, because _balance is already guaranteed to be greater than balance, so _diff must be greater than 0.

Repeated mapping access expends extra gas

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

Accessing the same item from an array many times requires lookup cost each time. Instead pull the item into memory. This may be mitigated by compiler, but I am not aware of it.

Storage of loans as an array uses additional storage writes

Arrays in solidity are composed of a mapping and a length uint. Every time an item is added the length uint must be incremented in storage, costing gas. The length is not being used anywhere, except to assign id. The loans object should be changed to a mapping with id as the key, where id is a unique hash set by calldata.

Support

FAQs

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