code-423n4 / 2022-05-opensea-seaport-findings

1 stars 0 forks source link

Gas Optimizations #209

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Utilise uncheck block for gas savings

End should be greater than start time so use unchecked block to save gas

https://github.com/code-423n4/2022-05-opensea-seaport/blob/4140473b1f85d0df602548ad260b1739ddd734a5/contracts/lib/OrderFulfiller.sol#L163

https://github.com/code-423n4/2022-05-opensea-seaport/blob/4140473b1f85d0df602548ad260b1739ddd734a5/contracts/lib/OrderCombiner.sol#L235

https://github.com/code-423n4/2022-05-opensea-seaport/blob/9d7ce4d08bf3c3010304a0476a785c70c0e90ae7/reference/lib/ReferenceOrderCombiner.sol#L241

If statement ensures no underflow :

https://github.com/code-423n4/2022-05-opensea-seaport/blob/9d7ce4d08bf3c3010304a0476a785c70c0e90ae7/contracts/lib/FulfillmentApplier.sol#L100

https://github.com/code-423n4/2022-05-opensea-seaport/blob/9d7ce4d08bf3c3010304a0476a785c70c0e90ae7/contracts/lib/FulfillmentApplier.sol#L112

https://github.com/code-423n4/2022-05-opensea-seaport/blob/9d7ce4d08bf3c3010304a0476a785c70c0e90ae7/reference/lib/ReferenceBasicOrderFulfiller.sol#L867

https://github.com/code-423n4/2022-05-opensea-seaport/blob/9d7ce4d08bf3c3010304a0476a785c70c0e90ae7/reference/lib/ReferenceFulfillmentApplier.sol#L109

https://github.com/code-423n4/2022-05-opensea-seaport/blob/9d7ce4d08bf3c3010304a0476a785c70c0e90ae7/reference/lib/ReferenceFulfillmentApplier.sol#L120

Cache advancedOrder.parameters.endTime in a local variable

https://github.com/code-423n4/2022-05-opensea-seaport/blob/4140473b1f85d0df602548ad260b1739ddd734a5/contracts/lib/OrderCombiner.sol#L235

https://github.com/code-423n4/2022-05-opensea-seaport/blob/9d7ce4d08bf3c3010304a0476a785c70c0e90ae7/reference/lib/ReferenceOrderCombiner.sol#L241

Variables are their default types

No need to assign them :

https://github.com/code-423n4/2022-05-opensea-seaport/blob/4140473b1f85d0df602548ad260b1739ddd734a5/contracts/lib/OrderCombiner.sol#L470

https://github.com/code-423n4/2022-05-opensea-seaport/blob/4140473b1f85d0df602548ad260b1739ddd734a5/contracts/lib/OrderCombiner.sol#L751

https://github.com/code-423n4/2022-05-opensea-seaport/blob/9d7ce4d08bf3c3010304a0476a785c70c0e90ae7/reference/lib/ReferenceAmountDeriver.sol#L46

HardlyDifficult commented 2 years ago

Utilise uncheck block for gas savings

Since _verifyTime requires startTime <= endTime it may be worth using unchecked here for a small savings. Same for the others so long as it is confirmed that the appropriate checks have already been peformed.

Cache advancedOrder.parameters.endTime in a local variable

Since the endTime does not appear to be read a second time here, it's not clear this change would offer any benefit.

Variables are their default types

The compiler seems to mostly handle this automatically. In my testing, not setting defaults offered very little savings.