Skip to content
Access control Audit finding Beginner

Admin drains all ERC based user funds using withdrawERC20()

The Gravity contract includes a withdrawERC20 function that lets an admin transfer the entire balance of any ERC20 token held by the contract to their own address. An attacker with the admin role could drain all bridged tokens, leaving users' funds on the Cosmos chain without an ERC20 representation.

p Follow

Originally disclosed on Code4rena

Submitted by pcrypt0, also found by 0x1337, AmitN, csanuragjain, danb, dirky, GermanKuber, IllIllI, kirk-baird, and WatchPug

Gravity.sol#L632-L638 Gravity.sol#L595-L609

Ability for admin to drain all ERC20 funds stored in contract at will, meaning all ERC20 based Cudos tokens (and any other ERC20 tokens stored in the contract) could be extracted by anyone with admin role and later sold, leaving users funds bridged on Cudos Cosmos chain with no ERC20 representation stored across the bridge - similar in impact as the wormhole hack.

This issue ought to fall within the limits the team allocated on assessing the governance role setups, since it describes a full-fledged security risk regarding users’ funds. Crucially, this function is not in the original Gravity Bridge contract for Gravity.sol.

Furthermore, the function has not been commented and does not appear in the documentation, suggesting that it has perhaps not yet been reasoned through by the development team and it’s critical this is flagged in the security audit.

Proof of Concept

Firstly, User with admin role granted waits until CUDOS bridge has decent TVL from users bridging their CUDOS tokens from Ethereum to the CUDOS Cosmos chain,

Secondly, User manually calls withdrawERC20(address _tokenAddress) with the ERC token address of the CUDOS token

 function withdrawERC20(
			address _tokenAddress)
			external {
			require(cudosAccessControls.hasAdminRole(msg.sender), "Recipient is not an admin");
			uint256 totalBalance = IERC20(_tokenAddress).balanceOf(address(this));
			IERC20(_tokenAddress).safeTransfer(msg.sender , totalBalance);
}

Thirdly, withdrawERC20() function checks if user has admin role and if so withdraws all the tokens of a given token address straight to the admin’s personal wallet

               require(cudosAccessControls.hasAdminRole(msg.sender), "Recipient is not an admin");
		uint256 totalBalance = IERC20(_tokenAddress).balanceOf(address(this));
		IERC20(_tokenAddress).safeTransfer(msg.sender , totalBalance);

Fourth, user exchanges CUDOS on DEX and then sends funds to tornado cash, leaving all user funds at risk.

Tools Used

My own logical reasoning and discussion with team on Discord for confirmation of admin roles and function’s logic.

Recommended Mitigation Steps

Delete the function or alternatively, send all funds to the ‘0’ address to burn rather than give them to the admin.

Change withdrawERC20 to:

function burnERC20(
	address _tokenAddress)
	external {
	require(cudosAccessControls.hasAdminRole(msg.sender), "Recipient is not an admin");
	uint256 totalBalance = IERC20(_tokenAddress).balanceOf(address(0));
	- IERC20(_tokenAddress).safeTransfer(msg.sender , totalBalance);
     +   IERC20(_tokenAddress).safeTransfer(address(0) , totalBalance);
}

maptuhec (Cudos) acknowledged and commented:

The reason we have created this functions is that, if the bridge stop working, the funds for the users would be locked, and there is no chance to withdraw them. CUDOS have no intention and incentive to maliciously withdraw the ERC20 tokes, because that would lead to losing the trust in its clients and thus killing their own network. The best way for handling this is to communicate this with the community so they can be aware.

Albert Chon (judge) decreased severity to Medium


The original report as published on Code4rena, by p. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

The contract includes an admin-only function that transfers the entire ERC20 balance of any token to the admin's address, without any restriction or burn mechanism.

Impact

An admin could drain all ERC20 tokens held by the bridge, leaving users' bridged funds on the Cosmos chain with no ERC20 backing; the team argued they have no incentive to do so, and the judge rated it Medium.

What the attacker needed

Admin role on the bridge contract; bridge holds user-deposited ERC20 tokens

The fix

The function should be removed, or changed so that tokens are sent to the zero address to be burned rather than transferred to the admin.

How it was found

  1. An admin waits until the bridge holds a significant amount of user-deposited tokens.
  2. The admin calls withdrawERC20 with the address of the token they want to drain.
  3. The function checks that the caller has the admin role and then transfers the contract's entire balance of that token to the admin.
  4. The admin can then sell the tokens on a decentralised exchange and move the proceeds.

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 contract holds users' tokens while they are moved to another blockchain. This contract had a special function that let an administrator take all of those tokens out to their own wallet. If that administrator turned malicious, users would lose the tokens they had bridged.

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.

More from Cudos contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.