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 BaseFeeOracle.sol: Reduction of extra Slot #562

Closed
wants to merge 1 commit into from

Conversation

0xScratch
Copy link

In the current file, state variables were arranged in this form:

address public baseFeeProvider; // slot 1
uint256 public maxAcceptableBaseFee; // slot 2

address public governance; // slot 3
address public pendingGovernance; // slot 4
mapping(address => bool) public authorizedAddresses; // slot 5 - slot_hash, values are stored at keccak256(key, slot)

bool public manualBaseFeeBool; // slot 6

// Total 6 slots are used up if we don't count the values in mapping

After the changes:

address public baseFeeProvider; // slot 1
uint256 public maxAcceptableBaseFee; // slot 2

address public governance; // slot 3
address public pendingGovernance; // slot 4
bool public manualBaseFeeBool; // slot 4

mapping(address => bool) public authorizedAddresses; // slot 5 - slot_hash, values are stored at keccak256(key, slot)

// Total 5 slots are used up if we don't count the values in mapping

With this one slot got reduced, cuz each slot can take upto 32 bytes whereas address covers up 20 bytes of space and bool takes up 1 byte. Thus, they both will be assigned into 1 slot i.e slot 4

For Further Explaination: link

Although, there was one more doubt related to bool public manualBaseFeeBool;, this variable will always be set to true in the constructor itself..Then why we don't just remove manualBaseFeeBool = true; from the constructor and change the initialization to bool public manualBaseFeeBool = true;. Why to add an extra line of code?

Thanks!

@0xScratch
Copy link
Author

Closing due to inactivity!

@0xScratch 0xScratch closed this Dec 9, 2024
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