a. The math for calculating the loanRatio allows for precision loss in favour of the borrower.
b. Another issue with it is that the hard coded decimal of 10 ** 18 could cause the lending protocol to require more or less collateral than intended.
a. The EVM does not allow for floating point values so all divisions are rounded down. The math for calculating the loanRatio essentially boils down to debt / collateral. We can say the multiplication by 10 ** 18 is there to ensure that the result retains the correct decimal after division.
Given the premise above, let's walk through an example without the multiplication by 10 ** 18. Say the maxLoanRatio = 2, and a borrower wants to get debt = 100 with collateral = 49. The loanRatio is 100 / 49 = 2.0408 which is above the maxLoanRatio of 2 and should fail. It will however pass because solidity will round it down to 2.
b. By assuming that the decimal for the collateral token is always going to be 10 ** 18, if the actual decimal is more e.g 10 ** 20, it allows the borrower to deposit less collateral than expected by the lender, potentially beating the maxLoanRation and vice versa
a. The loss of precision allows for under collateralised loans.
b. Borrower can use less collateral than what's provided in the maxLoanRatio or borrowers would be required to pay more collateral than lender expected or borrowers would only be able to get less loan than the lender would have expected.
None. it's simple enough.
Foundry
A better way to do the comparison would be to replace all occurrences of
with
It has the advantage of having divisions work in favour of the lender and handles basis conversion when both tokens have different decimals. The borrower must have enough collateral before they pass that check.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.