Skip to content
RED SAG Skills
hardStudy question · answer published in Blockchain interview questions, so no pointsgas-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