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

Update MultipleWinnersBuilder.sol: Packed Structs #347

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

0xScratch
Copy link

Well, this PR made a slight change within the elements of that struct which avoids usage of 1 extra slot. Usually, EVM allocates 2**256 slots to each contract and each slot comprises of 32 bytes. And the usage of slots costs us gas, which makes it better if any contract is achieving the same thing in less slots.
Let's suppose there are two structs:

Struct A {
    address abc; // 1st slot - covers up 20 bytes
    uint256 num; // 2nd slot - covers up 32 bytes
    bool isTrue; // 3rd slot - covers up 1 byte
}

Now, Struct A uses up 3 slots and is 3rd slot seems kind of expensive cuz only 1 byte is allotted to that entire 32 bytes slot..Let's optimize this

Struct B {
    address abc; // 1st slot - covers up 20 bytes
    bool isTrue; // 1st slot - covers up (20 + 1) byte
    uint256 num; // 2nd slot - covers up 32 bytes
}

Well, this makes sense and we neglected the usage of 1 slot by optimizing Struct A to Struct B. The same thing is done with the help of this PR. Note that RNGInterface rngService is a kind of address as far I am concerned.

For a better explanation, refer this

Thanks @PierrickGT

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.

1 participant