Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unbounded loop #14

Closed
pauliax opened this issue Nov 18, 2017 · 2 comments
Closed

unbounded loop #14

pauliax opened this issue Nov 18, 2017 · 2 comments
Labels

Comments

@pauliax
Copy link

pauliax commented Nov 18, 2017

function totalSupply() public view returns (uint) {
    return kitties.length - 1;
}

for (uint256 i = 1; i <= totalSupply(); i++) {...}

This loop in the contract can eventually grow so large as to make future operations of the contract cost too much gas to fit in a block. Then, iterating through this large array might consume all the gas provided (run out of gas) and it will never complete.

@adamkolar
Copy link

Quoting from the comment of the tokensOfOwnerByIndex function that contains mentioned loop:

    /// @dev This method MUST NEVER be called by smart contract code. It will almost
    ///  certainly blow past the block gas limit once there are a large number of
    ///  Kitties in existence. Exists only to allow off-chain queries of ownership.
    ///  Optional method for ERC-721.

@dete
Copy link

dete commented Nov 18, 2017

Thanks @pauliax. As @adamkolar noted, this function wasn't intended to be called on-chain, but we're also replacing this function as per #4.

@dete dete added the wontfix label Nov 19, 2017
@dete dete closed this as completed Nov 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants