Anyone can execute certain functions that use cross chain messages and potentially cancel them with potential loss of funds
Several functions that send cross-chain messages on the Game and MainVault contracts lack access control, allowing anyone to call them. An attacker could set a low relayer fee to delay the message or, once Connext enables cancellation, cancel the message after changing the origin chain state, leaving contracts out of sync and potentially causing loss of funds.
Jeiwan Follow with c7e7eff and rvierdiiev
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-01-derby-judging/issues/390
Found by
Jeiwan, c7e7eff, rvierdiiev
c7e7eff High
Summary
Certain functions that route messages cross chain on the Game and MainVault contract are unprotected (anyone can call them under the required state of the vaults). The way the cross chain messaging is implemented in the XProvider makes use of Connext's xcall() and sets the msg.sender as the delegate and msg.value as relayerFee.
There are two possible attack vectors with this:
- Either an attacker can call the function and set the msg.value to low so it won't be relayed until someone bumps the fee (Connext allows anyone to bump the fee). This however means special action must be taken to bump the fee in such a case.
- Or the attacker can call the function (which irreversibly changes the state of the contract) and as the delegate of the
xcallcancel the message. This functionality is however not yet active on Connext, but the moment it is the attacker will be able to change the state of the contract on the origin chain and make the cross chain message not execute on the destination chain leaving the contracts on the two chains out of synch with possible loss of funds as a result.
Vulnerability Detail
The XProvider contract's xsend() function sets the msg.sender as the delegate and msg.value as relayerFee
uint256 relayerFee = _relayerFee != 0 ? _relayerFee : msg.value;
IConnext(connext).xcall{value: relayerFee}(
_destinationDomain, // _destination: Domain ID of the destination chain
target, // _to: address of the target contract
address(0), // _asset: use address zero for 0-value transfers
msg.sender, // _delegate: address that can revert or forceLocal on destination
0, // _amount: 0 because no funds are being transferred
0, // _slippage: can be anything between 0-10000 because no funds are being transferred
_callData // _callData: the encoded calldata to send
);
}
xTransfer() using msg.sender as delegate:
IConnext(connext).xcall{value: (msg.value - _relayerFee)}(
_destinationDomain, // _destination: Domain ID of the destination chain
_recipient, // _to: address receiving the funds on the destination
_token, // _asset: address of the token contract
msg.sender, // _delegate: address that can revert or forceLocal on destination
_amount, // _amount: amount of tokens to transfer
_slippage, // _slippage: the maximum amount of slippage the user will accept in BPS (e.g. 30 = 0.3%)
bytes("") // _callData: empty bytes because we're only sending funds
);
}
Connext documentation explaining:
params.delegate | (optional) Address allowed to cancel an xcall on destination.
Connext documentation seems to indicate this functionality isn't active yet though it isn't clear whether that applies to the cancel itself or only the bridging back the funds to the origin chain.
Impact
An attacker can call certain functions which leave the relying contracts on different chains in an unsynched state, with possible loss of funds as a result (mainly on XChainControleler's sendFundsToVault() when actual funds are transferred.
Code Snippet
MainVault's pushTotalUnderlyingToController() has no access control and calls pushTotalUnderlying() on the xProvider
https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/MainVault.sol#L249
xProvider's pushTotalUnderlying() calling xsend()
https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/XProvider.sol#L243
MainVault's sendRewardsToGame() has no access control and calls pushRewardsToGame() on the xProvider
https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/MainVault.sol#L365
xProvider's pushRewardsToGame() calling xsend()
https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/XProvider.sol#L443
XProvider setting msg.sender as delegate and msg.value as relayer fee:
https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/XProvider.sol#L115-L124
XChainController's unprotected sendFundsToVault()
https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/XChainController.sol#L409-L414
XProvider's xTransfer() setting msg.sender as delegate:
https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/XProvider.sol#L152-L161
Also on the Game contract, the unprotected psuhAllocationsToController() function:
https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/Game.sol#L424
and the pushAllocationsToVaults()
https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/Game.sol#L465
Tool used
Manual Review
Recommendation
Provide access control limits to the functions sending message across Connext so only the Guardian can call these functions with the correct msg.value and do not use msg.sender as a delegate but rather a configurable address like the Guardian.
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 access control on cross-chain messaging functions and the use of msg.sender as the delegate in Connext's xcall, allowing any caller to control the message's relayer fee and cancellation.
Impact
An attacker could leave contracts on different chains out of sync, potentially causing loss of funds, especially when actual funds are transferred via sendFundsToVault().
What the attacker needed
Vaults in required state; Connext cancellation active (for cancel vector)
The fix
The functions sending messages across Connext should have access control so only the Guardian can call them with the correct msg.value, and a configurable address like the Guardian should be used as the delegate instead of msg.sender.
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.
Some functions that send messages from one blockchain to another can be called by anyone, not just the intended users. An attacker can call these functions and either pay too little for the message to be delivered or, in the future, cancel the message after it has already changed the state on the first chain. This can make the two chains disagree about important data, like how much money is where.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.