The function getUserMemorabiliaDetailed(address user) is used to fetch all memorabilia NFTs a user owns by checking each item in every collection. However, it uses two nested loops:
The first loop iterates over all collection and item IDs to count how many tokens the user owns.
The second loop repeats the exact same iteration to populate the arrays with matching token IDs and details.
This double iteration is redundant and gas-inefficient, especially as the number of collections and items grows. Every call to balanceOf(user, tokenId) is also expensive, and the function calls it twice per item.
HIGH :
No external condition required
Likelihood:
HIGH :
Iteratration over every possible tokenId, even ones no one owns.
Calling balanceOf(user, tokenId) many times (very expensive in large collections).
No mapping from users to owned token IDs exists.
Impact:
Out of gas errors
High gas consuming functions
Use mappings to reduce double loops calls
Track the actual count with an index.
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.