Skip to content

Conversation

@Amxx
Copy link
Collaborator

@Amxx Amxx commented Jun 7, 2021

Native bitmap are really storage inneficient:

mapping(X => bool) will use a new storage slot for each entry
bool[] will use an underlying bytes1[] array, which only truly uses 32 bits per 256 bits storage slot.

This PR include a dense bitmap, that will save on gas when entries are consecutive. This design is used by Uniswap merkle-distributor to reduce the gas cost of writing to new (clean) storage slot by a factor 8 over what bool[] would have required.

PR Checklist

  • Tests
  • Documentation
  • Changelog entry

Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code and tests look good to me.

frangio
frangio previously approved these changes Jun 10, 2021
Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, though I wonder if we also want a set(BitMap, uint256, bool) function. Could be useful in some cases.

Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
@frangio frangio merged commit f7da53c into OpenZeppelin:master Jun 11, 2021
@Amxx Amxx deleted the feature/structs/bitmap branch June 12, 2021 19:49
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.

2 participants