The function _applyFractionsAndTransferEach() contains two function pointer assignments, which are difficult to read.
They could also be set in the constructor and stored immutable, which will make the code more readable and save some gas.
The function _verifyProof() of contract CriteriaResolution uses a switch statement. This can be optimized to run withouth a jump to save some gas. As this is within a loop, it might be worth the effort.
Define function pointers in constructor
Impact
The function
_applyFractionsAndTransferEach()
contains two function pointer assignments, which are difficult to read. They could also be set in the constructor and storedimmutable
, which will make the code more readable and save some gas.Proof of Concept
Context: OrderFulfiller.sol#L199-L214, OrderFulfiller.sol#L289-L303
Tools Used
Manual review
Recommended Mitigation Steps
Consider setting the function pointers in the constructor, as shown in the following example:
Gas saving in
_verifyProof()
Impact
The function
_verifyProof()
of contractCriteriaResolution
uses aswitch
statement. This can be optimized to run withouth ajump
to save some gas. As this is within a loop, it might be worth the effort.Proof of Concept
Context: CriteriaResolution.sol#L265-L273
This is the current code:
Tools Used
Manual review
Recommended Mitigation Steps
Consider using the following:
Here is some test code to see the difference:
Gas saving by replacing the
if
condition with||
by a branchless expressionImpact
The condition can be replaced by
or(iszero(numerator), gt(numerator, denominator))
which saves onejumpi
.Proof of Concept
Context: Seaport.sol#L137
Tools Used
Manual review
Recommended Mitigation Steps
Replace the
if
statement by the equivalent code in assembly (mentioned above).