transferredAmount on mainnet can be drained if a malicious account can mint more tokens on Schain
A malicious account on the Schain side of a bridge can mint tokens on a custom ERC20 contract and then exit them to mainnet, draining the locked tokens held in the deposit box. This traps other users' funds on Schain and steals their mainnet tokens.
Submitted by kyliek, also found by cccz
Impact
Anyone on Schain that is able to mint more tokens, other than the mint action from postMessage in tokenManagerERC20 by bridging tokens over, can potentially drain the locked tokens in transferredAmount in depositBoxERC20 on mainnet by calling exit with the same amount of tokens in transferredAmount[schainHash][token].
This will trap other users’ funds on sChain and lost those funds on mainnet to the malicious attacker.
An example of proof of concept using ERC20OnChian is given below. This case may seem to be special as the deployer of the clone contract is malicious. However, this is a potential risk that generalises to other custom contracts with any mint functionality.
Proof of Concept (with ERC20)
- Malicious account deploys an ERC20 clone
ERC20OnChainon Schain. - By deployment, the malicious account is assigned the MINTER_ROLE on
ERC20OnChainin the constructor.
constructor(
string memory contractName,
string memory contractSymbol
) initializer
{
AccessControlEnumerableUpgradeable.__AccessControlEnumerable_init();
ERC20Upgradeable.__ERC20_init(contractName, contractSymbol);
ERC20BurnableUpgradeable.__ERC20Burnable_init();
_setRoleAdmin(MINTER_ROLE, MINTER_ROLE);
_setupRole(MINTER_ROLE, _msgSender());
}
- This ERC20 clone get registered on
tokenMangagerERC20.solby functionaddERC20TokenByOwner.
function addERC20TokenByOwner(
string calldata targetChainName,
address erc20OnMainChain,
address erc20OnSchain
)
- The malicious account wait for more users to deposit tokens on
depositBoxERC20.depositERC20, which will increase the amount intransferredAmount[schainHash][token]
function depositERC20(
string calldata schainName,
address erc20OnMainnet,
uint256 amount
)
- Malicious account mint to his account the amount equal to
transferredAmount[schainHash][token]onERC20OnChain
function mint(address account, uint256 value) external override {
require(hasRole(MINTER_ROLE, _msgSender()), "Sender is not a Minter");
_mint(account, value);
}
- Malicious account calls
exitToMainERC20inTokenManagerERC20.
function exitToMainERC20(
address contractOnMainnet,
uint256 amount
)
external
override
{
communityLocker.checkAllowedToSendMessage(msg.sender);
_exit(MAINNET_HASH, depositBox, contractOnMainnet, msg.sender, amount);
}
transferredAmount[schainHash][token]is drained to the malicious account on mainnet and victims’ tokens get stranded on schain.
Recommended Mitigation Steps
Disable minting function to be called directly in ERC20OnChain. Only allow minting when bridging tokens over.
cstrangedk (SKALE) disputed and commented:
Issue is acknowledged and work is pending on the roadmap. SKALE Chain owners must carefully manage MINTER_ROLE, and end-users carefully monitor role.
GalloDaSballo (judge) decreased severity to Medium and commented:
I believe the sponsor reply sheds further light into how the system will be used in 99% of cases.
That said we have to judge the codebase for how it could be exploited and used by malicious actors, and I do agree with he warden that if the MINTER_ROLE is granted to someone (let’s say the admin) then they could use it to drain funds from the mainnet side of the bridge.
Because this is contingent on setup and Admin Privilege, I believe Medium Severity to be more appropriate.
Switching from a role based system to an immutable Minter Address (the bridge contract) can be used as mitigation, alternatively sChain end users will have to monitor for these types of changes and act accordingly
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 bridge trusts any registered Schain token contract to report honest balances, so a token with a freely callable mint function lets its minter create unbacked tokens that the bridge then redeems for real mainnet deposits.
Impact
The attacker could drain the mainnet deposit box and strand other users' tokens on Schain; the judge rated this Medium because it depends on the minter role being granted to a malicious party.
What the attacker needed
Attacker can deploy a token on Schain; attacker holds the minter role on that token; token is registered with the bridge; other users deposit into the mainnet box
The fix
Minting on the Schain token should be restricted so it can only happen through the bridge, for example by using an immutable minter address instead of a role.
How it was found
- Deploy an ERC20 clone on Schain that gives the deployer the minter role.
- Register the clone on the token manager with the owner function.
- Wait for other users to deposit tokens into the mainnet deposit box.
- Mint an amount equal to the locked transferred amount to the attacker's account.
- Call exit to mainnet with that amount to receive the locked tokens.
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 holds users' tokens on one chain (mainnet) and gives them a matching token on another chain (Schain). If someone can create extra tokens on Schain, they can swap them back through the bridge and take the real tokens that belong to everyone else. This report shows that a custom token contract with a mint function lets its owner do exactly that.
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.