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

Use smaller uint types for some variables #20

Open
s-tikhomirov opened this issue Oct 3, 2024 · 0 comments
Open

Use smaller uint types for some variables #20

s-tikhomirov opened this issue Oct 3, 2024 · 0 comments

Comments

@s-tikhomirov
Copy link
Contributor

Some variables in the contract use uints with widths that may be larger than necessary. For example, with the tree depth set at 20, the number of elements in the membership set cannot exceed 2^20. This means that MAX_MEMBERSHIP_SET_SIZE could be stored in a uint24 instead of a uint32. (Solidity supports "uint8 to uint256 in steps of 8 (unsigned of 8 up to 256 bits)" - source).

However, it’s important to consider how the EVM packs storage variables into 256-bit words, which it operates on natively. Over-optimizing individual variable sizes could lead to inefficient storage usage due to misalignment with 256-bit boundaries.

Additionally, upgradability should be taken into account. For example, if the tree depth might increase to 32 in the future, it would make sense to use uint32 for the membership set size from the beginning to avoid the need for changes later.

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

No branches or pull requests

1 participant