Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict eth offer items #464

Merged
merged 19 commits into from
Jun 9, 2022
Merged

Restrict eth offer items #464

merged 19 commits into from
Jun 9, 2022

Conversation

d1ll0n
Copy link
Contributor

@d1ll0n d1ll0n commented Jun 8, 2022

Disallow ETH offer items except in matchOrders and matchAdvancedOrders.

@d1ll0n d1ll0n changed the title Restrict eth offer items [WIP Restrict eth offer items Jun 8, 2022
@d1ll0n
Copy link
Contributor Author

d1ll0n commented Jun 8, 2022

Working on getting coverage back to 100%

@0age
Copy link
Contributor

0age commented Jun 8, 2022

MagicModulus = 69 ftw 🔥

@d1ll0n d1ll0n changed the title [WIP Restrict eth offer items Restrict eth offer items Jun 8, 2022
@0age 0age merged commit fd798b8 into main Jun 9, 2022
@0age 0age deleted the restrict-eth-offer-items branch June 9, 2022 01:13
@@ -260,6 +264,10 @@ contract ReferenceOrderCombiner is
// Retrieve the offer item.
OfferItem memory offerItem = offer[j];

anyNativeOfferItems =
anyNativeOfferItems ||

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed since it hasn't been assigned before anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it can be removed. It's in a loop, you'd overwrite the result every iteration - only the last iteration would be deciding. You want to check if any of the offer items is native.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yea my bad, didn't notice the loop in the GH diff

@@ -348,6 +356,10 @@ contract ReferenceOrderCombiner is
}
}

if (anyNativeOfferItems && nonMatchFn) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would recommend moving the assignment of nonMatchFn here.

gt(
// Take the remainder of the selector modulo a magic value.
mod(
shr(NumBitsAfterSelector, calldataload(0)),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this always true? Wouldn't it be safer to just shift by 28 bytes and mask?

// of the two match selectors modulo the magic value.
NonMatchSelector_MagicRemainder
)
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The external functions that reach this point are:

fb4c2af9: fulfillAvailableAdvancedOrders(((address,address,(uint8,address,uint256,uint256,uint256)[],(uint8,address,uint256,uint256,uint256,address)
[],uint8,uint256,uint256,bytes32,uint256,bytes32,uint256),uint120,uint120,bytes,bytes)[],(uint256,uint8,uint256,uint256,bytes32[])[],(uint256,uint256)[][],(uint256,uint256)[][],bytes32,uint256)

ed98a574: fulfillAvailableOrders(((address,address,(uint8,address,uint256,uint256,uint256)[],(uint8,address,uint256,uint256,uint256,address)[],uint8,uint256,uint256,bytes32,uint256,bytes32,uint256),bytes)[],(uint256,uint256)[][],(uint256,uint256)[][],bytes32,uint256)

55944a42: matchAdvancedOrders(((address,address,(uint8,address,uint256,uint256,uint256)[],(uint8,address,uint256,uint256,uint256,address)[],uint8,uint256,uint256,bytes32,uint256,bytes32,uint256),uint120,uint120,bytes,bytes)[],(uint256,uint8,uint256,uint256,bytes32[])[],((uint256,uint256)[],(uint256,uint256)[])[])

a8174404: matchOrders(((address,address,(uint8,address,uint256,uint256,uint256)[],(uint8,address,uint256,uint256,uint256,address)[],uint8,uint256,uint256,bytes32,uint256,bytes32,uint256),bytes)[],((uint256,uint256)[],(uint256,uint256)[])[])

The sigs mod 69 are:
39, 52, 28, 29 (0x1d)

so this works

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(just a mental note: 0b10 if fulfill*, 0b00 otherwise so far after execution)

@@ -359,6 +390,13 @@ contract OrderCombiner is OrderFulfiller, FulfillmentApplier {
}
}

// If the second bit is set in the error buffer, we are not in a match function.
// If the first bit is set, a native offer item was encountered.
// If the value is greater than two, both the first and second bits were set.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is a bit misleading since it's true here because > 3 is not possible but the statement isn't true in general.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, this has been fixed in main. comment now states:

        // If the first bit is set, a native offer item was encountered. If the
        // second bit is set in the error buffer, the current function is not
        // matchOrders or matchAdvancedOrders. If the value is three, both the
        // first and second bits were set; in that case, revert with an error.

@@ -194,6 +194,10 @@ contract ReferenceOrderCombiner is
// Track the order hash for each order being fulfilled.
bytes32[] memory orderHashes = new bytes32[](totalOrders);

// Check if we are in a match function
bool nonMatchFn = msg.sig != 0x55944a42 && msg.sig != 0xa8174404;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use SeaportInterface.matchOrders/matchAdvancedOrders.selector?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea this would be much better

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already fixed :)
#524

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants