Skip to content
Business logic Audit finding Intermediate

Protocol doesn’t handle fee on transfer tokens

The protocol did not account for ERC20 tokens that charge a fee on transfer, so when a loan was funded with such a token, the second transfer could fail or the facilitator could lose funds. An attacker could not directly exploit this, but it could break core loan functionality or cause a loss for the lender or borrower.

0xDjango Follow

Originally disclosed on Code4rena

Submitted by 0xDjango, also found by cccz, csanuragjain, Dravee, IllIllI, robee, and Ruhum

NFTLoanFacilitator.sol#L155-L160

Since the borrower is able to specify any asset token, it is possible that loans will be created with tokens that support fee on transfer. If a fee on transfer asset token is chosen, the protocol will contain a point of failure on the original lend() call.

It is my belief that this is a medium severity vulnerability due to its ability to impact core protocol functionality.

Proof of Concept

For the first lender to call lend(), if the transfer fee % of the asset token is larger than the origination fee %, the second transfer will fail in the following code:

ERC20(loanAssetContractAddress).safeTransferFrom(msg.sender, address(this), amount);
uint256 facilitatorTake = amount * originationFeeRate / SCALAR;
ERC20(loanAssetContractAddress).safeTransfer(
    IERC721(borrowTicketContract).ownerOf(loanId),
    amount - facilitatorTake
);

Example:

  • originationFee = 2% Max fee is 5% per comments
  • feeOnTransfer = 3%
  • amount = 100 tokens
  • Lender transfers amount
  • NFTLoanFacilitator receives 97.
  • facilitatorTake = 2
  • NFTLoanFacilitator attempts to send 100 - 2 to borrower, but only has 97.
  • Execution reverts.

Other considerations:

If the originationFee is less than or equal to the transferFee, the transfers will succeed but will be received at a loss for the borrower and lender. Specifically for the lender, it might be unwanted functionality for a lender to lend 100 and receive 97 following a successful repayment (excluding interest for this example).

Recommended Mitigation Steps

Since the originationFee is calculated based on the amount sent by the lender, this calculation will always underflow given the example above. Instead, a potential solution would be to calculate the originationFee based on the requested loan amount, allowing the lender to send a greater value so that feeOnTransfer <= originationFee.

Oppositely, the protocol can instead calculate the amount received from the initial transfer and use this amount to calculate the originationFee. The issue with this option is that the borrower will receive less than the desired loan amount.

wilsoncusack (Backed Protocol) commented:

If amount - origination_fee - token_fee < 0, then yeah you will not be able to underwrite to loan. But that would be a huge fee.

wilsoncusack (Backed Protocol) commented:

Discussed more with warden 0xDjango, if the token even has a 1% fee then the second transfer will fail OR we will leak facilitator funds, although this is sort of impossible because currently none of the transactions with these fee on transfer tokens will work.

wilsoncusack (Backed Protocol) acknowledged and commented:

This issue is slightly different from others that just point out that borrowers will get amount - token_fee. The only one I have seen, I think, to point out that fulfilling loans with fee on transfer tokens is impossible.

Imagine a token that takes 1% on transfer. Amount = 100 99 reaches facilitator facilitator transfers 100 - facilitator take = 99 to the borrower. Facilitator gets nothing Borrower gets 98.

If the facilitator take is greater or the fee on transfer take is greater, it won’t work at all.

Med severity is maybe right given we can miss out on origination fees?

wilsoncusack (Backed Protocol) confirmed and resolved

gzeon (judge) commented:

Sponsor confirmed with fix.


The original report as published on Code4rena, by 0xDjango. 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 calculated the origination fee from the nominal loan amount without checking the actual balance received after a fee-on-transfer token deducted its fee.

Impact

Loans using fee-on-transfer tokens could fail entirely, or if the fee is small, the facilitator could lose funds and the borrower receive less than requested; the sponsor noted that currently no such transactions work.

What the attacker needed

Borrower specifies a fee-on-transfer token; lender funds the loan

The fix

The protocol was fixed after the sponsor confirmed the issue.

How it was found

  1. A borrower creates a loan request specifying a fee-on-transfer token as the asset.
  2. The first lender calls lend() and transfers the loan amount.
  3. The protocol receives less than the full amount due to the token's transfer fee.
  4. The protocol attempts to send the loan amount minus the origination fee to the borrower.
  5. The transfer fails because the contract's balance is insufficient, reverting the transaction.

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.

Some digital tokens take a small cut every time they are sent, like a bank fee. This protocol assumed tokens arrive in full, so when it tried to pass the loan amount to the borrower, it did not have enough left and the transaction failed. This meant loans using such tokens could not work, and if the fee was small, the protocol might lose money.

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 0xDjango

View all

23 more disclosed reports, best first.

More from Papr contest

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.