Skip to content
Business logic Audit finding Intermediate

Auction.sol#settleAuction() Mishandling bounty state could potentially disrupt settleAuction()

The withdrawBounty function loads the bounty into memory, so setting bounty.active to false does not update the stored state. An attacker could reuse a bounty ID that appears active, causing settleAuction to revert and the bonder to lose their bond.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

https://github.com/code-423n4/2021-09-defiProtocol/blob/main/contracts/contracts/Auction.sol#L143

function withdrawBounty(uint256[] memory bountyIds) internal {
    // withdraw bounties
    for (uint256 i = 0; i < bountyIds.length; i++) {
        Bounty memory bounty = _bounties[bountyIds[i]];
        require(bounty.active);

        IERC20(bounty.token).transfer(msg.sender, bounty.amount);
        bounty.active = false;

        emit BountyClaimed(msg.sender, bounty.token, bounty.amount, bountyIds[i]);
    }
}

In the withdrawBounty function, bounty.active should be set to false when the bounty is claimed.

However, since bounty is stored in memory, the state update will not succeed.

Impact

An auction successfully bonded by a regular user won’t be able to be settled if they passed seemly active bountyIds, and the bonder will lose the bond.

Proof of Concept

  1. Create an auction;
  2. Add a bounty;
  3. Auction settled with bounty claimed;
  4. Create a new auction;
  5. Add a new bounty;
  6. Calling settleAuction() with the bountyIds of the 2 seemly active bounties always reverts.

Recommended Mitigation Steps

Change to:

Bounty storage bounty = _bounties[bountyIds[i]];

frank-beard (Kuiper) confirmed and marked as duplicate:**

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

Alex the Entreprenerd (judge) commented:

Finding is valid, because the warden didn’t provide a POC of how to steal user funds, the finding is of medium severity

The original report as published on Code4rena, by WatchPug. 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 bounty variable is declared as memory instead of storage, so the assignment to bounty.active does not persist.

Impact

An auction successfully bonded by a regular user won’t be able to be settled if they passed seemly active bountyIds, and the bonder will lose the bond.

What the attacker needed

A user creates an auction; a bounty is added and claimed; a new auction is created with a new bounty; settleAuction is called with old bounty IDs

The fix

The bounty variable should be declared as storage so that setting active to false persists.

How it was found

  1. Create an auction
  2. Add a bounty
  3. Settle the auction with the bounty claimed
  4. Create a new auction
  5. Add a new bounty
  6. Call settleAuction with the bounty IDs of the two seemingly active bounties, which always reverts

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 stores data in two places: permanent storage and temporary memory. The code copied the bounty into memory, changed it there, and threw it away, so the real record never changed. This means a bounty that was already paid out still looks active, and trying to settle an auction with that old bounty ID fails.

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 WatchPug

View all

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