Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Owner of the token will not receive the funds of the highest bid after an Auction is claimed #245

Closed
c4-submissions opened this issue Nov 3, 2023 · 9 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) downgraded by judge Judge downgraded the risk level of this issue duplicate-971 satisfactory satisfies C4 submission criteria; eligible for awards sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") sufficient quality report This report is of sufficient quality

Comments

@c4-submissions
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-10-nextgen/blob/8b518196629faa37eae39736837b24926fd3c07c/smart-contracts/AuctionDemo.sol#L113-L114

Vulnerability details

Impact

In claimAuction function of AuctionDemo.sol, token owner should receive funds, but it will be transferred to AuctionDemo contract's owner.

    (bool success, ) = payable(owner()).call{value: highestBid}("");
    emit ClaimAuction(owner(), _tokenid, success, highestBid);

Proof of Concept

I tried to write tests for mintAndAuction and I'm attaching them below.

AuctionDemo.t.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.19;

import {console} from "forge-std/console.sol";
import {DeployHelper} from "./DeployHelper.t.sol";
import {NextGenRandomizerNXT} from "../smart-contracts/RandomizerNXT.sol";
import {auctionDemo} from "../smart-contracts/AuctionDemo.sol";
import {NextGenMinterContract} from "../smart-contracts/MinterContract.sol";
import {IERC721Receiver} from "../smart-contracts/IERC721Receiver.sol";

contract AuctionDemoTest is DeployHelper {

    function setupEnv() public virtual override {
        super.setupEnv();

        // burn collection 0
        vm.startPrank(funcAdminColManager);
        coreContract.createCollection("BurnCol", "", "ColDesc", "", "", "", "", new string[](0));

        // new collection 1
        coreContract.createCollection("NewCol", "", "ColDesc", "", "", "", "", new string[](0));

        vm.stopPrank();
    }
    
    function test_auction() public {

        uint256 collectionID = 2;
        uint256 collectionTotalSupply = 10;
        vm.warp(1 days);
        uint256 auctionEndTime = block.timestamp + 1 days;
        uint allowlistStartTime = block.timestamp;
        uint256 timePeriod = 2 minutes;
        uint256 tokenId;

        // mint and auction
        vm.startPrank(funcAdminColManager);
        vm.deal(funcAdminColManager, 1 ether);
        coreContract.addRandomizer(collectionID, address(new NextGenRandomizerNXT(address(randomPoolContract), address(adminContract), address(coreContract))));
        coreContract.setCollectionData(collectionID, artist, 100, collectionTotalSupply, 0);
        minterContract.setCollectionCosts(collectionID, 0, 0, 0, timePeriod, 0, address(0x0));
        minterContract.setCollectionPhases(collectionID, allowlistStartTime, 0, 0, 0, 0);
        minterContract.mintAndAuction(customer4, "", 0, collectionID, auctionEndTime);
        tokenId = coreContract.viewTokensIndexMin(collectionID) + coreContract.viewCirSupply(collectionID) - 1;
        vm.stopPrank();

        // do auction
        vm.deal(customer1, 1 ether);
        vm.deal(customer2, 1 ether);
        vm.deal(customer3, 1 ether);

        vm.prank(customer1);
        auctionContract.participateToAuction{value: 0.1 ether}(tokenId);
        vm.prank(customer2);
        auctionContract.participateToAuction{value: 0.2 ether}(tokenId);
        vm.prank(customer3);
        auctionContract.participateToAuction{value: 0.4 ether}(tokenId);

        assertEq(customer4.balance, 0, "token owner balance isn't zero");
        assertEq(coreContract.balanceOf(customer4), 1);
        assertEq(coreContract.balanceOf(customer1), 0, "customer1 has some nfts");
        assertEq(coreContract.balanceOf(customer2), 0, "customer2 has some nfts");
        assertEq(coreContract.balanceOf(customer3), 0, "customer3 has some nfts");

        vm.prank(customer4);
        coreContract.approve(address(auctionContract), tokenId);

        vm.warp(minterContract.getAuctionEndTime(tokenId));

        vm.prank(customer3);
        auctionContract.claimAuction(tokenId);

        assertEq(customer1.balance, 1 ether, "1");
        assertEq(coreContract.balanceOf(customer1), 0);
        assertEq(customer2.balance, 1 ether, "2");
        assertEq(coreContract.balanceOf(customer2), 0);
        assertEq(customer3.balance, 0.6 ether, "3");
        assertEq(coreContract.balanceOf(customer3), 1);
        assertEq(customer4.balance, 0.4 ether, "token owner didn't get eth");
        assertEq(coreContract.balanceOf(customer4), 0);
    }
}

DeployHelper.t.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.19;

import "forge-std/Test.sol";
import {NextGenAdmins} from "../smart-contracts/NextGenAdmins.sol";
import {NextGenMinterContract} from "../smart-contracts/MinterContract.sol";
import {NextGenCore} from "../smart-contracts/NextGenCore.sol";
import {auctionDemo} from "../smart-contracts/AuctionDemo.sol";
import {randomPool} from "../smart-contracts/XRandoms.sol";

abstract contract DeployHelper is Test {
    NextGenCore coreContract;
    NextGenAdmins adminContract;
    NextGenMinterContract minterContract;
    randomPool randomPoolContract;
    auctionDemo auctionContract;

    address public admin = vm.addr(0x01);
    address public funcAdminColManager = vm.addr(0x02);
    address public artist = vm.addr(0x04);
    address public customer1 = vm.addr(0x05);
    address public customer2 = vm.addr(0x06);
    address public customer3 = vm.addr(0x07);
    address public customer4 = vm.addr(0x08);

    function setUp() public {
        setupEnv();
    }

    function setupEnv() public virtual {
        vm.startPrank(admin);
        adminContract = new NextGenAdmins();
        coreContract = new NextGenCore("TNextGen", "TNG", address(adminContract));
        minterContract = new NextGenMinterContract(address(coreContract), address(0x0), address(adminContract));
        randomPoolContract = new randomPool();
        coreContract.addMinterContract(address(minterContract));
        auctionContract = new auctionDemo(address(minterContract), address(coreContract), address(adminContract));

        // register collection func admin
        adminContract.registerFunctionAdmin(funcAdminColManager, NextGenCore.createCollection.selector, true);
        adminContract.registerFunctionAdmin(funcAdminColManager, NextGenCore.setCollectionData.selector, true);
        adminContract.registerFunctionAdmin(funcAdminColManager, NextGenMinterContract.setCollectionCosts.selector, true);
        adminContract.registerFunctionAdmin(funcAdminColManager, NextGenMinterContract.setCollectionPhases.selector, true);
        adminContract.registerFunctionAdmin(funcAdminColManager, NextGenCore.addRandomizer.selector, true);
        adminContract.registerFunctionAdmin(funcAdminColManager, NextGenMinterContract.mintAndAuction.selector, true);
        vm.stopPrank();
    }
}

Tools Used

VS Code, Manual Review

Recommended Mitigation Steps

    (bool success, ) = payable(ownerOfToken).call{value: highestBid}("");
    emit ClaimAuction(ownerOfToken, _tokenid, success, highestBid);

Assessed type

Other

@c4-submissions c4-submissions added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Nov 3, 2023
c4-submissions added a commit that referenced this issue Nov 3, 2023
@c4-pre-sort
Copy link

141345 marked the issue as primary issue

@c4-pre-sort c4-pre-sort added the primary issue Highest quality submission among a set of duplicates label Nov 14, 2023
This was referenced Nov 14, 2023
@c4-sponsor
Copy link

a2rocket marked the issue as disagree with severity

@c4-sponsor c4-sponsor added the disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) label Nov 22, 2023
@a2rocket
Copy link

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 so at the end of the day the token owner and auction owner are the same person.

@c4-sponsor
Copy link

a2rocket (sponsor) disputed

@c4-sponsor c4-sponsor added sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") and removed sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue labels Nov 24, 2023
@c4-sponsor
Copy link

a2rocket (sponsor) confirmed

This was referenced Nov 25, 2023
@c4-pre-sort c4-pre-sort added the sufficient quality report This report is of sufficient quality label Nov 27, 2023
@c4-pre-sort
Copy link

141345 marked the issue as sufficient quality report

@c4-judge c4-judge closed this as completed Dec 5, 2023
@c4-judge c4-judge added duplicate-738 and removed primary issue Highest quality submission among a set of duplicates labels Dec 5, 2023
@c4-judge
Copy link

c4-judge commented Dec 5, 2023

alex-ppg marked issue #738 as primary and marked this issue as a duplicate of 738

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Dec 8, 2023
@c4-judge
Copy link

c4-judge commented Dec 8, 2023

alex-ppg marked the issue as satisfactory

@c4-judge
Copy link

c4-judge commented Dec 9, 2023

alex-ppg changed the severity to 2 (Med Risk)

@c4-judge c4-judge added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Dec 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) downgraded by judge Judge downgraded the risk level of this issue duplicate-971 satisfactory satisfies C4 submission criteria; eligible for awards sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") sufficient quality report This report is of sufficient quality
Projects
None yet
Development

No branches or pull requests

5 participants