The getUserMemorabiliaDetailed function should efficiently return all memorabilia owned by a user, minimizing gas costs.
Specific issue:
The function repeatedly reads from storage mappings (collections, balanceOf) inside nested loops, causing excessive gas usage as the number of collections and items grows.
Likelihood:
The bug will occur for any user with a large number of memorabilia tokens or as the number of collections/items increases.
Impact:
Users may experience high gas costs or even run out of gas when calling this function, especially as the contract grows in usage.
This can make the function impractical for users with many tokens.
The following Foundry test demonstrates the gas usage for a user with 5 memorabilia tokens. The measured gas for getUserMemorabiliaDetailed is 304,379 gas, run with forge test --gas-report to see the gas usage:
Cache storage reads in local variables to reduce redundant access, especially in nested loops:
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.