Closed code423n4 closed 1 year ago
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
if(inbox == address(0)) revert INBOX_NOT_SET();
require(inbox != address(0), "INBOX_NOT_SET");
if(msg.sender != address(bridge)) revert NOT_FROM_BRIDGE();
if(l2ToL1Sender != l2Counterpart) revert ONLY_COUNTERPART_GATEWAY();
Require statements including conditions with the && operator can be broken down in multiple require statements to save gas.
Instances Found:
require(_escrow != address(0), "INVALID_ESCROW"); require(Address.isContract(_escrow), "INVALID_ESCROW");
require(_escrow != address(0) && Address.isContract(_escrow), "INVALID_ESCROW");
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
if(inbox == address(0)) revert INBOX_NOT_SET();
instead ofrequire(inbox != address(0), "INBOX_NOT_SET");
if(msg.sender != address(bridge)) revert NOT_FROM_BRIDGE();
instead ofrequire(inbox != address(0), "INBOX_NOT_SET");
if(l2ToL1Sender != l2Counterpart) revert ONLY_COUNTERPART_GATEWAY();
instead ofrequire(inbox != address(0), "INBOX_NOT_SET");
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:
require(_escrow != address(0), "INVALID_ESCROW"); require(Address.isContract(_escrow), "INVALID_ESCROW");
instead ofrequire(_escrow != address(0) && Address.isContract(_escrow), "INVALID_ESCROW");