Closed c4-bot-1 closed 9 months ago
0xSorryNotSorry marked the issue as sufficient quality report
0xSorryNotSorry marked the issue as duplicate of #700
Trumpero marked the issue as unsatisfactory: Invalid
Hi @Trumpero I think this issue was wrongly duplicated with #700. I respectfully disagree that this issue is invalid since it was duplicated with an issue that shows that the openingFee is charged multiple times. However, this particular issue highlights that an excess amount of openingFee is being charged, rather than multiple times which can be seen from the PoC.
Here is an another example: Term with 0% APR, 5% open fee
After repayment, loan principal = 530, and the getLoanDebt() should return 550 because 530 is the principle and since we pay 30 openingFee with the first partialRepay, there must be only 20 openingFee left. However, the getLoanDebt() returns 556.5.
@MariinaKP I believe your calculation is incorrect because of rounding down. In the above case:
After repayment, loan pricipal = 524 -> opening fee left = 26 -> total opening fee is still 50
It can be easily proven by the code that the total principal repaid of a loan equals the initial borrowed amount. Since the borrowed amount decreases with each principal repayment, the total opening fee remains unchanged.
Lines of code
https://github.com/code-423n4/2023-12-ethereumcreditguild/blob/2376d9af792584e3d15ec9c32578daa33bb56b43/src/loan/LendingTerm.sol#L226
Vulnerability details
Impact
openingFee
is a fee charged once when opening a loan. When repaying a loan, thegetLoanDebt()
is called and theopeningFee
calculations are made and added to theloanDept
. It is added every time a user repays which does not seems to be a problem however when a user is partially repaying the accumulated fee is more then if he repayed it at once.If we assume a user first partial repay his loan, in the
_partialRepay()
a % of the repaid amount is transferred for the protocol for the fee. After time if he partial repay again, thegetLoanDebt()
calculates again theopeningFee
for the new borrowAmount(as it was decreased from the first repay), however more fee is calculated than expected.Proof of Concept
Paste the following test inside
test/unit/loan/LendingTerm.t.sol.
Tools Used
Manual Review
Recommended Mitigation Steps
Charge the opening fee inside the
borrow()
when opening a loan.Assessed type
Other