Submitted by PwnedNoMore, also found by 0xsanson, hyh, k, throttle, and zzzitron
https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityOrderBookComplication.sol#L154-L164
https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityOrderBookComplication.sol#L68-L116
https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityExchange.sol#L336-L364
https://github.com/code-423n4/2022-06-infinity/blob/765376fa238bbccd8b1e2e12897c91098c7e5ac6/contracts/core/InfinityExchange.sol#L178-L243
When any user provides a sellOrder and they are trying to sell multiple tokens from n (n > 1) different ERC1155 collections in a single order, hakcers can get the tokens of most expensive collections (with n times of the original amount) by paying the same price.
In short, hackers can violate the user-defined orders.
The logic of canExecTakeOrder and canExecMatchOneToMany is not correct.
Lets take canExecTakeOrder(OrderTypes.MakerOrder calldata makerOrder, OrderTypes.OrderItem[] calldata takerItems) as an example, while canExecMatchOneToMany shares the same error.
Specifically, it first checks whether the number of selling item in makerOrder matches with the ones in takerItems. Note that the number is an aggregated one. Then, it check whether all the items in takerItems are within the scope defined by makerOrder.
The problem comes when there are duplicated items in takerItems. The aggregated number would be correct and all takers Items are indeed in the order. However, it does not means takerItems exactly matches all items in makerOrder, which means violation of the order.
For example, if the order requires
and the taker provides
The taker can grabs two mock1155Contract1 tokens by paying the order which tries to sell a mock1155Contract1 token and a mock1155Contract2 token. When mock1155Contract1 is much more expensive, the victim user will suffer from a huge loss.
As for the approving issue, the users may grant the contract unlimited access, or they may have another order which sells mock1155Contract1 tokens. The attack is easy to perform.
First put the MockERC1155.sol under the contracts/ directory:
And then put poc.js under the test/ directory.
And run
Note that the passed test denotes a successful hack.
I would suggest a more gas-consuming approach by hashing all the items and putting them into a list. Then checking whether the lists match.
nneverlander (Infinity) confirmed and resolved:
HardlyDifficult (judge) commented:
