Bug in MatchOneToManyOrders may cause tokens theft
The MatchOneToManyOrders function does not check whether a sell order contains any NFT tokens, so an attacker can include an empty sell order that requests payment but transfers nothing. This allows the attacker to profit without giving up any NFT.
Originally disclosed on Code4rena
Submitted by PwnedNoMore
The MatchOneToManyOrders does not check whether a given sell order is malicious, i.e., containing no NFT tokens but still requiring payment.
This may cause the sellers to maliciously profit.
For example, we have a buyOrder and a set of sell orders [sellOrder0, sellOrder1, sellOrder2]. Originally, they match well but with a legal price gas (which is common in the real world), i.e., MatchOneToManyOrders(buyOrder, [sellOrder0, sellOrder1, sellOrder2]) can be successfully processed.
However, If the hacker proposes another sellOrder3 which sells nothing but requests money/tokens. The MatchOneToManyOrders(buyOrder, [sellOrder0, sellOrder1, sellOrder2, sellOrder3]) will also succeed and the hacker does not need to send out any NFT token but grabs a considerable gain.
Attack Scenario
There are two possible attack scenarios.
The MATCH_EXECUTOR is not in a good faith
MATCH_EXECUTOR can always gain profit by leveraging this vulnerability. That is, every time the executor proposes a MatchOneToManyOrders, it can add one more EMPTY order to gain the profit.
It is one kind of centralization issue. All the processes should happen in a trust-less environment.
Hackers can brute force the price gaps by sending out a large amount of EMPTY sell orders
Note that creating an order happens off-chain. That means, the hacker can send out a large amount of EMPTY orders without paying any gas fee.
Once the executor picks any of the malicious orders, the hacker can gain the profit without a loss of NFT tokens.
This vulnerability also affects matchOrders.
Proof of Concept
For full details, see original submission.
Recommended Mitigation Steps
To mitigate the issue entirely, I would suggest banning any empty NFT transfers.
For example, numNfts must be bigger than zero here. Also make sure the ERC1155 transferring at least 1 item.
nneverlander (Infinity) acknowledged and commented:
Please check this: https://github.com/infinitydotxyz/exchange-contracts-v2/commit/7f0e195d52165853281b971b8610b27140da6e41
No more ERC1155 either.
The loop that transfers NFTs already checks for non empty array
Not sure of the assessment.
HardlyDifficult (judge) decreased severity to Medium and commented:
This is a great report, appreciate the detail and the PoC code.
Given that the call must originate from the match executor, it seems unlikely that it would match with an empty sell order. Additionally it should be easy to filter these when submitted off-chain. With that in mind, lowering this to a Medium risk issue.
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 contract does not validate that the number of NFTs transferred in a sell order is greater than zero, allowing empty orders to be processed.
Impact
An attacker could profit without providing any NFT, but the attack requires the match executor to include the malicious order, and the judge noted it is unlikely the executor would do so and that such orders should be easy to filter off-chain.
What the attacker needed
Match executor includes the malicious order; attacker can create orders off-chain
The fix
The issue was fixed by banning empty NFT transfers and ensuring the loop that transfers NFTs checks for a non-empty array.
How it was found
- Create a buy order and several legitimate sell orders that match.
- Create an additional sell order that contains no NFT but requests payment.
- Submit all orders to MatchOneToManyOrders, which processes them successfully.
- The attacker receives payment without transferring any NFT.
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.
A smart contract function that matches buy and sell orders fails to verify that each sell order actually includes an NFT. An attacker can add a fake sell order that asks for payment but sends no NFT, and still get paid. This means the attacker steals money from the buyer without providing anything in return.
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.