Skip to content

Commit

Permalink
Merge pull request #53 from ProjectOpenSea/is-non-contract-on-stack
Browse files Browse the repository at this point in the history
use a stack variable to track non-contract orders
  • Loading branch information
0age authored Mar 4, 2024
2 parents 940d59f + b535ce8 commit a8dc71d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/core/lib/OrderCombiner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ contract OrderCombiner is OrderFulfiller, FulfillmentApplier {
and(NonMatchSelector_MagicMask, calldataload(0))
}

// Declare variables for later use.
// Declare "terminal memory offset" variable for use in efficient loops.
uint256 terminalMemoryOffset;

unchecked {
Expand All @@ -258,6 +258,9 @@ contract OrderCombiner is OrderFulfiller, FulfillmentApplier {

// Skip overflow checks as all for loops are indexed starting at zero.
unchecked {
// Declare variable to track if an order is not a contract order.
bool isNonContract;

// Iterate over each order.
for (uint256 i = OneWord; i < terminalMemoryOffset; i += OneWord) {
// Retrieve order using pointer libraries to bypass out-of-range
Expand Down Expand Up @@ -302,11 +305,9 @@ contract OrderCombiner is OrderFulfiller, FulfillmentApplier {
// types beyond the current set (0-4) and will need to be
// modified if more order types are added.
assembly {
// Declare a variable indicating if the order is not a
// contract order. Cache in scratch space to avoid stack
// depth errors.
let isNonContract := lt(orderType, 4)
mstore(0, isNonContract)
// Assign the variable indicating if the order is not a
// contract order.
isNonContract := lt(orderType, 4)

// Update the variable indicating if the order is not an
// open order, remaining set if it has been set already.
Expand All @@ -332,7 +333,7 @@ contract OrderCombiner is OrderFulfiller, FulfillmentApplier {
invalidNativeOfferItemErrorBuffer :=
or(
invalidNativeOfferItemErrorBuffer,
lt(mload(offerItem), mload(0))
lt(mload(offerItem), isNonContract)
)
}

Expand Down

0 comments on commit a8dc71d

Please sign in to comment.