The OwnerFacet.createMarket
function does not prevent the overflow of the assetId
, leading to assets with non-unique IDs.
The OwnerFacet.createMarket
function is responsible for creating new markets in the Ditto protocol. When a market is created, several storage variables are set for the market's asset. These variables include the assetId
, the asset's address in the assetMapping
, and the asset's address in the assets array. The length of the assets array is used to determine the new assetId
. However, it's important to note that the Asset.assetId
is of type uint8
, which can only hold values from 0 to 255. As a result, s.assets.length
is cast to uint8
, which effectively limits the number of markets to a maximum of 255.
The only requirement for this function is that the asset should not already be contained in s.asset
, but there is no requirement to check if the limit of markets has been reached.
If an attempt is made to create a new market when there are already 255 markets added, the 256th assetId
will be 0, as uint8(s.assets.length)
will overflow to 0. This could result in multiple assets having the same assetId
, potentially causing serious issues in the contract's functionality.
Place the following test case in test/CreateMarket.t.sol and run it with the command forge test --mt testCreateMarketOverflow -vv
.
Result:
The Asset's assetId
will not be unique, potentially causing serious issues in the protocol's functionality.
The assetId
is used in the ERC721Facet
for ShortRecord
transferring, which will not be possible if there are more than one assets with the same IDs.
Manual Review
Ensure that when the maximum market number is reached, it will not be possible to create new markets. Add a require statement at the beginning of the market creation function as follows:
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.