Submitted by kenzo, also found by 0xDjango
https://github.com/code-423n4/2022-06-infinity/blob/main/contracts/core/InfinityExchange.sol#L178
https://github.com/code-423n4/2022-06-infinity/blob/main/contracts/core/InfinityExchange.sol#L216
https://github.com/code-423n4/2022-06-infinity/blob/main/contracts/core/InfinityExchange.sol#L230
matchOneToManyOrders doesnt conform to Checks-Effects-Interactions pattern, and updates the maker order nonce only after the NFTs and payment have been sent.
Using this, a malicious user can re-enter the contract and re-fulfill the order using takeOrders.
Orders can be executed twice. User funds would be lost.
matchOneToManyOrders will set the order nonce as used only after the tokens are being sent:
So we can see that tokens are being transferred before nonce is being set to executed.
Therefore, POC for an attack -
Alice wants to buy 2 unspecified WolfNFT, and she will pay via AMP, an ERC-777 token.
Malicious user Bob will set up an offer to sell 2 WolfNFT.
The MATCH_EXECUTOR will match the offers.
Bob will set up a contract such that upon receiving of AMP, it will call takeOrders with Alices order, and 2 other WolfNFTs.
(Note that although takeOrders is nonReentrant, matchOneToManyOrders is not, and so the reentrancy will succeed.)
So in takeOrders, the contract will match Alices order with Bobs NFTs, and then set Alices orders nonce to true, then matchOneToManyOrders execution will resume, and again will set Alices orders nonce to true.
Alice ended up buying 4 WolfNFTs although she only signed an order for 2. Tough luck, Alice.
(Note: a similar attack can be constructed via ERC721s onERC721Received.)
Conform to CEI and set the nonce to true before executing external calls.
nneverlander (Infinity) confirmed and resolved:
HardlyDifficult (judge) commented:
