Loans charge simple interest based on the interestRate parameter in the pool.
However when a loan is transferred via giveLoan(), the debt over which the interest is charged is increased.
First totalDebt is calculated by adding the interest and protocol interest
uint256 totalDebt = loan.debt + lenderInterest + protocolInterest;
Then the original debt is overwritten by totalDebt:
loans[loanId].debt = totalDebt;
That means that the interest in this point is calculated based on debt+lenderInterest+protocolInterest
rather than the debt when the loan was initialized. This means that the debt is COMPOUNDED every time it is transferred via giveLoan()
compared to the lower simpleInterest charged when the loan is never transferred.
There is a code POC below:
The below code POC compares 2 scenarios:
In secnario without_giveLoan
, the borrower has a loan for 2 years, interest rate at 10%.
Lender makes no transfers
Borrower repays the loan
Result: They borrower pays 1.2x their original deposit, so end up paying 20% interest.
In scenario 2:
In secnario with_giveLoan
, the borrower has a loan for 2 years, interest rate at 10%.
Lender gives the loan to another account, lender2, 1 year in
The borrower repays the laon
Result: The borrower pays 1.21x their original deposit, they paid 10% the first year and 10% of 1.1x their original deposit the second year. They have paid compound interest instead!
This can be exacerbated if there are multiple calls to giveLoan() interspersed over that period, the interest is re-compounded every time it is called.
The loaner can giveLoan() to their other account to change their loan from Simple Interest to Compound Interest, effectively overcharging their interest
Foundry
Do not change the lender debt over which interest is charged when giveLoan() is called, while also ensuring that the debt is tracked correctly.
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.