getUserMemorabiliaDetailed loops from cId = 1 through nextCollectionId, but memorabilia collections start at ID 100 (nextCollectionId = 100 at deployment). IDs 1 through 99 will never contain memorabilia collections, so the first 99 iterations of each loop are wasted gas. The function also runs this loop twice (once for counting, once for populating), doubling the waste.
For the counting loop: IDs 1-3 are pass token IDs (GENERAL, VIP, BACKSTAGE). collections[1].currentItemId is 0 (uninitialized), so the inner loop body doesn't execute, but the outer loop still runs 99 iterations of SLOAD for collections[cId].currentItemId before reaching real collections at ID 100.
As more collections are created (nextCollectionId grows), the gas cost scales linearly. With 10 memorabilia collections (nextCollectionId = 110), the function executes 110 * 2 = 220 outer loop iterations when only 10 * 2 = 20 are needed. Additionally, the nested loop structure is O(collections * maxItemsPerCollection), which compounds the gas issue for off-chain callers using eth_call.
Likelihood:
This view function is called by any frontend or integration that displays a user's memorabilia collection. Every call wastes gas on empty iterations.
Impact:
Increased gas costs for off-chain callers. As collections accumulate, the function may exceed block gas limit for eth_call, returning empty results or timing out. No funds at risk since this is a view function.
Output:
Start the loop at 100 (the initial nextCollectionId value) or store the first collection ID:
The contest is live. Earn rewards by submitting a finding.
Submissions are being reviewed by our AI judge. Results will be available in a few minutes.
View all submissionsThe contest is complete and the rewards are being distributed.