Skip to content
Business logic Audit finding Intermediate

If the collateral is a fee-on-transfer token, repayment will be blocked

The contract records the full amount of collateral deposited, but fee-on-transfer tokens cause the actual received amount to be less. When the borrower repays, the contract tries to withdraw the recorded amount, which exceeds the actual balance, causing the transaction to revert and blocking repayment.

0x2e Follow with 8olidity, BAHOZ and 32 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-03-teller-judging/issues/91

Found by

0x2e, 8olidity, BAHOZ, Bauer, Breeje, Delvir0, HexHackers, HonorLt, MiloTruck, Nyx, Vagner, __141345__, ak1, cccz, cducrest-brainbot, ck, ctf_sec, dacian, deadrxsezzz, dingo, duc, evmboi32, giovannidisiena, innertia, monrel, n33k, nobody2018, saidam017, shaka, sinarette, spyrosonic10, tsvetanovv, tvdung94, whiteh4t9527, yixxas

Summary

As we all know, some tokens will deduct fees when transferring token. In this way, the actual amount of token received by the receiver will be less than the amount sent. If the collateral is this type of token, the amount of collateral recorded in the contract will bigger than the actual amount. When the borrower repays the loan, the amount of collateral withdrawn will be insufficient, causing tx revert.

Vulnerability Detail

The _bidCollaterals mapping of CollateralManager records the CollateralInfo of each bidId. This structure records the collateral information provided by the user when creating a bid for a loan. A lender can accept a loan by calling  TellerV2.lenderAcceptBid that will eventually transfer the user's collateral from the user address to the CollateralEscrowV1 contract corresponding to the loan. The whole process will deduct fee twice.

Solidity
//CollateralManager.sol
function _deposit(uint256 _bidId, Collateral memory collateralInfo)
        internal
        virtual
    {
        ......
        // Pull collateral from borrower & deposit into escrow
        if (collateralInfo._collateralType == CollateralType.ERC20) {
            IERC20Upgradeable(collateralInfo._collateralAddress).transferFrom(	//transferFrom first time
                borrower,
                address(this),
                collateralInfo._amount
            );
            IERC20Upgradeable(collateralInfo._collateralAddress).approve(
                escrowAddress,
                collateralInfo._amount
            );
            collateralEscrow.depositAsset(		//transferFrom second time
                CollateralType.ERC20,
                collateralInfo._collateralAddress,
                collateralInfo._amount,			//this value is from user's input
                0
            );
        }
        ......
    }

The amount of collateral recorded by the CollateralEscrowV1 contract is equal to the amount originally submitted by the user.

When the borrower repays the loan, collateralManager.withdraw will be triggered. This function internally calls CollateralEscrowV1.withdraw. Since the balance of the collateral in the CollateralEscrowV1 contract is less than the amount to be withdrawn, the entire transaction reverts.

Solidity
//CollateralEscrowV1.sol
function _withdrawCollateral(
        Collateral memory _collateral,
        address _collateralAddress,
        uint256 _amount,
        address _recipient
    ) internal {
        // Withdraw ERC20
        if (_collateral._collateralType == CollateralType.ERC20) {
            IERC20Upgradeable(_collateralAddress).transfer(   //revert
                _recipient,
                _collateral._amount	//_collateral.balanceOf(address(this)) < _collateral._amount
            );
        }
    ......
    }

Impact

The borrower's collateral is stuck in the instance of CollateralEscrowV1. Non-professional users will never know that they need to manually transfer some collateral into CollateralEscrowV1 to successfully repay.

  • This issue blocked the user's repayment, causing the loan to be liquidated.
  • The liquidator will not succeed by calling TellerV2.liquidateLoanFull.

Code Snippet

https://github.com/sherlock-audit/2023-03-teller/blob/main/teller-protocol-v2/packages/contracts/contracts/TellerV2.sol#L323-L326

https://github.com/sherlock-audit/2023-03-teller/blob/main/teller-protocol-v2/packages/contracts/contracts/CollateralManager.sol#L432-L434

https://github.com/sherlock-audit/2023-03-teller/blob/main/teller-protocol-v2/packages/contracts/contracts/TellerV2.sol#L510

https://github.com/sherlock-audit/2023-03-teller/blob/main/teller-protocol-v2/packages/contracts/contracts/CollateralManager.sol#L327-L341

https://github.com/sherlock-audit/2023-03-teller/blob/main/teller-protocol-v2/packages/contracts/contracts/escrow/CollateralEscrowV1.sol#L73

https://github.com/sherlock-audit/2023-03-teller/blob/main/teller-protocol-v2/packages/contracts/contracts/escrow/CollateralEscrowV1.sol#L166-L169

