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.
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:
- When
chainId != xControllerChain (or gameChain)andxProvider.homeChain == xControllerChain - When
chainId == xControllerChainandxControllerChain != 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
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
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:
function pushTotalUnderlying(
...
-if (_chainId == xControllerChain) {
+if (homeChain == xControllerChain) {
...
function pushRewardsToGame(
...
-if (_chainId == gameChain) {
+if (homeChain == gameChain) {
...
Discussion
sjoerdsommen
Correct should be (homechain == xChainControllerChain). But medium issue cause no funds are at risk.
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.