1

just wanting to be sure of this. If I have a contract that inherits from another contract and overrides a function of that contract with NonReentrant modifier on it. Will that NonReentrant modifier get deleted? I tried making both functions NonReentrant and the first function makes it revert so i'm assuming the modifier doesn't get deleted, but just want to be sure of this.

 contract A { 
   function something() virtual nonReentrant {}
 } 
    
 contract B is A {
   function something() overrides {
      super.something(); -> I'm assuming this will still be nonReentrant, right?
   }
 }

1 Answer 1

1

Yes, it will still behave nonReentrant as long as you call the super.something(); function, preferably first or before any money-withdrawing operations.

As you can see, when you override a function, you are able to drop some modifiers or change the visibility (based on some rules).

So, if you override the 'something' function but don't put the nonReentrant modifier on it and also don't call super.something();, then your overriden function will allow reentrancy.

When you inherit from another contract, your derived contract basically merges with the parent contract to form one single contract. So, if the parent contract has the 'nonReentrant` modifier declared in it, you can use it too:

 contract A { 

    bool internal locked;

    modifier nonReentrant {
        require(!locked, "Non reentrant!");
        locked = true;
        _;
        locked = false;
    }

   function something() public virtual nonReentrant {}
 }
    
 contract B is A {
    function something() public override nonReentrant {
      // No need to call super.something() anymore to guard against reentrancy since we are using nonReentrant modifier in this function now.
      // Unless you need the super.something() to do something else.
      //super.something();
    }
 }
0

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.