code-423n4 / 2023-09-delegate-findings

2 stars 1 forks source link

Gas Optimizations #380

Open c4-submissions opened 1 year ago

c4-submissions commented 1 year ago

See the markdown file with the details of this report here.

GalloDaSballo commented 1 year ago

Great refactoring imo

c4-judge commented 1 year ago

GalloDaSballo marked the issue as grade-a

0xfoobar commented 1 year ago

This isn't possible to change, this is the interface that Seaport expects

c4-sponsor commented 1 year ago

0xfoobar (sponsor) disputed

GalloDaSballo commented 1 year ago

This seems to compile

Rewriting the tests looks very laborious

CreateOfferer.sol

    function generateOrder(address fulfiller, SpentItem[] calldata minimumReceived, SpentItem[] calldata maximumSpent, bytes calldata context)
        external
        checkStage(Enums.Stage.generate, Enums.Stage.transfer)
        onlySeaport(msg.sender)
        returns (SpentItem[] memory offer, ReceivedItem[] memory consideration)
    {
        if (context.length != 160) revert Errors.InvalidContextLength();
        Structs.Context memory decodedContext = abi.decode(context, (Structs.Context));
        /// @audit Add some validation here
        (offer, consideration) = Helpers.processSpentItems(minimumReceived[0], maximumSpent[0]);
        Helpers.updateTransientState(transientState, fulfiller, minimumReceived[0], maximumSpent[0], decodedContext);
    }

CreateOffererLib.sol

function processSpentItems(SpentItem calldata minimumReceived, SpentItem calldata maximumSpent)
        internal
        view
        returns (SpentItem[] memory offer, ReceivedItem[] memory consideration)
    {
        if (minimumReceived.itemType != ItemType.ERC721 || minimumReceived.token != address(this) || minimumReceived.amount != 1) {
            revert CreateOffererErrors.MinimumReceivedInvalid(minimumReceived);
        }
        if (maximumSpent.itemType != ItemType.ERC721 && maximumSpent.itemType != ItemType.ERC20 && maximumSpent.itemType != ItemType.ERC1155) {
            revert CreateOffererErrors.MaximumSpentInvalid(maximumSpent);
        }
        offer = new SpentItem[](1);
        offer[0] = SpentItem({itemType: minimumReceived.itemType, token: minimumReceived.token, identifier: minimumReceived.identifier, amount: minimumReceived.amount});
        consideration = new ReceivedItem[](1);
        consideration[0] = ReceivedItem({
            itemType: maximumSpent.itemType,
            token: maximumSpent.token,
            identifier: maximumSpent.identifier,
            amount: maximumSpent.amount,
            recipient: payable(address(this))
        });
    }