Skip to content
RED SAGSkills
hard20 pts · first answer countsgas-optimisationsolidity

Expensive loop over storage

Which change saves the most gas in this function?

uint256[] public rewards;
uint256 public total;

function sum() external {
    for (uint256 i = 0; i < rewards.length; i++) {
        total += rewards[i];
    }
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions