Why declare `__gap` variable in ReentrancyGuardUpgradeable.sol?


I would like to know why declaring the __gap variable in ReentrancyGuardUpgradeable.sol.

abstract contract ReentrancyGuardUpgradeable is Initializable {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    function __ReentrancyGuard_init() internal initializer {

    function __ReentrancyGuard_init_unchained() internal initializer {
        _status = _NOT_ENTERED;

     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and make it call a
     * `private` function that does the actual work.
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;


        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    uint256[49] private __gap;

It is assumed that I only use this contract to prevent a reentrancy attack and I do not use the __gap variable. so It obviously spent more on storage and gas fee. so I would like to know the effect of this variable. is it if worthly to be used.

That array that has been assigned at the bottom of your script above.
It does not exist within open zeppelins template.

See here >

The array you pointed out must be related to another part of the contract.
Where else can you find __gap ?

Oh, I got it. This is the PartyDao contract code. because they used a proxy structure, maybe it is used to prevent storage slot clash. their repo is here:https://github.com/PartyDAO/partybid/tree/main/contracts

1 Like