Auction winner can prevent payments via safeTransferFrom callback
The auction settlement function transfers the NFT to the winner using safeTransferFrom, which calls back into the winner's contract. A malicious winner can revert in that callback, causing the whole settlement to fail so other bidders are never refunded and the seller never receives the winning bid.
The_Kakers Follow with Madalad, immeas and 48 others
Originally disclosed on Code4rena
Submitted by The_Kakers, also found by Madalad, immeas, DeFiHackLabs, Neon2835, xeros, Bauchibred, fibonacci, 00decree, SpicyMeatball, ChrisTina, Haipls, _eperezok, bdmcbri, alexxander, 0xarno, tnquanghuy0512, Ocean_Sky, spark, Talfao, r0ck3tz, Arabadzhiev, Tricko, 00xSEV, Jiamin, nuthan2x, lsaudit, cu5t0mpeo, 0x_6a70, bronze_pickaxe, circlelooper, rotcivegaf, Nyx, KupiaSec, Delvir0, BugsFinder0x, crunch, ke1caM, twcctop, Juntao, 0xJuda, amaechieth, 0xpiken, funkornaut, 0x180db, Taylor_Webb, BugzyVonBuggernaut, HChang26, ZdravkoHr, Timenov, dimulski, and 0x3b
An auction winner can decide to conditionally revert the claimAuction() execution.
This leads to the following impacts:
- Other bidders can’t get their funds back
- The protocol doesn’t receive the funds from the winning bid
This can lead to permanent loss of funds if the adversary decides to. As a drawback, they can’t get the NFT.
But nevertheless, they can use their control over the function to ask for a ransom, as the sum of other bids, plus the protocol earnings can be higher than the maximum bid itself and the damaged public image of the protocol for losing users funds.
It also breaks one of the main invariants of the protocol:
Properties that should NEVER be broken under any circumstance:
- 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.
Evaluated as Medium, as despite of the possibility of permanent assets lost, and breaking a main invariant, the adversary will have to take a loss as well; or persuade the participants via a ransom.
Proof of Concept
claimAuction() transfers the NFT using safeTransferFrom():
function claimAuction(uint256 _tokenid) public WinnerOrAdminRequired(_tokenid,this.claimAuction.selector){
/// ...
for (uint256 i=0; i< auctionInfoData[_tokenid].length; i ++) {
if (auctionInfoData[_tokenid][i].bidder == highestBidder && auctionInfoData[_tokenid][i].bid == highestBid && auctionInfoData[_tokenid][i].status == true) {
-> IERC721(gencore).safeTransferFrom(ownerOfToken, highestBidder, _tokenid); // @audit adversary can make it revert
-> (bool success, ) = payable(owner()).call{value: highestBid}(""); // @audit funds not transferred
emit ClaimAuction(owner(), _tokenid, success, highestBid);
} else if (auctionInfoData[_tokenid][i].status == true) {
-> (bool success, ) = payable(auctionInfoData[_tokenid][i].bidder).call{value: auctionInfoData[_tokenid][i].bid}(""); // @audit funds not transferred
emit Refund(auctionInfoData[_tokenid][i].bidder, _tokenid, success, highestBid);
} else {}
}
}
safeTransferFrom() calls back the receiver if it is a contract.
An adversary that won the auction can conditionally revert the execution of the transaction, upon the onERC721Received() callback.
This will revert the whole transaction, making it impossible to transfer any funds.
Bidders can’t cancel their bids either via cancelBid() or cancelAllBids(), due to they only allow it to do so if the auction was not ended: AuctionDemo.sol#L125
The protocol, nor the previous token owner have a way to claim the earnings from the auction.
Recommended Mitigation Steps
Move the logic to transfer the NFT to its own separated function.
Assessed type
DoS
The Warden specifies that the winning bidder may not implement a proper EIP-721 receive hook either deliberately or by accident.
I consider this to be an exhibit validly categorized as a medium given that its impact is sabotage (i.e. loss-of-funds for other users) at the expense of a single high bid and it can also be used as extortion.
This submission was selected as the best given that it cites the voidance of a main invariant of the protocol, articulates that the funds are irrecoverable, and mentions that it should be marked as a medium given that the attacker would also lose their bid.
@0xsomeone, while #739 could be critical, the high cost makes it unlikely. To execute the attack, the malicious actor must win an auction, risking their funds to lock others’ funds, which is impractical in real-world scenarios. You can check #1508 where I discussed the issue without providing a PoC, as it is QA at max, here:
Attackers can exploit this using
onERC721Receivedtoo, but it’s costlier since they need to be the highest bidder to claim the NFT.
@btk, thanks for your contribution! I believe you are misjudging why this was selected as a medium-risk vulnerability while #734 is a high-risk vulnerability.
Yes, the would-be attacker would need to be the winning bidder but they would acquire an NFT regardless that would offset the cost of the attack. Additionally, any bidder can simply “choose” to carry this attack or simply acquire the NFT. Specifying that the attack would be impractical is identical to saying users would not participate in auctions and win.
The likelihood might be low, but the impact is high rendering this an aptly graded medium-risk vulnerability. #734 has a lower bar of entry and has been marked as high-risk as such. This was already elaborated in the relevant comment of this submission.
Note: For full discussion, see here.
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
Impact
Other bidders cannot get their funds back and the protocol does not receive the winning bid, potentially causing permanent loss of funds, though the attacker also loses their bid and does not receive the NFT.
What the attacker needed
Win the auction with a malicious contract; contract reverts in onERC721Received
The fix
The logic to transfer the NFT should be moved to its own separate function.
How it was found
- Win the auction with a contract that implements an ERC721 receive hook which reverts.
- Call claimAuction for the token.
- The safeTransferFrom call invokes the winner's hook, which reverts.
- The whole transaction reverts, so no refunds or seller payment occur.
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 a smart contract receives an NFT through a 'safe' transfer, the NFT contract calls a function on the receiving contract to confirm it can handle the token. If that function fails or deliberately reverts, the entire transaction is undone. Here the winner's contract can refuse the token, which cancels the refunds and the payment to the seller in the same transaction.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.