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

Redundant SLOADs in Initializable #4579

Open
0xVolosnikov opened this issue Sep 6, 2023 · 0 comments
Open

Redundant SLOADs in Initializable #4579

0xVolosnikov opened this issue Sep 6, 2023 · 0 comments

Comments

@0xVolosnikov
Copy link
Contributor

Opening issue as mentioned in #4576 (comment)

📝 Details

Since InitializableStorage is a struct with two fields packed in one storage slot, compiler need to load this slot when writing new value only for one of the fields, like here:

if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}

Since (when) we know values for other fields, explicit usage of known values can let the compiler to prevent excessive SLOADs before SSTORE. Example:

$._initialized = 1;
$._initializing = false;

PS: this is applicable not only in this place, but also in some other contracts.

@0xVolosnikov 0xVolosnikov changed the title Reduntant SLOADs in Initializable Redundant SLOADs in Initializable Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants