Skip to content
Business logic Audit finding Intermediate

Permanent loss of tokens if swap data gets outdated

When a cross-chain swap via Stargate fails because the swap data is outdated, the tokens remain stuck in the StargateBridgeAdapter contract and cannot be recovered because the user can only retry with the same payload. This leads to permanent loss of the transferred tokens for the user.

windhustler Follow with monrel, nuthan2x and 1 other

Originally disclosed on Code4rena

Submitted by windhustler, also found by monrel, nuthan2x, and imare

While sending funds through StargateBridgeAdapter, the user passes the swap data as a parameter. The flow is stargate sending tokens on the receiving chain into the StargateBridgeAdapter and executing sgReceive.

The issue here is that sgReceive will fail if the swap data gets outdated, but this is not going to make the whole transaction revert.

Stargate will still send the tokens to the StargateBridgeAdapter, and if the sgReceive fails, the swap will be cached for later execution. See StargateComposer logic here: https://stargateprotocol.gitbook.io/stargate/stargate-composability/stargatecomposer.sol#sgreceive.

Now, tokens will be left sitting in the StargateBridgeAdapter contract, and since the user can only retry the transaction with the same swap data, the tokens will be stuck forever.

The impact is loss of transferred tokens for the user.

Proof of Concept

Consider the following flow:

  1. User invokes StargateBridgeAdapter:bridge() function as part of the whole flow of calling UTB:bridgeAndExecute() function.
  2. He is passing the swapData parameters to the remote chain.
  3. StargateComposer first transfers the tokens to the StargateBridgeAdapter contract.
  4. After that the StargateBridgeAdapter:sgReceive() function is executed.
  5. It then calls UTB:receiveFromBridge that tries to execute the swap.
  6. If the swap fails, which can frequently occur due to the fact that the swap data is outdated, most commonly minimum amount out gets outdated.
  7. The whole payload gets stored inside the StargateComposer contract, and the tokens are left in the StargateBridgeAdapter contract.
  8. As the user can only retry the transaction with the same payload, the tokens will be stuck forever.
  9. An example of StargateComposer contract can be seen on: https://stargateprotocol.gitbook.io/stargate/developers/contract-addresses/mainnet#ethereum

Note: The application needs to use the StargateComposer contract as opposed to StargateRouter because it is transferring funds with payload, i.e. it executes sgReceive on the receiving chain. You can only use StargateRouter directly if you’re sending funds empty payload. More on it: https://stargateprotocol.gitbook.io/stargate/stargate-composability

Recommended Mitigation Steps

Wrap the whole StargateBridgeAdapter:receiveFromBridge() call into a try/catch and if it reverts send the transferred tokens back to the user.

wkantaros (Decent) confirmed

0xsomeone (Judge) decreased severity to Medium and commented:

The Warden has demonstrated that it is possible for a Stargate-based cross-chain interaction to fail at the swap level perpetually.

While the StargateComposer::clearCachedSwap function exists to retry the same payload, as the Warden states, a sharp market event (i.e. token launch that leads to an upward trend or market crash that leads to a downward event) can cause the swap to fail.

Theoretically, the tokens can be rescued using a flash-loan if they are substantial, however, this would be very unconventional and not a real mitigation to the issue. The proposed solution by the Warden is adequate.

I believe a severity of Medium is more appropriate as the vulnerability relies on external requirements (i.e. a sharp market event), the maximum impact is the user’s own funds, and when users specify slippage (i.e. minimum output) they usually factor in the time it takes for a transaction to execute. Network congestion, market events, and cross-chain relay delays all play a role in whether the vulnerability manifests but present external requirements.

Note: For full discussion, see here.


The original report as published on Code4rena, by windhustler. 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 lack of a fallback mechanism in StargateBridgeAdapter to return tokens to the user when the swap execution fails, combined with StargateComposer caching the failed payload for retry with the same data.

Impact

The user permanently loses the transferred tokens, though this requires external conditions such as a sharp market event that makes the swap fail.

What the attacker needed

Cross-chain bridge via Stargate; swap data becomes outdated (e.g., slippage); market event causing swap failure

The fix

Wrap the receiveFromBridge call in a try/catch and, on failure, return the transferred tokens to the user.

How it was found

  1. User invokes StargateBridgeAdapter:bridge() as part of UTB:bridgeAndExecute(), passing swapData for the remote chain.
  2. StargateComposer transfers tokens to the StargateBridgeAdapter contract on the destination chain.
  3. StargateBridgeAdapter:sgReceive() is executed and calls UTB:receiveFromBridge to attempt the swap.
  4. If the swap fails (e.g., due to outdated minimum amount out), the payload is stored in StargateComposer and tokens remain in StargateBridgeAdapter.
  5. The user can only retry with the same payload, so the tokens stay stuck permanently.

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 report is about a cross-chain swap where tokens are sent from one blockchain to another. If the swap fails on the receiving chain (for example, because the minimum amount expected is no longer available), the tokens get stuck in a smart contract and the user cannot get them back because they can only retry with the same failing instructions.

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 windhustler

View all

6 more disclosed reports, best first.

More from Decent

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.