Incorrect amount taken
The repayBorrowFresh function transfers repayAmount instead of repayAmountFinal, so when a user repays with type(uint).max to indicate a full repayment, the contract attempts to transfer an excessive amount. This could lead to loss of user funds if the transfer succeeds, but in practice it reverts.
Originally disclosed on Code4rena
Submitted by csanuragjain, also found by 0xf15ers and gzeon
It was observed that in repayBorrowFresh function, User is asked to send repayAmount instead of repayAmountFinal. This can lead to loss of user funds as user might be paying extra
Proof of Concept
- User is making a repayment which eventually calls repayBorrowFresh function
- Assuming repayAmount == type(uint).max, so repayAmountFinal becomes accountBorrowsPrev
- This means User should only transfer in accountBorrowsPrev instead of repayAmount but that is not true. Contract is transferring repayAmount instead of repayAmountFinal as seen at CNote.sol#L129
uint actualRepayAmount = doTransferIn(payer, repayAmount);
Recommended Mitigation Steps
Revise CNote.sol#L129 to below:
uint actualRepayAmount = doTransferIn(payer, repayAmountFinal);
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
The warden has showed how, due to an oversight, using
type(uint).maxto signify a complete repayment will actually attempt to transfer 2^256-1 units of token.While I think High severity would have been reasonable had the tokens gotten transferred, because what will actually happen is a revert, I think Medium Severity to be more appropriate.
Remediation requires using
actualRepayAmountor re-assigning the value ofrepayAmount
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The code uses the wrong variable (repayAmount instead of repayAmountFinal) when transferring tokens, so the full repayment sentinel value is not replaced with the actual amount owed.
Impact
The user could lose funds if the excessive transfer succeeds, but the judge noted that the transfer would actually revert, limiting the impact to a denial of service or failed transaction.
What the attacker needed
User repays with type(uint).max; Sufficient token balance and allowance
The fix
The code should be fixed by using repayAmountFinal (or actualRepayAmount) in the transfer call instead of repayAmount.
How it was found
- User initiates a repayment that calls repayBorrowFresh.
- User sets repayAmount to type(uint).max to indicate full repayment.
- The contract computes repayAmountFinal as accountBorrowsPrev but transfers repayAmount instead.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you repay a loan, you can say 'take everything I owe' by using a very large number. The code mistakenly tries to take that huge number instead of just what you owe, which would fail and could cost you extra fees or cause problems.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.