...by Daniel Szego
quote
"Simplicity is the ultimate sophistication."
Leonardo da Vinci

Friday, July 6, 2018

Solidity Tips and Tricks - modifier inheritance


In solidity modifiers are inherited and they always overwrite the modifier of the ancestor. There is no way to call the ancestor class modifier if it has been overwritten, however, you can reference both the ancestor and descendant elements as well in your modifier. As an example:

contract Ancestor {
    uint public number = 11;
    
    modifier IsBig  {
            require (number > 10);
            _;
    }
}

contract Descendant is Ancestor {
    uint public number = 22;

    modifier IsBig  {
            require (Ancestor.number < 20);
            _;
    }
    function testFv() IsBig {
        
    }
}

In testFv() there is no possible to reference on super.IsBig or Acesntor.IsBig, the only thing that you can call is the overwritten IsBig modifier.