Description:
It was noted that the for loop in ThePredicter.sol::withdraw()
is looping through players.length
which is stored in storage instead of memeory which is less efficient and more gas expensive. Caching storage variables used in loops helps optimize gas usage and improve the efficiency of smart contracts.
Impact:
Accessing storage variables can be gas expensive as each read operation from storage costs significantly more than compared to when reading from memory. By repeatedly accessing a storage variable within a loop, the gas costs accumulate.
Tooling:
Gas ineficiencies can commonly be detected by static code analysis tools such as Slither.
Remediation:
Copy the players.length
to a memory variable before the loop to reduce the number of expensive storage reads. Following is an example of how this can be accomplished:
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.