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

Use of magic numbers

Summary

Constants should be used instead of magic numbers.

Vulnerability Details

Use of constants is preferred over magic numbers. Even assembly can benefit from using readable constants instead of hex/numeric literals.
Instances:

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

    if (_fee > 5000) revert FeeTooHigh();

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

    if (_fee > 500) revert FeeTooHigh();

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

    uint256 loanRatio = (debt * 10 ** 18) / collateral;

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

       uint256 loanRatio = (totalDebt * 10 ** 18) / loan.collateral;

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

        uint256 govFee = (borrowerFee * loan.collateral) / 10000;

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

        uint256 loanRatio = (debt * 10 ** 18) / collateral;

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

            uint256 fee = (borrowerFee * (debt - debtToPay)) / 10000;

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

    interest = (l.interestRate * l.debt * timeElapsed) / 10000 / 365 days;

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

    fees = (lenderFee * interest) / 10000;

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

                uint256 _ratio = _diff * 1e18 / totalSupply;

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

          uint256 _share = _supplied * _delta / 1e18;

Impact

Use of constants improves the overall readability of the code.

Tools Used

Manual Review and VS Code

Recommendations

Use constants instead of magic numbers.

Support

FAQs

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