1

ReentrancyGuard's _status is set in the constructor & we can't set it anywhere else: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/64e48203cecad94f02de9891ecdeed4d629c6dae/contracts/security/ReentrancyGuard.sol#L39-L41.

And in the proxy contract we can't have a constructor, only the initialize(), can the ReentrancyGuard's nonReentrant modifier be used in a proxy contract?

2 Answers 2

1

Okay, we can use the ReentrancyGuardUpgradeable contract from import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";

Then simply call the __ReentrancyGuard_init() which set's the _status.

The modifier name remains nonReentrant(). This works for me!

1

Like @DiamondDust said, you can call __ReentrancyGuard_init()

But when you check the contract ReentrancyGuardUpgradeable, you'll see that the modifier nonReentrant() checks _status first.

require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

Even without initializing _status, the check can succeed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.