The revert strings below can be shortened to 32 characters or fewer (as shown) to save gas (or else consider using custom error codes, which could save even more gas)
require(
_pendingImplementation != address(0) && msg.sender == _pendingImplementation,
"Caller must be the pending implementation"
);
Recommendation:
require(_pendingImplementation != address(0), "Caller must be the pending impl");
require(msg.sender == _pendingImplementation, "Caller must be the pending impl");
Change maxSubmissionCost > 0 to maxSubmissionCost != 0
Inline a function/modifier that’s only used once
It costs less gas to inline the code of functions that are only called once. Doing so saves the cost of allocating the function selector, and the cost of the jump when the function is called.
* @dev Modifier to check whether the `msg.sender` is the admin.
*/
modifier onlyAdmin() {
require(msg.sender == _admin(), "Caller must be admin");
_;
}
Require
revert string is too longThe revert strings below can be shortened to 32 characters or fewer (as shown) to save gas (or else consider using custom error codes, which could save even more gas)
GraphUpgradeable.sol: L32
Change message to
Caller must be the impl
GraphProxy.sol: L141
Change message to
Implementation must be contract
GraphProxy.sol: L142-145
Change message to
Caller must be the pending impl
Managed.sol: L53
Change message to
Caller must be Controller gov
GraphTokenGateway.sol: L21
Change message to
Only Gov or Guardian can call
The revert string below is also longer than 32 characters but it's not clear how to shorten it
GraphProxy.sol: L105
Avoid use of '&&' within a
require
functionSplitting into separate
require()
statements saves gasGoverned.sol: L54-57
Recommendation:
GraphProxy.sol: L142-145
Recommendation:
L1GraphTokenGateway.sol: L142
Recommendation:
Use
!= 0
instead of> 0
in arequire
statement if variable is an unsigned integer!= 0
should be used where possible since> 0
costs more gasL1GraphTokenGateway.sol: L217
Change
maxSubmissionCost > 0
tomaxSubmissionCost != 0
Inline a function/modifier that’s only used once
It costs less gas to inline the code of functions that are only called once. Doing so saves the cost of allocating the function selector, and the cost of the jump when the function is called.
Managed.sol: L70-74
Since
onlyController()
is used only once in this contract (infunction setController()
) as shown below, it should be inlined to save gasManaged.sol: L95-97
GraphTokenUpgradeable.sol: L59-62
Since
onlyMinter()
is used only once in this contract (infunction mint()
) as shown below, it should be inlined to save gasGraphTokenUpgradeable.sol: L132-134
L2GraphTokenGateway.sol: L68-74
Since
onlyL1Counterpart()
is used only once in this contract (infunction finalizeInboundTransfer()
) as shown below, it should be inlined to save gasL2GraphTokenGateway.sol: L226-232
L1GraphTokenGateway.sol: L73-74
Since
onlyL2Counterpart()
is used only once in this contract (infunction finalizeInboundTransfer()
) as shown below, it should be inlined to save gasL1GraphTokenGateway.sol: L263-269
GraphTokenGateway.sol: L18-22
Since
onlyGovernorOrGuardian()
is used only once in this contract (infunction setPaused()
) as shown below, it should be inlined to save gasGraphTokenGateway.sol: L47-49
The following two modifiers are never used and should be reviewed:
GraphProxyStorage.sol: L59-64
Managed.sol: L60-63