Tool used

Manual Review

Recommendation

Two ways to fix this issue.

  • The afterBalance-beforeBalance method should be used when recording the amount of collateral.
Diff
         --- a/teller-protocol-v2/packages/contracts/contracts/escrow/CollateralEscrowV1.sol
         +++ b/teller-protocol-v2/packages/contracts/contracts/escrow/CollateralEscrowV1.sol
         @@ -165,7 +165,7 @@ contract CollateralEscrowV1 is OwnableUpgradeable, ICollateralEscrowV1 {
                  if (_collateral._collateralType == CollateralType.ERC20) {
                      IERC20Upgradeable(_collateralAddress).transfer(
                          _recipient,
         -                _collateral._amount
         +                IERC20Upgradeable(_collateralAddress).balanceOf(address(this))
                      );
                  }
 ```



## Discussion

**ethereumdegen**

This is the same as the issue that I explained in the readme for this contest about 'poisoned collateral'. It has been known previously that collateral in the escrow could be made non-transferrable which makes loan repayment impossible. Thank you for the report.  Thisis a re-iteration of what was stated as 'known issues' in the contest readme. 

**iamjakethehuman**

Escalate for 10 USDC 
Disagree with sponsor's comment. This is not the case described in the Readme. The Readme states:
> A: Known issue 1: Collateral assets that can be 'paused' for transfer do exhibit a risk since they may not be able to be withdrawn from the loans as collateral. Furthermore, collateral assets that can be made non-transferrable can actually 'poison' a collateral vault and make a loan non-liquidateable since a liquidateLoan call would revert.

The contest FAQ states:
> FEE-ON-TRANSFER: any

The project clearly hasn't implemented logic for fee-on-transfer tokens when it has clearly stated that it should be able to operate with such tokens.
Would love to hear judge's opinion on this.

**sherlock-admin**

> Escalate for 10 USDC 
> Disagree with sponsor's comment. This is not the case described in the Readme. The Readme states:
> > A: Known issue 1: Collateral assets that can be 'paused' for transfer do exhibit a risk since they may not be able to be withdrawn from the loans as collateral. Furthermore, collateral assets that can be made non-transferrable can actually 'poison' a collateral vault and make a loan non-liquidateable since a liquidateLoan call would revert.
> 
> The contest FAQ states:
> > FEE-ON-TRANSFER: any
> 
> The project clearly hasn't implemented logic for fee-on-transfer tokens when it has clearly stated that it should be able to operate with such tokens.
> Would love to hear judge's opinion on this.

You've created a valid escalation for 10 USDC!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

**securitygrid**

According to README.md:
Collateral should not be able to be permanently locked/burned in the contracts. 
So this issue is valid M.

**Love4codes**

yeah, i second it's a valid M.
Let's see the judges opinion tho

**ethereumdegen**

Github PR: [Issue 225 - Separate logic for repay and collateral withdraw](https://github.com/teller-protocol/teller-protocol-v2/pull/69)

**hrishibhat**

Escalation accepted

Valid medium
This issue is a valid medium as fee-on-transfer tokens are in scope.

**sherlock-admin**

> Escalation accepted
> 
> Valid medium
> This issue is a valid medium as fee-on-transfer tokens are in scope.

 This issue's escalations have been accepted!

 Contestants' payouts and scores will be updated according to the changes made on this issue.

**IAm0x52**

Fix looks good. Repaying a loan in full no longer forces withdrawing collateral, preventing the repay call from reverting

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

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

Likely the contract records the nominal collateral amount instead of the actual received balance, so fee-on-transfer tokens cause a mismatch between recorded and actual collateral.

Impact

The borrower's collateral is stuck, repayment is blocked, and the loan may be liquidated; liquidation also fails.

What the attacker needed

Collateral is a fee-on-transfer token; borrower creates a bid with such collateral; lender accepts the bid

The fix

The fix was to separate repay and collateral withdraw logic so that repaying a loan in full no longer forces withdrawing collateral.

How it was found

  1. A borrower creates a bid with a fee-on-transfer token as collateral.
  2. A lender accepts the bid, and the collateral is transferred to the escrow contract, which deducts fees twice.
  3. The escrow contract records the full nominal amount as collateral.
  4. When the borrower repays the loan, the contract attempts to withdraw the recorded amount, but the actual balance is less, causing a revert.

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 tokens take a fee when transferred, so the receiver gets less than the sender sent. This contract records the full amount as collateral, but the actual balance is lower. When the borrower tries to repay, the contract attempts to return more collateral than it holds, so the repayment fails and the loan cannot be closed.

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

View all

2 more disclosed reports, best first.

More from Teller

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.