Skip to content
Race condition Audit finding Advanced

Vault could `rebalance()` before funds arrive from xChainController

The vault's rebalance function could be called before cross-chain funds arrive because the feedback message and the fund transfer are processed independently and may arrive out of order. An attacker could trigger rebalancing with incomplete funds, reducing rewards.

Ch_301 Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-01-derby-judging/issues/268

Found by

Ch_301

Summary

Invoke sendFundsToVault() to Push funds from xChainController to vaults. which is call xTransferToVaults()

For the cross-chain rebalancing xTransferToVaults() will execute this logic

Solidity
       ...
      pushFeedbackToVault(_chainId, _vault, _relayerFee);
      xTransfer(_asset, _amount, _vault, _chainId, _slippage, _relayerFee);
       ...

pushFeedbackToVault() always travel through the slow path

  • xTransfer() to transfer funds from one chain to another

If fast liquidity is not available, the xTransfer() will go through the slow path.

The vulnerability is if the xcall() of pushFeedbackToVault() excited successfully before xTransfer() transfer the funds to the vault, anyone can invoke rebalance() this will lead to rebalancing Vaults with Imperfect funds (this could be true only if funds that are expected to be received from XChainController are greater than reservedFunds and liquidityPerc together )

Vulnerability Detail

The above scenario could be done in two possible cases 1- xTransfer() will go through the slow path but because High Slippage the cross-chain message will wait until slippage conditions improve (relayers will continuously re-attempt the transfer execution).

2- Connext Team says

Diff
All messages are added to a Merkle root which is sent across chains every 30 mins
And then those messages are executed by off-chain actors called routers

so it is indeed possible that messages are received out of order (and potentially with increased latency in between due to batch times) 
For "fast path" (unauthenticated) messages, latency is not a concern, but ordering may still be (this is an artifact of the chain itself too btw)
one thing you can do is add a nonce to your messages so that you can yourself order them at destination

so pushFeedbackToVault() and xTransfer() could be added to a different Merkle root and this will lead to executing receiveFunds() before funds arrive.

Impact

The vault could rebalance() before funds arrive from xChainController, this will reduce rewards

Code Snippet

Tool used

Manual Review

Recommendation

Check if funds are arrived or not

The original report as published on Sherlock, by Ch_301. 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 vault does not verify that the expected cross-chain funds have actually been received before allowing rebalancing.

What the attacker needed

Cross-chain message ordering not guaranteed; funds expected from XChainController exceed reserved funds

How it was found

  1. Invoke sendFundsToVault() to push funds from xChainController to vaults.
  2. The pushFeedbackToVault() call goes through the slow path and may execute before xTransfer() completes.
  3. If the feedback message succeeds before funds arrive, anyone can invoke rebalance().
  4. This leads to rebalancing with imperfect funds.

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.

A vault is a smart contract that holds and manages money. When money is sent from another blockchain, a separate message tells the vault to expect it. If someone calls the vault's rebalance function before the money actually arrives, the vault makes decisions based on the wrong balance, which can lead to lower returns.

What is Race condition?

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.

More by Ch_301

View all

39 more disclosed reports, best first.

More from Derby

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Race conditions

The lesson behind this report.

Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.