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

audit: Better Storage and Struct Packing Possible #177

Closed
Orland0x opened this issue Jun 13, 2023 · 0 comments · Fixed by #204
Closed

audit: Better Storage and Struct Packing Possible #177

Orland0x opened this issue Jun 13, 2023 · 0 comments · Fixed by #204
Assignees

Comments

@Orland0x
Copy link
Contributor

The order of declaration of variables in storage and the order of fields in structs are relevant to their ultimate size. Storage variables that have combined sizes less than one word can be packed into a single storage slot, which can reduce the number of storage slots used, especially if they are often read or written together anyway. The same goes for struct fields, where sequential fields can be packed into one slot if they are small enough.
This can be applied in the following places:

  1. The vp field of the Member struct could be reduced to a uint96 so the entire struct would occupy one word. 96 bits of precision is likely sufficient to measure the voting power of a user.
  2. The Proposal struct's fields can be reordered to reduce its size to 4 words instead of 5.
  3. The order of storage variables in the Space contract can be reordered to occupy fewer slots.
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 a pull request may close this issue.

2 participants