0

Are items like the OpenZeppelin Pausable contracts any different than just having additional checks inline with standard Solidity? If a coder just placed checks in front of every function call with similar a similar boolean check, would this have any less security effect? The owner of the contract (or multi-sig option) would be the only one who can change the boolean.

If I am missing something please explain. I agree that a secure OS that builds all this on top of simple easy to read contracts is a good idea, I just want to be sure that the OpenZeppelin OS is not somehow doing something more than this.

0

Your assertion is accurate. There is no functional difference, except that modifiers by design have a smaller range of potential uses.

Functionally, they behave the same way with the constraint that modifiers can only use arguments sent to the function and can only alter contract storage. Inline function calls however, can also be passed memory variables inside the function and can more directly impact the functions code logic.

A modifier can also only execute its logic all at once either before or after the functions body is executed -- where as an inline function call can happen at any point during the functions execution.

Modifiers exist for readability and organization. If a lot of functions have the same requirements to be executed (an isOwner modifier for example), or re use the same patterns, have the same preparation or cleanup process, etc -- it provides a clean way to implement these without cluttering the function body so it can contain only what is unique to that function.

This also makes it easy to determine which patterns a function is implementing just looking at its declaration/signature:

function updateBalance(uint newBal) onlyOwner onlyIfUnpaused {

Just looking at the function declaration clearly informs you of the traits inherited by the modifier patterns: that only the owner can call it and only if the contract is currently unpaused.

  • That makes sense for readability and when using modifiers, but at the most basic level (while still clunky and not so readable) it would still work. I am trying to think of security enhancements which could be simple compiler options as a stop-gap until things like Zeppelin OS is well adopted. It seems that contracts could also have one-time use safety switches for high value contracts. for example, providing a one-time use pause the contract and one time use resume the contract could save millions of dollars by providing something like a private key in a crypto function (albeit clunky). – Kevin Larson Mar 18 '18 at 23:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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