The `getUserMemorabiliaDetailed()` function performs two complete iterations over all collections and items - first to count owned items, then again to populate the result arrays. This O(n²) approach becomes extremely gas-expensive as the number of collections and items grows, potentially causing the function to exceed gas limits or become economically unfeasible to call.
The normal behavior should efficiently retrieve user-owned memorabilia in a single pass. However, the current implementation uses a two-pass approach that doubles gas costs.
```solidity
function getUserMemorabiliaDetailed(address user) external view returns (...) {
// @> First iteration to count
uint256 count = 0;
for (uint256 cId = 1; cId < nextCollectionId; cId++) {
for (uint256 iId = 1; iId < collections[cId].currentItemId; iId++) {
uint256 tokenId = encodeTokenId(cId, iId);
if (balanceOf(user, tokenId) > 0) {
count++;
}
}
}
// @> Second iteration to populate
tokenIds = new uint256[](count);
// ... populate arrays with another nested loop
}
```
Likelihood:
* Function is called whenever user wants to view their memorabilia
* Gas cost increases quadratically with number of collections and items
* With many collections/items, function will become unusable
* No upper bound on collections or items per collection
Impact:
* Extremely high gas costs for users with many memorabilia items
* Potential denial of service if gas limit is exceeded
* Function becomes economically unfeasible to call
* Poor user experience
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.