Skip to content
Business logic Audit finding Intermediate

Complete debt size is not paid off for fee on transfer tokens, but users aren't warned

The protocol's full-debt repayment feature silently fails for fee-on-transfer tokens because the transferred amount is reduced by the fee, leaving a residual debt. An attacker could exploit this to trick users into believing their loan is fully repaid while interest continues to accrue.

tsvetanovv Follow with rvierdiiev, Avci and 4 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-02-blueberry-judging/issues/153

Found by

tsvetanovv, rvierdiiev, Avci, obront, chaduke, berndartmueller, Breeje

Summary

The protocol seems to be intentionally catering to fee on transfer tokens by measuring token balances before and after transfers to determine the value received. However, the mechanism to pay the full debt will not succeed in paying off the debt if it is used with a fee on transfer token.

Vulnerability Detail

The protocol is clearly designed to ensure it is compatible with fee on transfer tokens. For example, all functions that receive tokens check the balance before and after, and calculate the difference between these values to measure tokens received:

Solidity
function doERC20TransferIn(address token, uint256 amountCall)
    internal
    returns (uint256)
{
    uint256 balanceBefore = IERC20Upgradeable(token).balanceOf(
        address(this)
    );
    IERC20Upgradeable(token).safeTransferFrom(
        msg.sender,
        address(this),
        amountCall
    );
    uint256 balanceAfter = IERC20Upgradeable(token).balanceOf(
        address(this)
    );
    return balanceAfter - balanceBefore;
}

There is another feature of the protocol, which is that when loans are being repaid, the protocol gives the option of passing type(uint256).max to pay your debt in full:

Solidity
if (amountCall == type(uint256).max) {
    amountCall = oldDebt;
}

However, these two features are not compatible. If a user paying off fee on transfer tokens passes in type(uint256).max to pay their debt in full, the full amount of their debt will be calculated. But when that amount is transferred to the contract, the amount that the result increases will be slightly less. As a result, the user will retain some balance that is not paid off.

Impact

The feature to allow loans to be paid in full will silently fail when used with fee on transfer tokens, which may trick users into thinking they have completely paid off their loans, and accidentally maintaining a balance.

Code Snippet

https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/BlueBerryBank.sol#L760-L775

Tool used

Manual Review

Recommendation

I understand that it would be difficult to implement a mechanism to pay fee on transfer tokens off in full. That adds a lot of complexity that is somewhat fragile.

The issue here is that the failure is silent, so that users request to pay off their loan in full, get confirmation, and may not realize that the loan still has an outstanding balance with interest accruing.

To solve this, there should be a confirmation that any user who passes type(uint256).max has paid off their debt in full. Otherwise, the function should revert, so that users paying fee on transfer tokens know that they cannot use the "pay in full" feature and must specify the correct amount to get their outstanding balance down to zero.

The original report as published on Sherlock, by tsvetanovv. 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 full-repayment logic sets the repayment amount to the entire debt but does not verify that the received amount (after transfer fees) actually clears the debt, so any shortfall remains silently.

What the attacker needed

Protocol supports fee-on-transfer tokens; user repays with type(uint256).max

The fix

The function should verify that the debt is fully cleared after a full-repayment attempt and revert if any balance remains, so users know they must specify an exact amount.

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 small fee when transferred, so the receiver gets less than the sender sent. This protocol tries to support such tokens by checking the actual balance change, but its 'pay full debt' option still assumes the full amount arrives. As a result, a user who thinks they cleared their loan may still owe a little, and interest keeps growing on that leftover amount.

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 tsvetanovv

View all

3 more disclosed reports, best first.

More from Blueberry Update #3

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.