Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gas optimization in modifiers #128

Closed
Pfed-prog opened this issue Feb 18, 2023 · 2 comments
Closed

gas optimization in modifiers #128

Pfed-prog opened this issue Feb 18, 2023 · 2 comments

Comments

@Pfed-prog
Copy link

Modifiers code is copied in all instances where it's used, increasing bytecode size. By doing a refractor to the internal function, one can reduce bytecode size significantly at the cost of one JUMP. Consider doing this only if you are constrained by bytecode size.
https://0xmacro.com/blog/solidity-gas-optimizations-cheat-sheet/

@Pfed-prog
Copy link
Author

    modifier onlyArbitrator() {
        _checkOwner();
        _;
    }

    function _checkOwner() internal view virtual {
        require(msg.sender == address(arbitrator), "Can only be called by the arbitrator.");
    }

reduces gas to 768341 in TalentLayerArbitrator

@0xRomain
Copy link
Contributor

0xRomain commented Feb 19, 2023

Good point, in this case, it doesn't change much and reduce code readability, but we can check this point in other cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants