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

0 stars 0 forks source link

Gas Optimizations #296

Closed code423n4 closed 1 year ago

code423n4 commented 1 year ago

USE CUSTOM ERRORS RATHER THAN REVERT()/REQUIRE() STRINGS TO SAVE GAS

Custom Errors can be implemented as such:

INBOX_NOT_SET(); NOT_FROM_BRIDGE(); ONLY_COUNTERPART_GATEWAY(); INVALID_INBOX(); INVALID_L1_ROUTER(); INVALID_L2_GRT(); INVALID_ESCROW(); INVALID_ADDRESS(); ALREADY_WHITELISTED(); NOT_WHITELISTED(); TOKEN_NOT_GRT(): INVALID_ZERO_AMOUNT(); INVALID_DESTINATION(); CALL_HOOK_DATA_NOT_ALLOWED(); TOKEN_NOT_GRT(); BRIDGE_OUT_OF_FUNDS();

While REVERT() statements can be also used to replace REQUIRE() statements like this i.e.:

gateway/L1GraphTokenGateway.sol

MORE REQUIRE STATEMENTS INSTEAD OF ‘&&’

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

Instances Found: