Submitted by hihen
Note: Prior to this audit, a group of wardens added test coverage. While auditing was not the purpose of the testing phase, relevant and valuable findings reported during that timeframe were eligible to be judged. As such, this finding [M-01] was discovered during the testing squad phase and is being included here for completeness.
Subprotocol NFTs may be trapped in contract CidNFT forever.
When adding NFT to CidNFT with AssociationType ORDERED or PRIMARY, the cidData is written directly, without checking and handling the case that a previously added nft may not have been removed:
For AssociationType.ORDERED:
If (key1, subNft1) and (key1, subNft2) were added consecutively, subNft1 would be trapped in the contract forever, because subNft1 stored in cidData was overwritten by subNft2, and only subNft2 can be retrieved through CidNFT.remove().
For AssociationType.PRIMARY:
If subNft1 and subNft2 were added consecutively, subNft1 would be trapped in the contract forever, because subNft1 stored in cidData was overwritten by subNft2, and only subNft2 can be retrieved through CidNFT.remove().
Test code for PoC:
VS Code
Should revert the tx if an overwriting is found in CidNFT.add():
OpenCoreCH (Canto Identity) confirmed
