When transferring tokens native on SKALE to Ethereum with TokenManagerERC20.exitToMainERC20() , the tokens on the schain will be frozen on TokenManagerERC20 , but they will not receive tokens on Ethereum
The bridge contract on a SKALE chain allowed a user to send a natively minted token to Ethereum mainnet, but the Ethereum deposit box only understands a different message type and rejects it. The user's tokens are burned or locked on the SKALE side while no tokens arrive on Ethereum, so the funds are lost.
Submitted by WatchPug
In the current implementation of TokenManagerERC20, it allows exitToMainERC20(tokenOnSchain, amount).
At L277 of TokenManagerERC20.sol in exitToMainERC20(), if tokenOnSchain 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.
function exitToMainERC20(
address contractOnMainnet,
uint256 amount
)
external
override
{
communityLocker.checkAllowedToSendMessage(msg.sender);
_exit(MAINNET_HASH, depositBox, contractOnMainnet, msg.sender, amount);
}
function _exit(
bytes32 chainHash,
address messageReceiver,
address contractOnMainChain,
address to,
uint256 amount
)
private
{
bool isMainChainToken;
ERC20BurnableUpgradeable contractOnSchain = clonesErc20[chainHash][contractOnMainChain];
if (address(contractOnSchain) == address(0)) {
contractOnSchain = ERC20BurnableUpgradeable(contractOnMainChain);
isMainChainToken = true;
}
require(address(contractOnSchain).isContract(), "No token clone on schain");
require(contractOnSchain.balanceOf(msg.sender) >= amount, "Insufficient funds");
require(
contractOnSchain.allowance(
msg.sender,
address(this)
) >= amount,
"Transfer is not approved by token holder"
);
bytes memory data = Messages.encodeTransferErc20Message(address(contractOnMainChain), to, amount);
if (isMainChainToken) {
data = _receiveERC20(
chainHash,
address(contractOnSchain),
msg.sender,
amount
);
_saveTransferredAmount(chainHash, address(contractOnSchain), amount);
require(
contractOnSchain.transferFrom(msg.sender, address(this), amount),
"Transfer was failed"
);
} else {
require(
contractOnSchain.transferFrom(msg.sender, address(this), amount),
"Transfer was failed"
);
contractOnSchain.burn(amount);
}
messageProxy.postOutgoingMessage(
chainHash,
messageReceiver,
data
);
}
However, the DepositBoxERC20 contract on Ethereum mainnet does not support such message from TokenManagerERC20 on the schain:
The type of the message from schain TokenManagerERC20 is TRANSFER_ERC20_AND_TOKEN_INFO (see L354 of TokenManagerERC20.sol) or TRANSFER_ERC20_AND_TOTAL_SUPPLY (see L362 of TokenManagerERC20.sol).
function _receiveERC20(
bytes32 chainHash,
address erc20OnMainChain,
address to,
uint256 amount
)
private
returns (bytes memory data)
{
ERC20BurnableUpgradeable erc20 = ERC20BurnableUpgradeable(erc20OnMainChain);
uint256 totalSupply = erc20.totalSupply();
require(amount <= totalSupply, "Amount is incorrect");
bool isERC20AddedToSchain = _schainToERC20[chainHash].contains(erc20OnMainChain);
if (!isERC20AddedToSchain) {
_addERC20ForSchain(chainHash, erc20OnMainChain);
data = Messages.encodeTransferErc20AndTokenInfoMessage(
erc20OnMainChain,
to,
amount,
_getErc20TotalSupply(erc20),
_getErc20TokenInfo(erc20)
);
} else {
data = Messages.encodeTransferErc20AndTotalSupplyMessage(
erc20OnMainChain,
to,
amount,
_getErc20TotalSupply(erc20)
);
}
emit ERC20TokenReady(chainHash, erc20OnMainChain, amount);
}
DepositBoxERC20 on Ethereum MAINNET can only process TRANSFER_ERC20. (see DepositBoxERC20.sol L155 and Messages.sol L270)
When getting a message with the type of TRANSFER_ERC20_AND_TOKEN_INFO or TRANSFER_ERC20_AND_TOTAL_SUPPLY from schain TokenManagerERC20, 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.
function postMessage(
bytes32 schainHash,
address sender,
bytes calldata data
)
external
override
onlyMessageProxy
whenNotKilled(schainHash)
checkReceiverChain(schainHash, sender)
returns (address)
{
Messages.TransferErc20Message memory message = Messages.decodeTransferErc20Message(data);
require(message.token.isContract(), "Given address is not a contract");
require(ERC20Upgradeable(message.token).balanceOf(address(this)) >= message.amount, "Not enough money");
_removeTransferredAmount(schainHash, message.token, message.amount);
require(
ERC20Upgradeable(message.token).transfer(message.receiver, message.amount),
"Transfer was failed"
);
return message.receiver;
}
function decodeTransferErc20Message(
bytes calldata data
) internal pure returns (TransferErc20Message memory) {
require(getMessageType(data) == MessageType.TRANSFER_ERC20, "Message type is not ERC20 transfer");
return abi.decode(data, (TransferErc20Message));
}
Recommendation
Consider preventing moving schain native tokens to Ethereum MAINNET, for example: Add require(chainHash != MAINNET_HASH, "...") near L277 of TokenManagerERC20.sol.
cstrangedk (SKALE) disagreed with severity and commented:
Valid issue, however disagree with severity as issue relates to
function incorrect as to spec. Suggestlow severity.
GalloDaSballo (judge) decreased severity to Medium and commented:
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 skalenetwork/IMA#1031.
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 exit function did not check that the destination chain was not mainnet for tokens native to the SKALE chain, so it produced a message type the mainnet deposit box cannot decode.
Impact
A user's native SKALE tokens are burned or locked on the SKALE chain and never arrive on Ethereum, so the funds are lost; the judge noted this depends on how the chain is configured.
What the attacker needed
A SKALE chain with a native token; user holds that native token; user calls the exit function
The fix
The issue was mitigated by adding a check that prevents sending native SKALE tokens to mainnet.
How it was found
- Approve the token manager to spend the native SKALE token.
- Call exitToMainERC20 with the token address and an amount.
- The token manager transfers the tokens from the user and burns them.
- It posts a message of a type the mainnet deposit box cannot decode.
- The mainnet deposit box reverts, so no tokens are delivered.
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 bridge moves tokens between two blockchains. This bridge had a path that let someone send a token that only exists on the SKALE chain towards Ethereum, but the Ethereum side did not recognise that kind of message and refused it. The tokens were already taken from the user on the SKALE side, so they disappeared without arriving on the other side.
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.