yearn-vaults
yearn-vaults copied to clipboard
Update BaseFeeOracle.sol: Reduction of extra Slot
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!