Skip to content
Access control Audit finding Intermediate

Scoop ERC20 tokens from basket contract

The settleAuction function allows an attacker to specify any output token, including unrelated ERC20 tokens that may have been sent to the basket contract by mistake or airdrop. An attacker can call bondForRebalance and settleAuction to transfer those tokens to themselves.

gpersoon Follow

Originally disclosed on Code4rena

Submitted by gpersoon

Impact

Suppose some unrelated ERC20 tokens end up in the basket contract (via an airdrop, a user mistake etc)

Then anyone can do a bondForRebalance() and settleAuction() to scoop these tokens.

The function settleAuction() allows you to specify an outputToken, so also completely unrelated tokens. Thus you can retrieve additional tokens with settleAuction()

Proof of Concept

https://github.com/code-423n4/2021-09-defiProtocol/blob/main/contracts/contracts/Auction.sol#L69 function settleAuction(.. address[] memory outputTokens, uint256[] memory outputWeights) public override { … for (uint256 i = 0; i < outputTokens.length; i++) { IERC20(outputTokens[i]).safeTransferFrom(address(basket), msg.sender, outputWeights[i]); }

Recommended Mitigation Steps

Check outputTokens are part of the previous basket tokens (e.g. basket.tokens() )

frank-beard (Kuiper) acknowledged

Alex the Entreprenerd (judge) commented:

If the Auction contract has any ERC20 that is not checked against the require, those tokens can be taken away for free. The warden didn’t directly mention this, but this can also apply to bounties. Any bounty specified in a token that is not protected can be taken without claiming the bounty (as the require won’t check for it)

I think that the finding has appropriate severity, although the warden didn’t directly mention the ability to steal bounties

The original report as published on Code4rena, by gpersoon. 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 settleAuction function does not validate that the outputTokens are among the basket's expected tokens.

Impact

Anyone could steal unrelated ERC20 tokens that end up in the basket contract, including tokens sent by mistake or as bounties.

What the attacker needed

Unrelated ERC20 tokens present in basket contract

The fix

The settleAuction function should check that each outputToken is part of the basket's token list.

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 holds tokens for trading. Normally, only the tokens it expects should be withdrawable. But the withdrawal function lets the caller name any token, so if someone accidentally sends a different token to the contract, anyone can take it.

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 gpersoon

View all

47 more disclosed reports, best first.

More from Kuiper 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.