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

Incorrect formula for `loanRatio`

Summary

Incorrect formula for loanRatio, which would break accounting.

Vulnerability Details

The loanRatio in Lender.sol is currently calculated as follows:

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

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

The formula assumes that both debt and collateral tokens have the same decimals of 10**18.

In the case where:

  • Debt and collateral token have different decimals

  • Debt and / or collateral token does not have 18 decimals (e.g. USDC, USDT)

The formula will lead to an incorrect accounting of loanRatio.

Impact

This breaks the accounting of the protocol.

Tools Used

Manual review.

Recommendations

Tokens should be scaled according to the number of decimals they have.

Support

FAQs

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

Give us feedback!