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

1 stars 0 forks source link

Gas Optimizations #124

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

_verifyTime optimization

Proof of Concept

https://github.com/code-423n4/2022-05-opensea-seaport/blob/main/contracts/lib/Verifiers.sol#L37-L55

Original _verifyTime:

    function _verifyTime(
        uint256 startTime,
        uint256 endTime,
        bool revertOnInvalid
    ) internal view returns (bool valid) {
        // Revert if order's timespan hasn't started yet or has already ended.
        if (startTime > block.timestamp || endTime <= block.timestamp) {
            // Only revert if revertOnInvalid has been supplied as true.
            if (revertOnInvalid) {
                revert InvalidTime();
            }

            // Return false as the order is invalid.
            return false;
        }

        // Return true as the order time is valid.
        valid = true;
    }

Recommended Mitigation Steps

Change to:

    function _verifyTime(
        uint256 startTime,
        uint256 endTime,
        bool revertOnInvalid
    ) internal view returns (bool valid) {
        if (startTime <= block.timestamp && endTime > block.timestamp) {
            valid = true;
        }
        else if (revertOnInvalid) {
            revert InvalidTime();
        }
    }
HardlyDifficult commented 2 years ago

I tested this and got mixed results. fullfillOrder saved as much as 12 gas but other functions such as fulfillAvailableOrders went up as much as 36.

Since this is not a clear win, closing as invalid.