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:
- User invokes
StargateBridgeAdapter:bridge()function as part of the whole flow of callingUTB:bridgeAndExecute()function. - He is passing the swapData parameters to the remote chain.
StargateComposerfirst transfers the tokens to theStargateBridgeAdaptercontract.- After that the
StargateBridgeAdapter:sgReceive()function is executed. - It then calls
UTB:receiveFromBridgethat tries to execute the swap. - 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.
- The whole payload gets stored inside the
StargateComposercontract, and the tokens are left in theStargateBridgeAdaptercontract. - As the user can only retry the transaction with the same payload, the tokens will be stuck forever.
- 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.
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::clearCachedSwapfunction 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.
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
- User invokes StargateBridgeAdapter:bridge() as part of UTB:bridgeAndExecute(), passing swapData for the remote chain.
- StargateComposer transfers tokens to the StargateBridgeAdapter contract on the destination chain.
- StargateBridgeAdapter:sgReceive() is executed and calls UTB:receiveFromBridge to attempt the swap.
- If the swap fails (e.g., due to outdated minimum amount out), the payload is stored in StargateComposer and tokens remain in StargateBridgeAdapter.
- 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.