The current implementation of getUserMemorabiliaDetailed() is highly gas inefficient.
Although the global state variable nextCollectionId starts from 100, the outer loop begins iteration from cId = 1, resulting in unnecessary loop executions over unused or non-existent collection IDs.
Additionally, both the outer and inner loops repeatedly access state variables (nextCollectionId and collections[cId].currentItemId), which are stored in contract storage. These epeated SLOAD operations in each iteration result in additional gas cost.
Likelihood:
This inefficiency incurs gas overhead every time getUserMemorabiliaDetailed() is invoked
Impact:
Based on the Known Issues, we know that the project pays attention to gas optimization, and this implementation is obviously inefficient
While this is not a direct security vulnerability, it increases gas costs for users interacting with the function on-chain
It may discourage usage if the function is part of a core user experience, such as displaying collected memorabilia
Add the following test, then run the command: forge test -vv --match-test test_GetUserMemorabiliaDetailed_GasCost
PoC Results:
Let cId start from 100, result gas cost:
Furthermore, create a local copy of nextCollectionId and collections[cId].currentItemId, resulting gas cost:
Final version:
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.