Open code423n4 opened 2 years ago
Adding unchecked directive can save gas
This seems valid and could provide a small savings, but updating channels is not common and does not impact end-users so this is not a critical path.
Setting uint256 variables to 0 is redundant
There are a lot of instances of this, but in my testing the optimizer seems to mostly take care of this automatically. I saw very little impact from changes like this.
Using constant value instead this.[functionName].selector is more gas efficient
It's unfortunate that the optimizer does not handle this automatically, but given there is small savings here it may be worth including despite the impact to readability. Using immutable may be nice so that the values used are programmatically assigned.
Adding unchecked directive can save gas
For the arithmetic operations that will never over/underflow, using the unchecked directive (Solidity v0.8 has default overflow/underflow checks) can save some gas from the unnecessary internal over/underflow checks.
For example:
https://github.com/code-423n4/2022-05-opensea-seaport/blob/4140473b1f85d0df602548ad260b1739ddd734a5/contracts/conduit/ConduitController.sol#L137-L152
channelPreviouslyOpen
istrue
means thatchannelIndexPlusOne != 0
, andchannelIndexPlusOne
isuint256
, thenchannelIndexPlusOne - 1
will never underflow.Setting
uint256
variables to0
is redundanthttps://github.com/code-423n4/2022-05-opensea-seaport/blob/4140473b1f85d0df602548ad260b1739ddd734a5/contracts/lib/AmountDeriver.sol#L44
Setting
uint256
variables to0
is redundant as they default to0
.Other examples include:
https://github.com/code-423n4/2022-05-opensea-seaport/blob/4140473b1f85d0df602548ad260b1739ddd734a5/contracts/lib/OrderCombiner.sol#L470
Using constant value instead
this.[functionName].selector
is more gas efficienthttps://github.com/code-423n4/2022-05-opensea-seaport/blob/4140473b1f85d0df602548ad260b1739ddd734a5/contracts/conduit/Conduit.sol#L79-L80
Recommendation
Change to:
Based on our tests, this change can save
21
gas.Other examples include:
https://github.com/code-423n4/2022-05-opensea-seaport/blob/4140473b1f85d0df602548ad260b1739ddd734a5/contracts/conduit/Conduit.sol#L112-L113