Skip to content
DoS Audit finding Intermediate

Incorrect calls and Enforcements during Migration To a market

The migration function unconditionally checks deposit and borrow pause status and calls a post-deposit hook even when only debt is moved, causing legitimate migrations to fail. This can block users from moving debt or adding collateral during critical moments, increasing liquidation risk.

7 Follow with Artur, Bigsam and 3 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-08-usg-tangent-judging/issues/180

Found by

7, Artur, Bigsam, Brene, Tigerfrake, aman

Summary

Migration allows users to move collateral and debt, or collateral alone or debt alone. _migrateTo unconditionally enforces deposit and borrow pause checks and always calls _postDeposit, even when the migration only moves debt. This creates an unnecessary DoS on migration in legitimate cases and can block users from rescuing positions during critical moments.

Root Cause

Solidity
   function _migrateTo(IControlTower _controlTower, address account, uint256 collatToAdd, uint256 debtToAdd) internal returns (uint256) {
        _verifySenderMigrator(_controlTower);

@audit>>        _verifyIsDepositNotPaused();         // check if we are adding collateral..... 
@audit>>           _verifyIsBorrowNotPaused();        // check only if we are borrowing when we are not why check?
       

      uint256 debtIndex = _checkpointIR();

        uint256 uDebtShares = userDebtShares[account];
        uint256 newUserDebt = _convertToAmount(uDebtShares, debtIndex) + debtToAdd;
        uint256 newCollatBalance = collateralBalances[account] + collatToAdd;
        uint256 sharesToAdd = _convertToShares(debtToAdd, debtIndex);
        uint256 newTotalDebtShares = totalDebtShares + sharesToAdd;
        uint256 newUserDebtShares = uDebtShares + sharesToAdd;

        // We check both condition on minimum loan and maxLTV
        // Dont need to check them when the new user debt is equal to 0
        if (newUserDebt != 0) {
            _verifyMinimumDebt(newUserDebt);
            _verifyMaxLTV(newCollatBalance, newUserDebt, false);          
            _verifyDebtCap(badDebt, newTotalDebtShares, debtIndex);      
        }

        _updateCollatAndDebts(account, newCollatBalance, totalCollateral + collatToAdd, newUserDebtShares, newTotalDebtShares);
 


@audit>>          _postDeposit(collatToken);   // Only when deposit occurs

        return newUserDebtShares;
    }
Solidity

@audit>>    /// @notice Pauses new deposits on the market
@audit>>     bool public isDepositPaused;

@audit>>     /// @notice Pauses new borrows on the market
@audit>>     bool public isBorrowPaused;

isDepositPaused is specifically used to Prevent New deposit to the Market. isBorrowPaused is specifically used to Prevent New borrow action in the Market.

Solidity
  /**
*      
@audit>>      * @dev Hook after deposit to allow extended logic such as staking the collateral in an underlying protocol.
@audit>>      *      When not override, does nothing. Otherwise, refers to the overriding implementation.
@audit>>      * @param _collatToken Collateral token being deposited.
     */

@audit>>     function _postDeposit(IERC20 _collatToken) internal virtual {}

_postDeposit is specifically call whenever a new deposit is made after a deposit to allow extended logic.

Migration incorrectly calls above 3 functions regardless of the action in play

The correct flow

  1. Coll > 0 and debt > 0 . call all . Correct
  2. Coll > 0 and debt == 0 . check new deposit is allowed and calls post-deposit ...
  3. Coll == 0 and debt > 0 . check if new borrow /debt transferred is allowed ....

Migration 2 and 3 fails even in ideal and correct state.

This strictly enforces SPECIFIC SPECIAL calls that are individual deposit and borrow calls flow

Solidity
   /**
     * @dev Internal function called during 'deposit' external function.
     * @param _for            Address of the user/position receiving collateral.
     * @param amountDeposited Amount of collateral deposited.
     */
    function _deposit(address _for, uint256 amountDeposited, IERC20 _collatToken) internal {

 @audit>>        // Cannot deposit on a market with paused deposits
@audit>>         _verifyIsDepositNotPaused();
 
@audit>>        // Cannot deposit 0
@audit>>         _verifyCollatInputNotZero(amountDeposited);
      


        // Checkpoint the IR and indexes
        _checkpointIR();                                                                                             
        // Increase collateral balance of the position and update total debt
        _updateCollateral(_for, collateralBalances[_for] + amountDeposited, totalCollateral + amountDeposited);

        _postDeposit(_collatToken);
    }

Solidity
  /**
     * @dev  Internal function called during 'borrow', 'depositAndBorrow' and 'leverage' external functions.
     * @param receiver      Address receiving the borrowed USG.
     * @param USGToBorrow Amount of USG to borrow.
     * @param collatAmount  Amount of collateral owned by borrower.
     * @param isLeverage    Whether this borrow is part of a leverage transaction.
     * @return Updated user debt shares after borrow.
     * @return Updated total debt shares for the market.
     */
    function _borrow(address receiver, uint256 USGToBorrow, uint256 collatAmount, bool isLeverage) internal returns (uint256, uint256) {
 
@audit>>       _verifyIsBorrowNotPaused();
@audit>>         _verifyDebtInputNotZero(USGToBorrow);
     


       uint256 newDebtIndex = _checkpointIR();

        uint256 _userDebtShares = userDebtShares[msg.sender];

        uint256 newUserDebt = USGToBorrow + _convertToAmount(_userDebtShares, newDebtIndex);

        //  Cache the new value in USG of the debt
        uint256 newUserDebtShares = _convertToShares(USGToBorrow, newDebtIndex);   

        uint256 newTotalDebtShares = totalDebtShares + newUserDebtShares;        

        _verifyDebtCap(badDebt, newTotalDebtShares, newDebtIndex);              

        //  Verify that newDebt is over the minimum loan
        _verifyMinimumDebt(newUserDebt);                                     

        // Verify that the newDebt of the loan is not over the maximum borrrowable
        _verifyMaxLTV(collatAmount, newUserDebt, false);                       

        // If it's a leverage transaction, USG is already minted before
        if (!isLeverage) {
            // Mint USG to the receiver
            _mintUSG(usg, receiver, USGToBorrow);       // users can mint USG for free  ........ unbacked..
        }

        return (_userDebtShares + newUserDebtShares, newTotalDebtShares);
    }

