EIP-712 signatures can be re-used in private sales
The private sale function did not track whether an EIP-712 signature had already been used, so a buyer could reuse the same signature to repurchase the NFT if the seller regained ownership and relisted it. An attacker could buy the NFT again at the original price, potentially profiting if the NFT's value had risen.
Within a NFTMarketPrivateSale contract, buyers are allowed to purchase a seller’s NFT. This is done through a seller providing a buyer a EIP-712 signature. The buyer can then call #buyFromPrivateSaleFor providing the v, r, and s values of the signature as well as any additional details to generate the message hash. If the signature is valid, then the NFT is transferred to the buyer.
The problem with the code is that EIP-712 signatures can be re-used within a small range of time assuming that the original seller takes back ownership of the NFT. This is because the NFTMarketPrivateSale#buyFromPrivateSaleFor method has no checks to determine if the EIP-712 signature has been used before.
Proof of Concept
Consider the following example:
Joe the NFT owner sells a NFT to the malicious buyer Rachel via a private sale.
Rachel through this private sale obtains the EIP-712 signature and uses it to purchase a NFT.
Joe the NFT owner purchases back the NFT within two days of the original sale to Rachel.
Joe the NFT owner puts the NFT back on sale.
Rachel, who has the original EIP-712 signature, can re-purchase the NFT by calling #buyFromPrivateSaleFor again with the same parameters they provided in the original private sale purchase in step 1.
The #buyFromPrivateSaleForfunction runs several validation checks before transferring the NFT over to the buyer. The validations are as follows:
L#132 - The signature has expired.
L#135 - The deadline is beyond 48 hours from now.
L#143 - The amount argument is greater than msg.value.
L#149 - The msg.value is greater than the amount set.
L#171 - This checks that the EIP-712 signature comes from the NFT seller.
As you can see, there are no checks that the EIP-712 signature has been used before. If the original NFT seller purchases back the NFT, then they are susceptible to having the original buyer taking back the NFT. This can be problematic if the NFT has risen in value, as the original buyer can utilize the same purchase amount from the first transaction in this malicious transaction.
Recommended Mitigation Steps
Most contracts utilize nonces when generating EIP-712 signatures to ensure that the contract hasn’t been used for. When a nonce is injected into a signature, it makes it impossible for re-use, assuming of course the nonce feature is done correctly.
Yes, this is a good point to raise and something like this could happen because it’s not intuitive to think that the private sale remains valid after it’s been used.
This is mitigated by the short time window we use for Private Sales. Our frontend uses 24-hour expirations and in the contract we ensure the window is <= 48 hours.
In order to remain backwards compatible with our existing integration and any signatures which are outstanding at the time of the upgrade, we decided not to use nonce as recommended. Instead we simply store a mapping tracking if the exact private sale terms have already been used.
Here’s the primary addition:
// Ensure that the offer can only be accepted once.
if (privateSaleInvalidated[nftContract][tokenId][msg.sender][seller][amount][deadline]) {
revert NFTMarketPrivateSale_Signature_Canceled_Or_Already_Claimed();
}
privateSaleInvalidated[nftContract][tokenId][msg.sender][seller][amount][deadline] = true;
The original report as published on Code4rena, by thankthedark. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
The contract lacked a mechanism to mark EIP-712 signatures as used, allowing replay within the signature's validity window.
Impact
The original buyer could repurchase the NFT at the original price if the seller regained ownership and relisted it, potentially profiting if the NFT's value increased; the short validity window (≤48 hours) limits the time for abuse.
What the attacker needed
Seller must have previously sold the NFT via private sale; seller must regain ownership and relist within signature…; attacker must possess the original signature
The fix
The project mitigated by storing a mapping to track used private sale terms, preventing reuse of the same signature.
How it was found
Joe sells an NFT to Rachel via private sale, providing an EIP-712 signature.
Rachel uses the signature to purchase the NFT.
Joe buys back the NFT within two days.
Joe relists the NFT for sale.
Rachel reuses the original signature to repurchase the NFT at the original price.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
When you buy something with a signed permission slip, the system should mark that slip as used so it can't be used again. Here, the contract didn't do that, so the same slip could be used multiple times if the item came back for sale. This means someone could buy the same NFT again at the old price, even if it's now worth more.
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.
More from Foundation Exhibition, Scheduling & Early Access Solo Audit by Lambda