An offer made after auction end can be stolen by an auction winner
An offer made for an NFT after an auction ended but before the winner collected the NFT could be stolen by the auction winner. The winner could accept the offer, causing the NFT to be transferred to themselves while the offer amount was also paid to them, leaving the offer maker without the NFT or their funds.
Submitted by hyh, also found by leastwood, shenwilly, and WatchPug
An Offer which is made for an NFT when auction has ended, but its winner hasn’t received the NFT yet, can be stolen by this winner as _transferFromEscrow being called by _acceptOffer will transfer the NFT to the winner, finalising the auction, while no transfer to the user who made the offer will happen.
This way the auction winner will obtain both the NFT and the offer amount after the fees at no additional cost, at the expense of the user who made the offer.
Proof of Concept
When an auction has ended, there is a possibility to make the offers for an auctioned NFT as:
makeOffer checks _isInActiveAuction:
https://github.com/code-423n4/2022-02-foundation/blob/main/contracts/mixins/NFTMarketOffer.sol#L200
_isInActiveAuction returns false when auctionIdToAuction[auctionId].endTime < block.timestamp, so makeOffer above can proceed:
Then, the auction winner can call acceptOffer -> _acceptOffer (or setBuyPrice -> _autoAcceptOffer -> _acceptOffer).
_acceptOffer will try to transfer directly, and then calls _transferFromEscrow:
If the auction has ended, but a winner hasn’t picked up the NFT yet, the direct transfer will fail, proceeding with _transferFromEscrow in the FNDNFTMarket defined order:
function _transferFromEscrow(
address nftContract,
uint256 tokenId,
address recipient,
address seller
) internal override(NFTMarketCore, NFTMarketReserveAuction, NFTMarketBuyPrice, NFTMarketOffer) {
super._transferFromEscrow(nftContract, tokenId, recipient, seller);
}
NFTMarketOffer._transferFromEscrow will call super as nftContractToIdToOffer was already deleted:
NFTMarketBuyPrice._transferFromEscrow will call super as there is no buy price set:
Finally, NFTMarketReserveAuction._transferFromEscrow will send the NFT to the winner via _finalizeReserveAuction, not to the user who made the offer:
The recipient user who made the offer is not present in this logic, the NFT is being transferred to the auction.bidder, and the original acceptOffer will go through successfully.
Recommended Mitigation Steps
An attempt to set a buy price from auction winner will lead to auction finalisation, so _buy cannot be called with a not yet finalised auction, this way the NFTMarketReserveAuction._transferFromEscrow L550-L560 logic is called from the NFTMarketOffer._acceptOffer only:
https://github.com/code-423n4/2022-02-foundation/blob/main/contracts/mixins/NFTMarketOffer.sol#L270
is the only user of
This way the fix is to update L556-L560 for the described case as:
Now:
// Finalization will revert if the auction has not yet ended.
_finalizeReserveAuction(auctionId, false);
// Finalize includes the transfer, so we are done here.
return;
To be, we leave the NFT in the escrow and let L564 super call to transfer it to the recipient:
// Finalization will revert if the auction has not yet ended.
_finalizeReserveAuction(auctionId, true);
NickCuso (Foundation) confirmed and commented:
Yes! This was a great find and a major issue with our implementation. I’m very happy that it was flagged by a few different people, it helps raise our confidence that several wardens really dove into the code.
It was a big miss on our part that this was not thoroughly tested. Our tests for this scenario confirmed the events and payouts, but did not validate the ownership in the end!
The proposed fix is perfect and exactly what we have implemented. This follows the patterns we established well, and actually simplifies the logic here so that things are easier to reason about.
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 _transferFromEscrow function finalises the auction and transfers the NFT to the auction winner instead of the offer recipient when an offer is accepted after the auction has ended but before the winner has collected the NFT.
Impact
The auction winner could obtain both the NFT and the offer amount, while the user who made the offer loses their funds and does not receive the NFT.
What the attacker needed
An auction has ended; the auction winner has not yet collected the NFT; a user makes an offer for the NFT; the auction winner accepts the offer
The fix
The fix was to change the escrow transfer logic so that when an offer is accepted after an auction has ended, the NFT is left in escrow and transferred to the offer recipient instead of finalising the auction to the winner.
How it was found
- An auction ends but the winner has not yet received the NFT.
- A user makes an offer for the NFT, which is allowed because the auction is no longer active.
- The auction winner calls acceptOffer (or setBuyPrice which triggers _autoAcceptOffer).
- The direct transfer fails, so _transferFromEscrow is called.
- The escrow transfer logic finalises the auction and sends the NFT to the winner, not the offer maker.
- The offer amount is paid to the winner, and the offer maker loses their funds.
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.
In an NFT auction, after the auction ends, the winner is supposed to receive the NFT. But if someone else makes an offer to buy the NFT during that gap, the auction winner can accept that offer. The code then sends the NFT to the winner (not the offer maker) and also pays the offer amount to the winner, so the offer maker loses their money and gets nothing.
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.