Skip to content
Business logic Audit finding Intermediate

Unsafe approve would halt the auction and burn the bond

The Basket contract calls approve without handling non-standard ERC20 tokens that revert when the allowance is not zero. An attacker could cause the auction bonder to lose their bond and suspend the auction by using such a token.

jonah1005 Follow

Originally disclosed on Code4rena

Submitted by jonah1005, also found by 0xRajeev, 0xsanson, cmichel, and itsmeSTYJ

Impact

Basket.sol#L224-L228 calls approve that do not handle non-standard erc20 behavior.

  1. Some token contracts do not return any value.
  2. Some token contracts revert the transaction when the allowance is not zero.

Since the auction contract calls setNewWeights in function settleAuction, auctionBonder may lock its bond and never successfully settles the auction. This leads to the auctionBonder loss he’s bond and the basket and the auction becomes suspended.

auctionBonder would lose his bond and the contract would be suspended. I consider this a high-risk issue.

Proof of Concept

USDT may be a classic non-standard erc20 token.

Here’s a short POC.

usdt.functions.approve(basket.address, 100).transact()
## the second tx would be reverted as the allowance is not zero
usdt.functions.approve(basket.address, 50).transact()

Tools Used

None

Recommended Mitigation Steps

Recommend to use safeApprove instead and set the allowance to 0 before calling it.

function approveUnderlying(address spender) private {
    for (uint256 i = 0; i < weights.length; i++) {
        IERC20(tokens[i]).safeApprove(spender, 0);
        IERC20(tokens[i]).safeApprove(spender, type(uint256).max);
    }
}

frank-beard (Kuiper) marked as duplicate:

duplicate of https://github.com/code-423n4/2021-09-defiprotocol-findings/issues/260

Alex the Entreprenerd (judge) commented:

Agree with the finding, because this is contingent on an external condition (token being USDT) the finding is of medium severity

The original report as published on Code4rena, by jonah1005. 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 contract uses the standard ERC20 approve function without checking for tokens that require the allowance to be reset to zero before setting a new value.

Impact

The auction bonder could lose their bond and the auction could become suspended, but this only happens if the token is non-standard like USDT.

What the attacker needed

The token used is non-standard (e.g., USDT); The allowance is not zero before the approve call

The fix

The contract should use safeApprove and set the allowance to zero before setting a new allowance.

How it was found

  1. The auction bonder calls settleAuction, which calls setNewWeights, which calls approve on the token.
  2. If the token is USDT and the allowance is not zero, the approve call reverts.
  3. The bond remains locked and the auction cannot be settled.

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.

Some tokens, like USDT, behave differently from the standard: they refuse to change an allowance unless it is first set to zero. The contract did not account for this, so when it tried to approve the token again, the transaction failed. This could trap the bonder's money and stop the auction from working.

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.

More by jonah1005

View all

39 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.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.