OZ Upgrades v5 private get storage methods

I'm creating an upgradeable contract that inherit from the ERC4626Upgradeable using @openzeppelin/contracts-upgradeable v5.0.2.
I see that since v5 the Namespaced Storage Layout is used to avoid potential storage collisions and so OZ contract includes

    bytes32 private constant ERC4626StorageLocation = 0x0773e532dfede91f04b12a73d3d2acd361424f41f76b4fb79f090161e36b4e00;

    function _getERC4626Storage() private pure returns (ERC4626Storage storage $) {
        assembly {
            $.slot := ERC4626StorageLocation

My contract inherits from the base ERC4626Upgradeable and need to access variables from the base storage

    struct ERC4626Storage {
        IERC20 _asset;
        uint8 _underlyingDecimals;

(eg _asset). What's the correct pattern for doing this? Should I redeclare the needed variable in the child contract like the following

contract ERC4626Child is ERC4626Upgradeable {
  address asset;

  function initialize(address _asset) public initializer {
    asset = _asset;


Why both the constant and the _getERC4626Storage are private instead of internal?

Thanks in advance

1 Like

These are meant to be private variables (e.g. see the non-upgradeable version of ERC4626.sol)

Could you just use the asset() getter?

You are right, sorry went a bit too fast on this one and missed the asset() method :sweat_smile: