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

AuctionDemo#claimAuction - A malicious user could steal the NFT by being the winner and canceling their bid on the last block timestamp #1896

Closed
c4-submissions opened this issue Nov 13, 2023 · 4 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-1323 partial-50 Incomplete articulation of vulnerability; eligible for partial credit only (50%)

Comments

@c4-submissions
Copy link
Contributor

Lines of code

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

Vulnerability details

Impact

The vulnerability arises due to a timing issue where block.timestamp is used as a condition to gate both the claimAuction and cancelBid functions. Specifically, when block.timestamp is equal to minter.getAuctionEndTime(_tokenId), a user can invoke both functions in the same transaction block. This is because the conditional check uses <= instead of <. Consequently, a malicious actor could claim the auctioned token with claimAuction and then invalidate their bid by calling cancelBid, retrieving their bid amount and effectively receiving the token without payment.

Proof of Concept

The attack can be executed as follows:

  1. Ensure you are the highest bidder in the auction.
  2. Monitor the block time closely. When block.timestamp is exactly equal to minter.getAuctionEndTime(_tokenId), execute claimAuction.
  3. In the same transaction block, call cancelBid. Due to the condition block.timestamp <= minter.getAuctionEndTime(_tokenId), this will succeed.
  4. Retrieve the bid amount, thus obtaining the token at no cost.

Tools Used

Manual Review.

Recommended Mitigation Steps

  • Adjust the conditional checks to ensure that cancelBid cannot be called in the same block as claimAuction. This can be achieved by using a strict inequality (<) in cancelBid.
  • Set auctionClaimed to true when claimAuction is successfully called. This variable should then be checked in the cancelBid function to prevent bid cancellation after a claim (require(auctionClaim[_tokenid] = false)

Assessed type

Invalid Validation

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

141345 marked the issue as duplicate of #1904

@c4-pre-sort
Copy link

141345 marked the issue as duplicate of #962

@c4-judge
Copy link

c4-judge commented Dec 4, 2023

alex-ppg marked the issue as duplicate of #1323

@c4-judge
Copy link

c4-judge commented Dec 8, 2023

alex-ppg marked the issue as partial-50

@c4-judge c4-judge added the partial-50 Incomplete articulation of vulnerability; eligible for partial credit only (50%) label Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-1323 partial-50 Incomplete articulation of vulnerability; eligible for partial credit only (50%)
Projects
None yet
Development

No branches or pull requests

3 participants