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

optimize Quorum #55

Closed
ZzzzHui opened this issue Aug 21, 2023 · 1 comment · Fixed by #56 or #57
Closed

optimize Quorum #55

ZzzzHui opened this issue Aug 21, 2023 · 1 comment · Fixed by #56 or #57
Assignees
Labels
A-contracts Area: contracts T-feature Type: feature
Milestone

Comments

@ZzzzHui
Copy link
Contributor

ZzzzHui commented Aug 21, 2023

📚 Context

This issue is to optimize the PR to add quorum, which addresses this issue.

  • We can optimize the Quorum by getting rid of AccessControlEnumerable and EnumerableSet.
  • Furthermore, instead of using mapping(address => bool) voted; to note who has voted, we could consider splitting a uint256 into bits and utilize bit position to denote whether a validator has voted.

For details, please see this comment

✔️ Solution

Since the last part (split a uint256) of the optimization can be complex and we are not sure whether we will go for that route, we will open 2 PR for this issue.

@ZzzzHui ZzzzHui self-assigned this Aug 21, 2023
@ZzzzHui ZzzzHui linked a pull request Aug 21, 2023 that will close this issue
@ZzzzHui
Copy link
Contributor Author

ZzzzHui commented Aug 23, 2023

Splitting a uint256 into | who_has_voted(248 bit) | count(8 bit) | is the most optimal. But it can be error prone as well. So I wanna take the middle ground by using a 256 bit map to indicate whether a validator has voted, and a uint256 var to count the number of votes.

The openzeppelin library called BitMaps is most suitable for this case. Compared with the current solution (mapping(address => bool) voted), which uses 1 storage slot for each validator, BitMaps use only storage slot for every 256 validators (or 255 as we don't use the bit on index 0 for the first slot).

Compared with the current solution, BitMaps saves on gas because write a non-zero storage slot (2,900 gas) is much cheaper than writing a zero storage slot (20,000 gas), excluding the access operation gas.

BitMaps solution is on branch feature/optimize-quorum-bitmap
PR opened here

P.S. OpenZeppelin BitMaps is basically the same as our library BitMask

@ZzzzHui ZzzzHui linked a pull request Aug 23, 2023 that will close this issue
@ZzzzHui ZzzzHui transferred this issue from cartesi/rollups Aug 30, 2023
@ZzzzHui ZzzzHui moved this to 👀 In review in Rollups Unit Aug 30, 2023
@ZzzzHui ZzzzHui added T-feature Type: feature no changelog A-contracts Area: contracts labels Aug 30, 2023
This was linked to pull requests Aug 30, 2023
@guidanoli guidanoli added this to the 1.1.0 milestone Sep 4, 2023
@guidanoli guidanoli modified the milestones: 1.1.0, 1.2.0 Oct 3, 2023
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Ready in Rollups Unit Oct 26, 2023
@guidanoli guidanoli modified the milestones: 1.2.0, 2.0.0 Nov 9, 2023
@pedroargento pedroargento modified the milestones: 2.0.0, 2.1.0 Dec 19, 2023
@ZzzzHui ZzzzHui removed this from the 2.1.0 milestone Jan 11, 2024
@ZzzzHui ZzzzHui added this to the 2.0.0 milestone Jan 11, 2024
@guidanoli guidanoli moved this from ✅ Ready to 🚀 Done in Rollups Unit Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-contracts Area: contracts T-feature Type: feature
Projects
Status: 🚀 Done
3 participants