Skip to content

Use smaller uint types for some variables #20

@s-tikhomirov

Description

@s-tikhomirov

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions