FV-SOL-9-C1 Dynamic Array

TLDR

This issue arises when a loop iterates over a dynamic array (an array whose size can grow over time) without bounds or a reasonable upper limit

Game

Hoping that the array size can't grow too large..?

// SPDX-License-Identifier: MIT
// Open me in VSCode and really think before opening the hints!
// Add @audit tags wherever suspicious
// Go to the solidity docs to complete missing knowledge of what's happening here
// Solve by drafting a fix!
pragma solidity ^0.8.0;

contract DynamicArrayGame {
    uint256[] public numbers;

    function addNumber(uint256 number) public {
        numbers.push(number);
    }

    function sumNumbers() public view returns (uint256) {
        uint256 sum = 0;
        for (uint256 i = 0; i < numbers.length; i++) {
            sum += numbers[i];
        }
        return sum;
    }
}

Last updated