Skip to content
Business logic Audit finding Intermediate

multiHopSellCollateral() will fail due to call on an invalid market address causing bridged collateral to be locked up

The multiHopSellCollateral function fails because it calls getBorrowPartForAmount on a non-existent market on the destination chain, causing the cross-chain transaction to revert and bridged collateral to be locked. An attacker could not exploit this directly, but users attempting to leverage down would lose access to their bridged collateral.

peakbolt Follow

Originally disclosed on Code4rena

Submitted by peakbolt

https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/markets/singularity/Singularity.sol#L409-L427

https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/markets/singularity/SGLLeverage.sol#L81

https://github.com/Tapioca-DAO/tapiocaz-audit/blob/master/contracts/tOFT/modules/BaseTOFTLeverageModule.sol#L79-L108

https://github.com/Tapioca-DAO/tapiocaz-audit/blob/master/contracts/tOFT/modules/BaseTOFTLeverageModule.sol#L227

multiHopSellCollateral() allows users to leverage down by selling the TOFT collateral on another chain and then send it to host chain (Arbitrum) for repayment of USDO loan.

However, it will fail as it tries to obtain the repayableAmount on the destination chain by calling IMagnetar.getBorrowPartForAmount() on a non-existing market. That is because Singularity/BigBang markets are only deployed on the host chain.

https://github.com/Tapioca-DAO/tapiocaz-audit/blob/master/contracts/tOFT/modules/BaseTOFTLeverageModule.sol#L205-L227

    function leverageDownInternal(
        uint256 amount,
        IUSDOBase.ILeverageSwapData memory swapData,
        IUSDOBase.ILeverageExternalContractsData memory externalData,
        IUSDOBase.ILeverageLZData memory lzData,
        address leverageFor
    ) public payable {
        _unwrap(address(this), amount);

        //swap to USDO
        IERC20(erc20).approve(externalData.swapper, amount);
        ISwapper.SwapData memory _swapperData = ISwapper(externalData.swapper)
            .buildSwapData(erc20, swapData.tokenOut, amount, 0, false, false);
        (uint256 amountOut, ) = ISwapper(externalData.swapper).swap(
            _swapperData,
            swapData.amountOutMin,
            address(this),
            swapData.data
        );

        //@audit this call will fail as there is no market in destination chain
        //repay
        uint256 repayableAmount = IMagnetar(externalData.magnetar)
            .getBorrowPartForAmount(externalData.srcMarket, amountOut);

Impact

The issue will prevent users from using multiHopSellCollateral() to leverage down.

Furthermore the failure of the cross-chain transaction will cause the bridged collateral to be locked in the TOFT contract on a non-host chain as the refund mechanism will also revert and retryMessage() will continue to fail as this is a permanent error.

Proof of Concept

Consider the following scenario where a user leverage down by selling the collateral on Ethereum (a non-host chain).

  1. User first triggers Singularity.multiHopSellCollateral() on host chain Arbitrum.
  2. That will call SGLLeverage.multiHopSellCollateral(), which will conduct a cross chain message via ITapiocaOFT(address(collateral)).sendForLeverage() to bridge over and sell the collateral on Ethereum mainnet.
  3. The collateral TOFT contract on Ethereum mainnet will receive the bridged collateral and cross-chain message via _nonBlockingLzReceive() and then BaseTOFTLeverageModule.leverageDown().
  4. The execution continues with BaseTOFTLeverageModule.leverageDownInternal(), but it will revert as it attempt to call getBorrowPartForAmount() for a non-existing market in Ethereum.
  5. The bridgex collateral will be locked in the TOFT contract on Ethereum mainnet as the refund mechanism will also revert and retryMessage() will continue to fail as this is a permanent error.

Recommended Mitigation Steps

Obtain the repayable amount on the Arbitrum (host chain) where the BigBang/Singularity markets are deployed.

0xRektora (Tapioca) confirmed


The original report as published on Code4rena, by peakbolt. 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 code assumes that the market contract exists on all chains, but Singularity/BigBang markets are only deployed on the host chain, so the call to getBorrowPartForAmount on a non-host chain reverts.

Impact

The issue prevents users from using multiHopSellCollateral() to leverage down, and the failure causes bridged collateral to be locked in the TOFT contract on a non-host chain because the refund mechanism also reverts and retryMessage() will continue to fail.

What the attacker needed

User uses multiHopSellCollateral; Destination chain is not host chain

The fix

Obtain the repayable amount on the Arbitrum (host chain) where the BigBang/Singularity markets are deployed.

How it was found

  1. User triggers Singularity.multiHopSellCollateral() on host chain Arbitrum.
  2. That calls SGLLeverage.multiHopSellCollateral(), which sends a cross-chain message via ITapiocaOFT.sendForLeverage() to bridge and sell collateral on Ethereum mainnet.
  3. The collateral TOFT contract on Ethereum receives the bridged collateral and message via _nonBlockingLzReceive() and then BaseTOFTLeverageModule.leverageDown().
  4. Execution continues with BaseTOFTLeverageModule.leverageDownInternal(), but it reverts because it calls getBorrowPartForAmount() for a non-existing market on Ethereum.
  5. The bridged collateral becomes locked in the TOFT contract on Ethereum mainnet because the refund mechanism also reverts and retryMessage() will continue to fail.

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 bug in a cross-chain lending system. When a user tries to sell collateral on another chain to repay a loan, the code asks a contract on that other chain for information that only exists on the main chain. Because that information is missing, the whole transaction fails and the user's collateral gets stuck.

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 peakbolt

View all

16 more disclosed reports, best first.

More from Tapioca Invitational

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.