MENU

Gatekeeper 1

Function modifier is a good gatekeeper that can protect your function from unexpected behavior.
But you should know a few things about function modifiers.

Function modifiers can be inefficient.
When you add a function modifier, the code of that function is picked up and put in the function modifier in place of the _ symbol. This can also be understood as ‘The function modifiers are inlined”. In normal programming languages, inlining small code is more efficient without any real drawback but Solidity is no ordinary language. In Solidity, the maximum size of a contract is restricted to 24 KB by EIP 170. If the same code is inlined multiple times, it adds up in size and that size limit can be hit easily. Internal functions, on the other hand, are not inlined but called as separate functions. This means they are very slightly more expensive in run time but save a lot of redundant bytecode in deployment. Internal functions can also help avoid the dreaded “Stack too deep Error” as variables created in an internal function don’t share the same restricted stack with the original function, but the variables created in modifiers share the same stack limit. I managed to reduce the size of one of my contracts from 23.95 KB to 11.9 KB with this trick.

Play a Solidity game, that will help you understand function modifiers.

https://github.com/maAPPsDEV/gatekeeper-attack-one

Sorry, the comment form is closed at this time.