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

Add enumerate() back into EnumerableSet #2296

Closed
wants to merge 1 commit into from

Conversation

thegostep
Copy link

@thegostep thegostep commented Jun 28, 2020

Fixes #2166

@nventuro
Copy link
Contributor

Thanks @thegostep! This would indeed make such an external function easier to implement. However, I worry about unbounded array access: even if these are view functions, eth_call is still gas-limited.

What do you think about doing pagination by providing a query size? It has the disadvantage that you need to query the set size beforehand, but I think this is one of the better ways to make this scale.

Using the high level getters the code might look something like:

function enumerate(Set set, uint256 startIndex, uint256 pageSize) internal view returns (uint256[] memory) {
    uint256[] memory result;
    require(startIndex + pageSize <= set.length(), "Read index out of bounds");

    for (uint256 i = 0; i < pageSize; ++i) {
        result[i] = set.at(i + startIndex);
    }

    return result;
}

@thegostep
Copy link
Author

@thegostep
Copy link
Author

Removing functionality because there is a chance of running out of gas is not a good approach IMO.

Realistically, most use cases will not reach that edge case and the ones that do have all they need to mitigate it.

@frangio
Copy link
Contributor

frangio commented Jun 30, 2020

the ones that do have all they need to mitigate it.

How is this so? A smart contract that uses a function that returns an array has a vulnerability that potentially can't be mitigated. We don't want to provide a primitive that could put users in that position.

While you're free to include all 3 variants in your own contracts, because you know you won't misuse them, we think we have to be more careful and avoid providing interfaces that are easy to misuse.

@thegostep
Copy link
Author

ERC20 is easy to misuse 😂

@stale
Copy link

stale bot commented Jul 16, 2020

Hi all!
This Pull Request has not had any recent activity, is it still relevant? If so, what is blocking it? Is there anything we can do to help move it forward?
Thanks!

@stale stale bot added the stale label Jul 16, 2020
@frangio
Copy link
Contributor

frangio commented Jul 21, 2020

@nventuro Should we close this issue in favor of a pagination or indexing approach?

It has the disadvantage that you need to query the set size beforehand, but I think this is one of the better ways to make this scale.

I don't think this is true by the way. It should be possible to query for pages until you get one that is smaller than the size you requested, then you know you've reached the end.

@stale stale bot removed the stale label Jul 21, 2020
@nventuro
Copy link
Contributor

Should we close this issue in favor of a pagination or indexing approach?

What do you mean by 'pagination or indexing'? Whether the index is the actual item index or the page number? Page number seems more sensible, and yes I'd go for that.

I don't think this is true by the way. It should be possible to query for pages until you get one that is smaller than the size you requested, then you know you've reached the end.

Good point.

@frangio
Copy link
Contributor

frangio commented Jul 23, 2020

Yes, I mean what you said.

@frangio frangio closed this Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Restore EnumerableSet.enumerate
3 participants