Skip to content
Business logic Audit finding Intermediate

Incorrect chainId comparison in xProvider

Two functions in the xProvider contract compared the destination chain ID from their parameters against the controller or game chain ID, rather than comparing the provider's own home chain. This caused calls to fail in certain chain configurations, preventing some vaults from progressing to the next stage.

Sulpiride Follow

Originally disclosed on Sherlock

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

Found by

Sulpiride

Summary

xProvider.pushTotalUnderlying and xProvider.pushRewardsToGame incorrectly implement chainId comparison.

Vulnerability Detail

xProvider.pushTotalUnderlying and xProvider.pushRewardsToGame incorrectly implement chainId comparison. Instead of comparing the chainId of xProvider with the chainId of the destination chain, the chainId from functions' parameter was used

Impact

Calling these two functions will fail in two scenarios:

  1. When chainId != xControllerChain (or gameChain) and xProvider.homeChain == xControllerChain
  2. When chainId == xControllerChain and xControllerChain != xProvider.homeChain
  • chainId = incoming _chainId from functions parameters

In the first case, the call will fail because you can't xcall to the same chain In the second case, because xController and game are address(0)

This will prevent some vaults from moving to the next stage, so this just haults them

Code Snippet

pushTotalUnderlying: https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/XProvider.sol#L207-L245

Solidity
  function pushTotalUnderlying(
    uint256 _vaultNumber,
    uint32 _chainId,
    uint256 _underlying,
    uint256 _totalSupply,
    uint256 _withdrawalRequests
  ) external payable onlyVaults {
    if (_chainId == xControllerChain) { // _chainId can be different from homeChain, but equal to xControllerChain
      return
        IXChainController(xController).setTotalUnderlying(
          _vaultNumber,
          _chainId,
          _underlying,
          _totalSupply,
          _withdrawalRequests
        );
    } else {
      bytes4 selector = bytes4(
        keccak256("receiveTotalUnderlying(uint256,uint32,uint256,uint256,uint256)")
      );
      bytes memory callData = abi.encodeWithSelector(
        selector,
        _vaultNumber,
        _chainId,
        _underlying,
        _totalSupply,
        _withdrawalRequests
      );

      xSend(xControllerChain, callData, 0);
    }
  }

pushRewardsToGame: https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/XProvider.sol#L427-L445

Solidity
  function pushRewardsToGame(
    uint256 _vaultNumber,
    uint32 _chainId,
    int256[] memory _rewards
  ) external payable onlyVaults {
    if (_chainId == gameChain) {
      return IGame(game).settleRewards(_vaultNumber, _chainId, _rewards);
    } else {
      bytes4 selector = bytes4(keccak256("receiveRewardsToGame(uint256,uint32,int256[])"));
      bytes memory callData = abi.encodeWithSelector(selector, _vaultNumber, _chainId, _rewards);

      xSend(gameChain, callData, 0);
    }
  }

Tool used

Manual Review

Recommendation

Change the condition to the following:

Diff
function pushTotalUnderlying(
...
-if (_chainId == xControllerChain) { 
+if (homeChain == xControllerChain) {
...
Diff
function pushRewardsToGame(
...
-if (_chainId == gameChain) {
+if (homeChain == gameChain) {
...

Discussion

sjoerdsommen

Correct should be (homechain == xChainControllerChain). But medium issue cause no funds are at risk.

The original report as published on Sherlock, by Sulpiride. 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

Impact

Some vaults could not move to the next stage because the calls would revert, but no funds were at risk.

What the attacker needed

Vault calls the affected functions; chain configuration differs from home chain

The fix

The condition should compare the provider's home chain with the controller or game chain instead of the parameter chain ID.

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 smart contract has to know which blockchain it is running on before it sends a message to another chain. These two functions checked the wrong chain identifier, so in some setups they tried to send a message to the chain they were already on, or looked up an address that was empty. The result was that the action failed and the vault got 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 from Derby

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.