20,000 USDC
View results
Submission Details
Severity: gas

## [G-28] Use assembly for math (add, sub, mul, div)

Summary

[G-28] Use assembly for math (add, sub, mul, div)

Use assembly for math instead of Solidity. You can check for overflow/underflow in assembly to ensure safety. If using Solidity versions < 0.8.0 and you are using Safemath, you can gain significant gas savings by using assembly to calculate values and checking for overflow/underflow.

file: /src/Lender.sol
723 uint256 timeElapsed = block.timestamp - l.startTimestamp;
724 interest = (l.interestRate * l.debt * timeElapsed) / 10000 / 365 days;
725 fees = (lenderFee * interest) / 10000;

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

file: /src/Lender.sol
618 uint256 loanRatio = (debt * 10 ** 18) / collateral;

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

Support

FAQs

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