-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Conversation
Thanks @thegostep! This would indeed make such an external function easier to implement. However, I worry about unbounded array access: even if these are 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;
} |
Why not all 3? It's usually what I do in my projects: |
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. |
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. |
ERC20 is easy to misuse 😂 |
Hi all! |
@nventuro Should we close this issue in favor of a pagination or indexing approach?
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. |
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.
Good point. |
Yes, I mean what you said. |
Fixes #2166