From 67e286b0477fea3dc9e85869efb02aeb5d998589 Mon Sep 17 00:00:00 2001 From: Carter Carlson Date: Fri, 28 Feb 2025 12:10:06 -0800 Subject: [PATCH] Gas golf DeleGatorCore.sol Reduce bytecode size of modifiers. Each function a modifier decorates appends bytecode. By changing the code inside a modifier from conditional statements to a function pointer, there is less bytecode appended across the contract. --- src/DeleGatorCore.sol | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/DeleGatorCore.sol b/src/DeleGatorCore.sol index 888a9461..2c99ace8 100644 --- a/src/DeleGatorCore.sol +++ b/src/DeleGatorCore.sol @@ -95,28 +95,40 @@ abstract contract DeleGatorCore is * @dev Check that the caller is the entry point */ modifier onlyEntryPoint() { - if (msg.sender != address(entryPoint)) revert NotEntryPoint(); + _onlyEntryPoint(); _; } + function _onlyEntryPoint() private view { + if (msg.sender != address(entryPoint)) revert NotEntryPoint(); + } + /** * @notice Require the function call to come from the EntryPoint or this contract. * @dev Check that the caller is either the delegator contract itself or the entry point */ modifier onlyEntryPointOrSelf() { - if (msg.sender != address(entryPoint) && msg.sender != address(this)) revert NotEntryPointOrSelf(); + _onlyEntryPointOrSelf(); _; } + function _onlyEntryPointOrSelf() private view { + if (msg.sender != address(entryPoint) && msg.sender != address(this)) revert NotEntryPointOrSelf(); + } + /** * @notice Require the function call to come from the DelegationManager. * @dev Check that the caller is the stored delegation manager. */ modifier onlyDelegationManager() { - if (msg.sender != address(delegationManager)) revert NotDelegationManager(); + _onlyDelegationManager(); _; } + function _onlyDelegationManager() private view { + if (msg.sender != address(delegationManager)) revert NotDelegationManager(); + } + ////////////////////////////// Constructor ////////////////////////////// /**