The price of a bid can be at most the maximum value of a uint80 and can be chosen by the bidder. When creating the bid, the price is multiplied by the ercAmount and stored in a uint256. If the bid is not matched at the time of creation, it goes onto the order book and waits for an Ask or a Short to match it. When a Short/Ask is created that matches the Bid, the ercAmount and the price of the Bid are multiplied again, but this time, they are stored in a uint88. It is possible that the result of this multiplication is greater than a uint88, which can lead to a revert, preventing the creation of the incoming Short/Ask.
Bids are sorted so that those with the highest price come first. If someone creates a bid with a very high price that goes into the order book, then the ercAmount of a new short/ask order can be at most such that the ercAmount multiplied by the price of the highest bid still fits into a uint88. This means that the maximum ercAmount that can be placed in a sell order depends on the highest Bid Price.
An attacker can now create a bid with the highest possible price. Therefore, a short/ask that is created must have an ercAmount of less than 1 ETH, as otherwise, the ercAmount multiplied by the bid price would be greater than a uint88, causing the short/ask creation to revert. Asks/Shorts have a minAskEth amount, so the ercAmount multiplied by the specified price must be greater than minAskEth. MinAskEth can be at most 0.255 ether. For shorts, there is an additional minShortErc, which checks that the ercAmount is high enough for a short. This can be at most the maximum value of a uint16.
It can be concluded that if a bid with the highest possible price is created, the only possible shorts/asks ercAmount must be less than 1 ETH and greater than minAskEth, and for a short, the ercAmount must also be greater than minShortErc.
Additionally if minShortErc is now greater than 1 ether, no shorts can be created.
This is the line where the error is thrown when the price of the highest bid is multiplied by the ercAmount during matching:
Here is a PoC that shows the short creation reverts when a bid with the highest price exists, and minShortErc is used as the ercAmount for the short:
The POC can be placed in the test folder and executed with this command: forge test --match-test testPOC -vv
The impact is, as described above, that the highest possible ercAmount from a Short/Ask depends on the highest Bid Price. This results in Asks can only created with a limited ercAmount, and shorts can not being created if minShortErc is higher than 1 ether. Nevertheless, in my opinion, the severity is only low. To create such a high bid, one must first possess enough ETH to deposit it.
VSCode, Foundry
The value that results from the multiplication of the highest Bid Price and the ercAmount should be stored in a uint256:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.