Skip to content
Access control Audit finding Intermediate

Owner can transfer all ERC20 reward token out using function recoverERC20

The contract's owner-only recoverERC20 function lets the owner withdraw any token, including reward tokens meant for users. Because the owner can first remove a token from the whitelist, the safeguard fails and the owner can transfer all reserved reward tokens to themselves, causing loss of funds for pledge creators and rewards for users.

ladboy233 Follow with yixxas, JTJabba and 24 others

Originally disclosed on Code4rena

Submitted by ladboy233, also found by yixxas, JTJabba, rbserver, Aymen0909, horsefacts, minhtrng, 0xhunter, Trust, peritoflores, 0xDecorativePineapple, Dravee, hansfriese, imare, Jeiwan, wagmi, 0x52, Picodes, cryptonue, pashov, Bnke0x0, Lambda, Nyx, cccz, dic0de, csanuragjain, and rvierdiiev

The function recoverERC20 is very privileged. It means to recover any token that is accidently sent to the contract.

function recoverERC20(address token) external onlyOwner returns(bool) {
	if(minAmountRewardToken[token] != 0) revert Errors.CannotRecoverToken();

	uint256 amount = IERC20(token).balanceOf(address(this));
	if(amount == 0) revert Errors.NullValue();
	IERC20(token).safeTransfer(owner(), amount);

	return true;
}

However, admin / owner can use this function to transfer all the reserved reward tokens, which result in fund loss of the pledge creator and the loss of reward for users that want to delegate the veToken.

Also, the recovered token is sent to owner directly instead of sending to a recipient address.

The safeguard

if(minAmountRewardToken[token] != 0)

cannot stop owner transferring funds because if the owner is compromised or misbehaves, he can adjust the whitelist easily.

Proof of Concept

The admin can set minAmountRewardToken[token] to 0 first by calling updateRewardToken:

function updateRewardToken(address token, uint256 minRewardPerSecond) external onlyOwner {

By doing this the admin removes the token from the whitelist, then the token can call recoverERC20 to transfer all the token into the owner wallet.

function recoverERC20(address token) external onlyOwner returns(bool) {

Recommended Mitigation Steps

We recommend that the project uses a multisig wallet to safeguard the owner’s wallet.

We can also keep track of the reserved amount for rewarding token and only transfer the remaining amount of token out.

 pledgeAvailableRewardAmounts[pledgeId] += totalRewardAmount;
 reservedReward[token] += totalRewardAmount;

Then we can change the implementation to:

function recoverERC20(address token, address recipient) external onlyOwner returns(bool) {

	uint256 amount = IERC20(token).balanceOf(address(this));
	if(amount == 0) revert Errors.NullValue();

	if(minAmountRewardToken[token] == 0) {
	 // if it is not whitelisted, we assume it is mistakenly sent,
	   // we transfer the token to recipient
	 IERC20(token).safeTransfer(recipient, amount);
	} else {
	// revert if the owner over transfer
	if(amount >  reservedReward[token]) revert rewardReserved();
	  IERC20(token).safeTransfer(recipient, amount - reservedReward[token]);
	}

	return true;

}

Kogaroshi (Paladin) confirmed

Kogaroshi (Paladin) commented:

Interesting proposed Mitigation to be noted.


The original report as published on Code4rena, by ladboy233. 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

Likely the recoverERC20 function allows the owner to transfer any token balance without checking whether those tokens are reserved for rewards, and the owner can also remove a token from the whitelist to bypass the only safeguard.

Impact

The owner could transfer all reserved reward tokens, causing loss of funds for pledge creators and loss of rewards for users who delegate veToken.

What the attacker needed

Owner is compromised or misbehaves

The fix

The project should use a multisig wallet for the owner and track reserved reward amounts so that recoverERC20 only transfers tokens that are not reserved for rewards.

How it was found

  1. The owner calls updateRewardToken to set minAmountRewardToken[token] to 0, removing the token from the whitelist.
  2. The owner then calls recoverERC20 for that token.
  3. The function transfers the entire token balance to the owner's address.

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 smart contract has a special function that only the owner can call, meant to rescue tokens sent by mistake. But the owner can also use it to take tokens that were set aside as rewards for users. The owner can even change the rules first so the safety check does not stop them.

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 by ladboy233

View all

47 more disclosed reports, best first.

More from Paladin - Warden Pledges 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.