Skip to content
Business logic Audit finding Intermediate

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.

Anurag Jain Follow

Originally disclosed on Code4rena

Submitted by csanuragjain, also found by 0xf15ers and gzeon

https://github.com/Plex-Engineer/lending-market/blob/755424c1f9ab3f9f0408443e6606f94e4f08a990/contracts/CNote.sol#L129

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

  1. User is making a repayment which eventually calls repayBorrowFresh function
  2. Assuming repayAmount == type(uint).max, so repayAmountFinal becomes accountBorrowsPrev
  3. 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);

tkkwon1998 (Canto) confirmed

Alex the Entreprenerd (judge) decreased severity to Medium and commented:

The warden has showed how, due to an oversight, using type(uint).max to 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 actualRepayAmount or re-assigning the value of repayAmount


The original report as published on Code4rena, by csanuragjain. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. User initiates a repayment that calls repayBorrowFresh.
  2. User sets repayAmount to type(uint).max to indicate full repayment.
  3. 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.

More by Anurag Jain

View all

63 more disclosed reports, best first.

More from Canto

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.