Skip to content
Business logic Audit finding Intermediate

Auction payout goes to AuctionDemo contract owner, not the token owner

The auction contract's claim function sends the winning bid to the contract owner instead of the token owner, so the token owner receives nothing from the sale. An attacker who is the contract owner could take the proceeds, though the report notes the token owner and contract owner are often the same trusted party.

bird-flu Follow with SovaSlava, devival and 24 others

Originally disclosed on Code4rena

Submitted by bird-flu, also found by SovaSlava, devival, 0xAadi, smiling_heretic, Kaysoft, Audinarey, Viktor_Cortess, Eigenvectors, DeFiHackLabs, rotcivegaf, cartlex_, 00decree, The_Kakers, Krace, jacopod, xAriextz, Hama, funkornaut, degensec, Fitro, AS, peanuts, evmboi32, xiao, REKCAH, and openwide

At the end of an auction in AuctionDemo, the highest bidder claims the token, which transfers the token from the token owner to the auction winner. In the same transaction, the token owner should receive the auction payout.

However, the function AuctionDemo::claimAuction() sends the payout to the AuctionDemo contract owner.

This behavior deviates from the listed invariant:

The highest bidder will receive the token after an auction finishes, the owner of the token will receive the funds and all other participants will get refunded.

  1. Auction is started, Alice deployed the AuctionDemo contract and Cecilia approved the AuctionDemo contract to transfer her tokens to the winning bidder.
  2. Auction is completed. The highest bid was Bob.
  3. Bob claims his winnings. The token is transferred from Cecilia to Bob. The bid from Bob is sent to Alice and Cecilia gets nothing.

Impact

Any auction executed through AuctionDemo will have proceeds sent to the AuctionDemo contract owner, not the token owner. The token owner is left without auction proceeds.

PoC

context("Auction Sends proceeds to owner of auctiondemo, not the token owner", () => {
    it.only("should execute", async () => {
    const tokenOwner = signers.addr2;
    const nextGenOwner = signers.owner;
    const highestBidder = signers.addr3;

    // Auction contract and collections Setup
    const AuctionDemo = await ethers.getContractFactory("auctionDemo");
    let auctionDemo = await AuctionDemo.deploy(
        await contracts.hhMinter.getAddress(),
        await contracts.hhCore.getAddress(),
        await contracts.hhAdmin.getAddress()
    );
    timestamp = (await ethers.provider.getBlock(await ethers.provider.getBlockNumber())).timestamp;

    await contracts.hhCore.addMinterContract(contracts.hhMinter.getAddress());
    await contracts.hhCore.createCollection(
        "Test Collection 1",
        "Artist 1",
        "For testing",
        "www.test.com",
        "CCO",
        "https://ipfs.io/ipfs/hash/",
        "",
        ["desc"],
    );
    await contracts.hhCore.addRandomizer(1, contracts.hhRandomizer.getAddress());
    await contracts.hhCore.connect(signers.owner).setCollectionData(1, signers.addr1.getAddress(), 100, 200, timestamp + 250);

    await contracts.hhMinter.setCollectionCosts(1, ethers.parseEther('.1'), ethers.parseEther('.1'), 0, 100, 0, signers.addr1.getAddress())
    await contracts.hhMinter.setCollectionPhases(1, timestamp + 25, timestamp + 50, timestamp + 100, timestamp + 150, '0x0000000000000000000000000000000000000000000000000000000000000000')

    await ethers.provider.send("evm_increaseTime", [20]);
    await contracts.hhMinter.connect(nextGenOwner).mintAndAuction(tokenOwner.getAddress(), "Test Auction 1", 10, 1, timestamp + 100);

    id1 = 10000000000;
    await contracts.hhCore.connect(tokenOwner).approve(auctionDemo.getAddress(), id1);

    // Winning auction bid
    await auctionDemo.connect(highestBidder).participateToAuction(id1, { value: ethers.parseEther('2') });

    // Move past auction end time and claim token
    await ethers.provider.send("evm_setNextBlockTimestamp", [timestamp + 101]);
    const transaction = auctionDemo.connect(highestBidder).claimAuction(id1);

    // get owner of auditDemo contract and make sure it's not the token owner for this usecase
    let owner = await auctionDemo.connect(nextGenOwner).owner();
    expect(owner).to.not.equal(tokenOwner.getAddress());

    // NextGen owner receives proceeds, token owner receives nothing.
    await expect(() => transaction).to.changeEtherBalance(nextGenOwner, ethers.parseEther('2'));
    await expect(() => transaction).to.changeEtherBalance(tokenOwner, 0);
    expect(await contracts.hhCore.ownerOf(id1)).to.eq(await highestBidder.getAddress());
    });
});

