Submitted by 00xSEV
LibSRUtil.transferShortRecord does not check the owner of nft.shortOrderId before canceling it. shortOrderIds are reused after the order is canceled.
An attacker can create a state for an NFT where the short records status is SR.PartialFill, but nft.shortOrderId is already reassigned to another user, yet still set in the attackers NFT. This will make the system think that it needs to cancel nft.shortOrderId, even though it belongs to another user already and does not reference the original order.
https://github.com/code-423n4/2024-03-dittoeth/blob/91faf46078bb6fe8ce9f55bcb717e5d2d302d22e/contracts/libraries/LibSRUtil.sol#L134-L136
For the example, we will use ids that would be used by a new asset (starting ids, 2 for shortRecord and 100 for short order).
Steps for the attacker, the simplest attack (see test1 function in PoC too):
The attacker can also create many NFTs and choose which orders to cancel as they wish (See the second function in PoC). The attacker can then create the NFTs again and start the attack again (See the third PoC).
Its also possible to have several NFTs on the same address or different addresses with the same nft.shortOrderId. It may also lead to accidental cancellation even if a user is not malicious.
The attacker has full control over which short orders appear on the order book; they can censor orders, manipulate the price by canceling orders with a low price.
Its possible to reduce others rewards by canceling shorts just before the rewards are due (Token yield is provided only after some time on the order book, see here).
The platform is unusable because short orders can be canceled at any time arbitrarily by an attacker, or several attackers/bad actors, who do not like some short orders.
forge test -vvv --match-path contracts/AANftAttack.sol
Invalid Validation
ditto-eth (DittoETH) confirmed
