Skip to content

Commit

Permalink
keep pushing
Browse files Browse the repository at this point in the history
  • Loading branch information
0age committed Feb 7, 2024
1 parent 1a247b2 commit 915ea6c
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 19 deletions.
13 changes: 12 additions & 1 deletion src/core/lib/CriteriaResolution.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

import { ItemType, Side } from "seaport-types/src/lib/ConsiderationEnums.sol";
import {
ItemType,
OrderType,
Side
} from "seaport-types/src/lib/ConsiderationEnums.sol";

import {
AdvancedOrder,
Expand Down Expand Up @@ -173,6 +177,13 @@ contract CriteriaResolution is CriteriaResolutionErrors {
OrderParameters memory orderParameters =
(advancedOrder.parameters);

// Skip verification that all criteria have been resolved
// for contract orders, as they will be checked as part
// of order generation.
if (orderParameters.orderType == OrderType.CONTRACT) {
continue;
}

// Read consideration length from memory and place on stack.
uint256 totalItems = orderParameters.consideration.length;

Expand Down
55 changes: 55 additions & 0 deletions src/core/lib/OrderCombiner.sol
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,61 @@ contract OrderCombiner is OrderFulfiller, FulfillmentApplier {
advancedOrder.parameters, advancedOrder.extraData, revertOnInvalid
);

////// TEMP TEMP TEMP — instead we should copy these encoded values
// right from the returndata of generateOrder or something similar.

// Iterate over each offer item on the order.
for (uint256 j = 0; j < advancedOrder.parameters.offer.length; ++j) {
// Retrieve the offer item.
OfferItem memory offerItem = advancedOrder.parameters.offer[j];

// Update amounts in memory to match the current amount.
// Note that the end amount is used to track spent amounts.
offerItem.endAmount = offerItem.startAmount;
}

// Iterate over each consideration item on the order.
for (uint256 j = 0; j < advancedOrder.parameters.consideration.length; ++j) {
// Retrieve the consideration item.
ConsiderationItem memory considerationItem =
(advancedOrder.parameters.consideration[j]);

uint256 currentAmount = considerationItem.startAmount;

// Utilize assembly to manually "shift" the recipient value,
// then to copy the start amount to the recipient.
// Note that this sets up the memory layout that is
// subsequently relied upon by
// _aggregateValidFulfillmentConsiderationItems.
assembly {
// Derive the pointer to the recipient using the item
// pointer along with the offset to the recipient.
let considerationItemRecipientPtr :=
add(
considerationItem,
ConsiderationItem_recipient_offset // recipient
)

// Write recipient to endAmount, as endAmount is not
// used from this point on and can be repurposed to fit
// the layout of a ReceivedItem.
mstore(
add(
considerationItem,
ReceivedItem_recipient_offset // old endAmount
),
mload(considerationItemRecipientPtr)
)

// Write startAmount to recipient, as recipient is not
// used from this point on and can be repurposed to
// track received amounts.
mstore(considerationItemRecipientPtr, currentAmount)
}
}

////// END TEMP TEMP TEMP

assembly {
mstore(add(orderHashes, i), orderHash)
}
Expand Down
34 changes: 16 additions & 18 deletions src/core/lib/OrderValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ import {
MaxUint120,
OrderStatus_filledDenominator_offset,
OrderStatus_filledNumerator_offset,
OrderStatus_ValidatedAndNotCancelled
OrderStatus_ValidatedAndNotCancelled,
ReceivedItem_recipient_offset
} from "seaport-types/src/lib/ConsiderationConstants.sol";

import {
Expand Down Expand Up @@ -574,16 +575,19 @@ contract OrderValidator is Executor, ZoneInteraction {
let itemType := mload(originalItem)
let identifier := mload(add(originalItem, Common_identifier_offset))

// Set returned identifier for criteria-based items w/ criteria = 0.
if and(gt(itemType, 3), iszero(identifier)) {
// Set returned identifier for criteria-based items w/ criteria = 0
// (and revert if criteria != 0).
if gt(itemType, 3) {
if identifier {
// TODO: replace with an "unresolved criteria" error?
revert(0, 0)
}

// replace item type
itemType := sub(3, eq(itemType, 4))
identifier := mload(add(newItem, Common_identifier_offset))
}

let originalAmount := mload(add(originalItem, Common_amount_offset))
let newAmount := mload(add(newItem, Common_amount_offset))

isInvalid :=
iszero(
and(
Expand All @@ -596,18 +600,12 @@ contract OrderValidator is Executor, ZoneInteraction {
),
eq(itemType, mload(newItem))
),
// originalItem.identifier == newItem.identifier &&
// originalItem.startAmount == originalItem.endAmount
and(
eq(
identifier,
mload(add(newItem, Common_identifier_offset))
),
eq(
originalAmount,
mload(add(originalItem, Common_endAmount_offset))
)
// originalItem.identifier == newItem.identifier
eq(
identifier,
mload(add(newItem, Common_identifier_offset))
)

)
)
}
Expand Down Expand Up @@ -787,7 +785,7 @@ contract OrderValidator is Executor, ZoneInteraction {
> mPtrOriginal.offset(Common_amount_offset).readUint256()
) | _compareItems(mPtrOriginal, mPtrNew)
| _checkRecipients(
mPtrOriginal.offset(ConsiderItem_recipient_offset)
mPtrOriginal.offset(ReceivedItem_recipient_offset)
.readAddress(),
mPtrNew.offset(ConsiderItem_recipient_offset).readAddress()
);
Expand Down

0 comments on commit 915ea6c

Please sign in to comment.