Post deposit fails on 0 deposit..

Solidity
  function _postDeposit(IERC20 _collatToken) internal override {
        stakingProxyVault.deposit(_collatToken.balanceOf(address(this)), true);
    }


    function _postDeposit(IERC20 _collatToken) internal override {
        uint256 _pid = pid;

        // When pid = 0 / Means the Market is not yet linked to Convex
        if (_pid != 0) {
            CVX_BOOSTER.deposit(_pid, _collatToken.balanceOf(address(this)), true);
        }
    }


    //deposit crv for cvxCrv
    //can locking immediately or defer locking to someone else by paying a fee.
    //while users can choose to lock or defer, this is mostly in place so that
    //the cvx reward contract isnt costly to claim rewards
    function deposit(uint256 _amount, bool _lock, address _stakeAddress) public {

@audit>>>        require(_amount > 0,"!>0");


   //deposit lp tokens and stake
@audit>>>      function deposit(uint256 _pid, uint256 _amount, bool _stake) public returns(bool){
        require(!isShutdown,"shutdown");
        PoolInfo storage pool = poolInfo[_pid];
        require(pool.shutdown == false, "pool is closed");

        //send to proxy to stake
        address lptoken = pool.lptoken;
        IERC20(lptoken).safeTransferFrom(msg.sender, staker, _amount);

        //stake
        address gauge = pool.gauge;
        require(gauge != address(0),"!gauge setting");
        IStaker(staker).deposit(lptoken,gauge);

        //some gauges claim rewards when depositing, stash them in a seperate contract until next claim
        address stash = pool.stash;
        if(stash != address(0)){
            IStash(stash).stashRewards();
        }

        address token = pool.token;

@audit>>>          if(_stake){
            //mint here and send to rewards on user behalf
            ITokenMinter(token).mint(address(this),_amount);
            address rewardContract = pool.crvRewards;
            IERC20(token).safeApprove(rewardContract,0);
            IERC20(token).safeApprove(rewardContract,_amount);

@audit>>>              IRewards(rewardContract).stakeFor(msg.sender,_amount);


 function stakeFor(address _for, uint256 _amount)
        public
        updateReward(_for)
        returns(bool)
    {

@audit>>>          require(_amount > 0, 'RewardPool : Cannot stake 0');

Internal Pre-conditions

https://github.com/sherlock-audit/2025-08-usg-tangent/blob/main/tangent-contracts/src/USG/Market/abstract/MarketCore.sol#L655-L679

https://github.com/sherlock-audit/2025-08-usg-tangent/blob/main/tangent-contracts/src/USG/Market/abstract/MarketCore.sol#L193-L196

https://github.com/sherlock-audit/2025-08-usg-tangent/blob/main/tangent-contracts/src/USG/Market/abstract/MarketCore.sol#L105-L114

External Pre-conditions

........

Attack Path

Improper check enforcement and handling of call-in migration in two specific edge cases.

Impact

This creates a Denial of service, leaving users at risk of being liquidated and losing their collateral.

This can prevent users from:

  1. Moving debt away from a stressed market or into a safer one if they have excess collateral in another market ( has 0 collateral migration fails) .

  2. Adding collateral via migration to shore up health.

Result: increased liquidation risk and potential loss of user funds in volatile periods.

PoC

No response

Mitigation

To mitigate this, add a condition to each call and enforce only when necessary.

Solidity
   function _migrateTo(IControlTower _controlTower, address account, uint256 collatToAdd, uint256 debtToAdd) internal returns (uint256) {
        _verifySenderMigrator(_controlTower);

if( collatToAdd > 0 )  {     _verifyIsDepositNotPaused();    }     // check if we are adding collateral..... 
if (debtToAdd > 0  )    {     _verifyIsBorrowNotPaused();   }     // check only if we are borrowing when we are not, why check?




if (collatToAdd > 0)    {      _postDeposit(collatToken);  }     // Only when deposit occurs

        return newUserDebtShares;
    }

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/Tangent-labs/tangent-contracts/pull/115

The original report as published on Sherlock, by 7. 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 migration function applies deposit and borrow pause checks and the post-deposit hook unconditionally, instead of only when collateral or debt is actually being added.

Impact

This creates a denial of service, preventing users from moving debt away from a stressed market or adding collateral via migration, which could lead to liquidation and loss of funds.

What the attacker needed

Migration function is used; deposit or borrow is paused; or migrating only debt

The fix

The protocol team fixed this issue by adding conditions to only enforce pause checks and call the post-deposit hook when collateral or debt is actually being added.

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 move your loan (debt) or collateral from one market to another, the code always checks if new deposits or borrows are paused, even if you are only moving debt. It also runs a deposit hook that fails when no collateral is added. This means you cannot move your debt to safety or add collateral when you need to, which could lead to losing your collateral if the market turns bad.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by 7

View all

2 more disclosed reports, best first.

More from USG - Tangent

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.