Recommendations

Send the auction proceeds to ownerOfToken instead of owner.

AuctionDemo L113-L114

@@ -110,8 +110,8 @@ contract auctionDemo is Ownable {
for (uint256 i=0; i< auctionInfoData[_tokenid].length; i ++) {
    if (auctionInfoData[_tokenid][i].bidder == highestBidder && auctionInfoData[_tokenid][i].bid == highestBid && 112| auctionInfoData[_tokenid][i].status == true) {
        IERC721(gencore).safeTransferFrom(ownerOfToken, highestBidder, _tokenid);
-       (bool success, ) = payable(owner()).call{value: highestBid}("");
-       emit ClaimAuction(owner(), _tokenid, success, highestBid);
+       (bool success, ) = payable(ownerOfToken).call{value: highestBid}("");
+       emit ClaimAuction(ownerOfToken, _tokenid, success, highestBid);

Assessed type

ETH-Transfer

a2rocket (NextGen) confirmed and commented via duplicate issue #245:

The mintAndAuction function can only be called by trusted parties. The _recipient of that function will be a trusted wallet that will also call setApprovalForAll() from the Core contract for the Auction Contract. In our case, the _recipient will be the deployer of the Auction contract; at the end of the day, the token owner and auction owner are the same person.

0xsomeone (judge) commented:

After re-visiting, I consider this submission to be better than #738 because it also correctly specifies that the event should be fixed rather than just the statement. While I cannot penalize submissions for not including the event in their proposed remediations, I can mark a submission that cites it and is of equivalent quality as “best”.

MrPotatoMagic (warden) commented:

@0xsomeone, here is why I believe this issue is QA at most:

  1. As per the sponsors comments here, the owner of the auction contract and the owner of the token are trusted team’s address. This means that whether the funds are sent to either, they are not lost, just that the team needs to make an additional fund transfer on their end (if needed).
  2. Although the invariant is broken, it has no impact on the functioning of the protocol. Due to this, I believe the severity should be QA at most.

0xsomeone (judge) commented:

@MrPotatoMagic, thanks for contributing! The code goes against its specification and breaks an invariant of the protocol. Regardless of severity, an invariant being broken will always be considered a medium-risk issue given that it relates to pivotal functionality in the system being incorrect.

In this case, funds are sent to a NextGen address rather than a collection-affiliated address or secondary smart contract meant to facilitate fund disbursements. This has implications tax-wise, implications about trust (i.e. if a 10m auction is held, the stakes of trust are increased significantly), and other such problems. Logistically, it is also a heavy burden to manage multiple auction payments at once, prove which source sent which, and so on.

Combining the above with the fact that a clear invariant of the protocol is broken, I will maintain the medium-risk rating.


The original report as published on Code4rena, by bird-flu. 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 payout uses the contract's owner() instead of the token's ownerOfToken when transferring the highest bid.

Impact

Any auction executed through AuctionDemo will have proceeds sent to the AuctionDemo contract owner, not the token owner, leaving the token owner without auction proceeds; the report notes the token owner and auction owner are often the same trusted party, so funds may not be lost but the invariant is broken.

What the attacker needed

AuctionDemo contract deployed; Token owner approves AuctionDemo; Auction ends with a winning bid

How it was found

  1. Deploy the AuctionDemo contract and set up a collection and minter.
  2. Mint a token and start an auction for it.
  3. Have the token owner approve the AuctionDemo contract to transfer the token.
  4. Place a winning bid from another account.
  5. Advance time past the auction end and call claimAuction from the winning bidder.
  6. Observe that the bid amount is sent to the AuctionDemo contract owner, not the token owner.

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.

When an auction ends, the winning bidder pays and should get the item, while the person who owned the item should get the money. In this code, the money goes to the person who controls the auction contract, not to the item's owner. That means the item's owner can lose out on the sale proceeds.

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 from NextGen

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.