code-423n4 / 2022-10-thegraph-findings

0 stars 0 forks source link

Gas Optimizations #207

Closed code423n4 closed 1 year ago

code423n4 commented 1 year ago

1 - Calculate the hash value and hardcode in the code could save gas

The hash calculations of each variable and put them in the code could save gas in the deployment

Instances of this issue:

contracts/l2/token/GraphTokenUpgradeable.sol#L34      bytes32 private constant DOMAIN_TYPE_HASH =
contracts/l2/token/GraphTokenUpgradeable.sol#L38      bytes32 private constant DOMAIN_NAME_HASH = keccak256("Graph Token");
contracts/l2/token/GraphTokenUpgradeable.sol#L39      bytes32 private constant DOMAIN_VERSION_HASH = keccak256("0");
contracts/l2/token/GraphTokenUpgradeable.sol#L40      bytes32 private constant DOMAIN_SALT =
contracts/l2/token/GraphTokenUpgradeable.sol#L42      bytes32 private constant PERMIT_TYPEHASH =

Links:

contracts/l2/token/GraphTokenUpgradeable.sol#L34-L45

2 - Remove unnecessary emit in order to save gas

The following emission is unnecessary and does not correspond to the function acceptOwnership

contracts/governance/Governed.sol#L66                emit NewPendingOwnership(oldPendingGovernor, pendingGovernor);

Links:

contracts/governance/Governed.sol#L66

3 - Use multiple require statements instead of &&

Require statements including conditions with the && operator can be broken down in multiple require statements to save gas.

contracts/gateway/L1GraphTokenGateway.sol#L142      require(_escrow != address(0) && Address.isContract(_escrow), "INVALID_ESCROW");
contracts/upgrades/GraphProxy.sol#L143                     require(
                                              _pendingImplementation != address(0) && msg.sender == _pendingImplementation,

Links:

contracts/gateway/L1GraphTokenGateway.sol#L142 contracts/upgrades/GraphProxy.sol#L143