Skip to content
Business logic Audit finding Advanced

Wrong implementation of TurboSafe.sol#less() may cause boosted record value in TurboMaster bigger than actual lead to BoostCapForVault and BoostCapForCollateral to be permanently occupied

The less() function in TurboSafe.sol incorrectly updates the master contract's accounting when the amount of Fei withdrawn exceeds the debt balance, causing the recorded boosted amount for a vault to be larger than the actual amount. This can permanently occupy the boost caps for the vault and collateral, preventing new boosts.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug, also found by cmichel and hyh

TurboSafe.sol#L225-L236

// Get out current amount of Fei debt in the Turbo Fuse Pool.
uint256 feiDebt = feiTurboCToken.borrowBalanceCurrent(address(this));

// If our debt balance decreased, repay the minimum.
// The surplus Fei will accrue as fees and can be sweeped.
if (feiAmount > feiDebt) feiAmount = feiDebt;

// Repay Fei debt in the Turbo Fuse Pool, unless we would repay nothing.
if (feiAmount != 0) require(feiTurboCToken.repayBorrow(feiAmount) == 0, "REPAY_FAILED");

// Call the Master to allow it to update its accounting.
master.onSafeLess(asset, vault, feiAmount);

In the current implementation, when calling less() to withdraw Fei from the Vault and use it to repay debt, if the amount of Fei is bigger than the debt balance, the onSafeLess hook will use feiDebt as The amount of Fei withdrawn from the Vault.

As a result, getTotalBoostedForVault[vault] in TurboMaster will be larger than the actual total amount of Fei being used to boost the Vault.

Since the Turbo Gibber may impound some of the Safe’s collateral and mint a certain amount of Fei and repay the Safe’s Fei debt with the newly minted Fei. In that case, the Safe’s debt balance can be less than the amount of Fei in Vault. Which constitutes the precondition for the less() call to case the distortion of getTotalBoostedForVault[vault].

Proof of Concept

Given:

  • 1 WBTC = 100,000
  • collateralFactor of WBTC = 0.6
  • getBoostCapForCollateral[WBTC] = 300,000
  • getBoostCapForVault[vault0] = 300,000
  • Alice create Safe and deposit 10 WBTC and Boost 300,000 Fei to vault0
  • Safe’s debt = 300,000
  • Safe’s Fei in vault = 300,000

On master:

  • getTotalBoostedForVault[vault0] = 300,000
  • getTotalBoostedAgainstCollateral[WBTC] = 300,000

On safe:

  • getTotalFeiBoostedForVault[vault0] = 300,000
  • totalFeiBoosted = 300,000
  • WBTC price drop to 50,000, Turbo Gibber impound 2 WBTC and mint 100,000 Fei to repay debt for Alice’s Safe.
  • Safe’s debt = 200,000
  • Safe’s Fei in vault0 = 300,000
  • Alice call less() withdraw 300,000 Fei from Vault and repay 200,000 debt, in the hook: master.onSafeLess(WBTC, vault0, 200,000)
  • Safe’s debt = 0
  • Safe’s Fei in vault = 0

On master:

  • getTotalBoostedForVault[vault0] = 100,000
  • getTotalBoostedAgainstCollateral[WBTC] = 100,000

On Safe:

  • getTotalFeiBoostedForVault[vault0] = 0
  • totalFeiBoosted = 0
  • Alice try deposit 20 WBTC and Boost 300,000 Fei will fail due to BOOSTER_REJECTED.

Recommended Mitigation Steps

Change to:

function less(ERC4626 vault, uint256 feiAmount) external nonReentrant requiresLocalOrMasterAuth {
    // Update the total Fei deposited into the Vault proportionately.
    getTotalFeiBoostedForVault[vault] -= feiAmount;

    unchecked {
        // Decrease the boost total proportionately.
        // Cannot underflow because the total cannot be less than a single Vault.
        totalFeiBoosted -= feiAmount;
    }

    emit VaultLessened(msg.sender, vault, feiAmount);

    // Withdraw the specified amount of Fei from the Vault.
    vault.withdraw(feiAmount, address(this), address(this));

    // Call the Master to allow it to update its accounting.
    master.onSafeLess(asset, vault, feiAmount);

    // Get out current amount of Fei debt in the Turbo Fuse Pool.
    uint256 feiDebt = feiTurboCToken.borrowBalanceCurrent(address(this));

    // If our debt balance decreased, repay the minimum.
    // The surplus Fei will accrue as fees and can be sweeped.
    if (feiAmount > feiDebt) feiAmount = feiDebt;

    // Repay Fei debt in the Turbo Fuse Pool, unless we would repay nothing.
    if (feiAmount != 0) require(feiTurboCToken.repayBorrow(feiAmount) == 0, "REPAY_FAILED");
}

transmissions11 (Tribe Turbo) commented:

Good find

Alex the Entreprenerd (judge) commented:

The warden identified a way to desynch the actual amounts of boostedFei for a vault and the system vs the amounts tracked in storage.

Because of this discrepancy the availability of borrowable FEI in the system can be distorted, preventing new borrows.

I do not believe this puts collateral at risk and also believe that the temporary “denial of borrowing” would be quickly fixed by raising caps.

I want to commend the warden for finding a way to break the system invariants, while the system internal accounting has been broken, no meaningful leak of value, extended denial of service or funneling of funds happened.

Liquidations can also still happen at the pool level.

Because of these reasons, I agree with Medium Severity.


The original report as published on Code4rena, by WatchPug. 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

Likely, the less() function calls master.onSafeLess with the original feiAmount before capping it to the actual debt, so the master records a larger amount than was actually used to repay debt.

Impact

The boost caps for the vault and collateral can be permanently occupied, preventing new boosts, though the judge noted this is a temporary denial of borrowing that could be fixed by raising caps and does not put collateral at risk.

What the attacker needed

A Safe with a boost; Debt reduced by Turbo Gibber; Fei in Vault exceeds debt

The fix

The less() function should update the Safe's internal accounting and call master.onSafeLess with the actual amount of Fei withdrawn from the Vault before capping it to the debt balance.

How it was found

  1. Alice creates a Safe, deposits 10 WBTC, and boosts 300,000 Fei to vault0.
  2. WBTC price drops, Turbo Gibber impounds 2 WBTC and mints 100,000 Fei to repay part of Alice's debt, reducing debt to 200,000.
  3. Alice calls less() to withdraw 300,000 Fei from the Vault and repay the remaining 200,000 debt.
  4. The master's onSafeLess is called with 200,000, but the Safe's internal accounting is reduced by 300,000, creating a discrepancy.
  5. Alice tries to deposit 20 WBTC and boost 300,000 Fei but fails due to BOOSTER_REJECTED because the caps are still occupied.

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.

This is a smart contract bug where a function that repays debt updates a shared record with the wrong number. The record then shows more money is being used than actually is, so the system thinks its limit is reached and blocks new users from boosting.

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 WatchPug

View all

197 more disclosed reports, best first.

More from Tribe Turbo 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.