The double for-loop iteration found in getUserMemorabiliaDetailed function is inefficient and causes high gas overhead for this view call function. The nextCollectionId is initialized at 100, but cId starts at 1, resulting unused iteration of all collection id below 100, this unnecessary memory reads adds on to the expensive view call.
Inefficient double for-loop was found in getUserMemorabiliaDetailed view function in addition to unused 100 iteration of collection id cId since nextCollectionId is initialized at 100. These will cause the view function becomes slow over time along with expesive high gas overhead and could even result this view function to revert when the collections grow too large.
Likelihood:
Whenever this view function is called, inefficiency and relatively high gas cost imposed due to the double for-loop iteration. It will get slower over time when the collections grow larger and larger
Impact:
Inefficient and expensive view function call that could get slow over time and potentially revert when collections grow large that hits the block gas limit
To refactor the code and implement a mapping function to correlate user address to list of owned memorabilias such as
mapping(address => uint256[]) public userOwnMemorabilias
Keep this mapping updated during redeemMemorabilia to directly capture the owned memorabilias.
Then in the getUserMemorabiliaDetailed function, simplify the codes by tapping on the userOwnMemorabilias mapping as suggested below:
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.