Open code423n4 opened 2 years ago
Valid issue, however disagree with severity as issue relates to function incorrect as to spec
. Suggest low severity
.
Let me reason through the finding: -> The warden has shown a way for funds to be lost as long as a user uses a sChainNativeToken and burns them to bridge to mainnet (Potentially High)
-> This is contingent on the configuration of the depositBoxErc20 (Potentially Med)
I disagree with the sponsor argument in that while the code may not be as to spec, the functionality impaired as a medium to high impact.
At this time I can rationalize the severity either as: -> It should be High because the given codebase "default" functionality has this flaw -> it should be Med because this is contingent on a configuration parameter
Given the pre-context that the sChain could be set up by the admin to allow the misconfiguration to happen, at this time, I believe Medium Severity to be more appropriate as the impact is solely dependent upon the configuration of the chain which as explained in the readmes is mostly dependent on the admin
Mitigated in https://github.com/skalenetwork/IMA/pull/1031/
Lines of code
https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/schain/TokenManagers/TokenManagerERC20.sol#L95-L104
Vulnerability details
In the current implementation of
TokenManagerERC20
, it allowsexitToMainERC20(tokenOnSchain, amount)
.At L277 of
TokenManagerERC20.sol
inexitToMainERC20()
, iftokenOnSchain
is minted on SKALE schain natively, there are no such require statement that prevents the target chain being mainnet, eg:require(chainHash != MAINNET_HASH, "...")
Therefore, a user can set mainnet as the target chain, and at L298 of
TokenManagerERC20.sol
, the tokens will be transferred to the contract, and at L308, send message to Ethereum mainnet.https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/schain/TokenManagers/TokenManagerERC20.sol#L95-L104
https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/schain/TokenManagers/TokenManagerERC20.sol#L264-L313
However, the
DepositBoxERC20
contract on Ethereum mainnet does not support such message fromTokenManagerERC20
on the schain:The type of the message from schain
TokenManagerERC20
isTRANSFER_ERC20_AND_TOKEN_INFO
(see L354 of TokenManagerERC20.sol) orTRANSFER_ERC20_AND_TOTAL_SUPPLY
(see L362 of TokenManagerERC20.sol).https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/schain/TokenManagers/TokenManagerERC20.sol#L339-L370
DepositBoxERC20
on Ethereum MAINNET can only processTRANSFER_ERC20
. (see DepositBoxERC20.sol L155 and Messages.sol L270)When getting a message with the type of
TRANSFER_ERC20_AND_TOKEN_INFO
orTRANSFER_ERC20_AND_TOTAL_SUPPLY
from schainTokenManagerERC20
, it will revert at L270 of Messages.sol.As a result, the schain tokens will be frozen on TokenManagerERC20, but they will not receive tokens on Ethereum.
https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/mainnet/DepositBoxes/DepositBoxERC20.sol#L143-L164
https://github.com/skalenetwork/ima-c4-audit/blob/11d6a6ae5bf16af552edd75183791375e501915f/contracts/Messages.sol#L267-L272
Recommendation
Consider preventing moving schain native tokens to Ethereum MAINNET, for example: Add
require(chainHash != MAINNET_HASH, "...")
near L277 of TokenManagerERC20.sol.