Skip to content

Commit

Permalink
Merge pull request #55 from ProjectOpenSea/basic-order-optimize-valid…
Browse files Browse the repository at this point in the history
…ate-sig

Only copy signature calldata region to memory when it is needed for `BasicOrder`s
  • Loading branch information
0age authored Mar 5, 2024
2 parents a8dc71d + 609ddbf commit c912945
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
17 changes: 1 addition & 16 deletions src/core/lib/BasicOrderFulfiller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
AdditionalRecipient_size,
BasicOrder_additionalRecipients_data_cdPtr,
BasicOrder_additionalRecipients_length_cdPtr,
BasicOrder_basicOrderParameters_cd_offset,
BasicOrder_basicOrderType_cdPtr,
BasicOrder_common_params_size,
BasicOrder_considerationAmount_cdPtr,
Expand Down Expand Up @@ -58,7 +57,6 @@ import {
BasicOrder_order_startTime_ptr,
BasicOrder_order_typeHash_ptr,
BasicOrder_receivedItemByteMap,
BasicOrder_signature_cdPtr,
BasicOrder_startTime_cdPtr,
BasicOrder_totalOriginalAdditionalRecipients_cdPtr,
BasicOrder_zone_cdPtr,
Expand Down Expand Up @@ -1059,20 +1057,7 @@ contract BasicOrderFulfiller is OrderValidator {

// Verify the status of the derived order.
OrderStatus storage orderStatus = _validateBasicOrder(
orderHash,
_toBytesReturnType(_decodeBytes)(
// Wrap the absolute pointer to the order signature as a
// CalldataPointer.
CalldataPointer.wrap(
// Read the relative pointer to the order signature.
CalldataPointer
.wrap(BasicOrder_signature_cdPtr)
.readMaskedUint256() +
// Add the BasicOrderParameters struct offset to the
// relative pointer.
BasicOrder_basicOrderParameters_cd_offset
)
)
orderHash
);

// Determine whether order is restricted and, if so, that it is valid.
Expand Down
29 changes: 24 additions & 5 deletions src/core/lib/OrderValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import { MemoryPointer } from "seaport-types/src/helpers/PointerLibraries.sol";
import {
AdvancedOrder_denominator_offset,
AdvancedOrder_numerator_offset,
BasicOrder_basicOrderParameters_cd_offset,
BasicOrder_offerer_cdPtr,
BasicOrder_signature_cdPtr,
Common_amount_offset,
Common_endAmount_offset,
Common_identifier_offset,
Expand All @@ -53,6 +55,10 @@ import {
Panic_error_selector
} from "seaport-types/src/lib/ConsiderationErrorConstants.sol";

import {
CalldataPointer
} from "seaport-types/src/helpers/PointerLibraries.sol";

/**
* @title OrderValidator
* @author 0age
Expand Down Expand Up @@ -83,12 +89,9 @@ contract OrderValidator is Executor, ZoneInteraction {
* must first be validated.
*
* @param orderHash The hash of the order.
* @param signature A signature from the offerer indicating that the order
* has been approved.
*/
function _validateBasicOrder(
bytes32 orderHash,
bytes memory signature
bytes32 orderHash
) internal view returns (OrderStatus storage orderStatus) {
// Retrieve offerer directly using fixed calldata offset based on strict
// basic parameter encoding.
Expand All @@ -110,7 +113,23 @@ contract OrderValidator is Executor, ZoneInteraction {

// If the order is not already validated, verify the supplied signature.
if (!orderStatus.isValidated) {
_verifySignature(offerer, orderHash, signature);
_verifySignature(
offerer,
orderHash,
_toBytesReturnType(_decodeBytes)(
// Wrap the absolute pointer to the order signature as a
// CalldataPointer.
CalldataPointer.wrap(
// Read the relative pointer to the order signature.
CalldataPointer
.wrap(BasicOrder_signature_cdPtr)
.readMaskedUint256() +
// Add the BasicOrderParameters struct offset to the
// relative pointer.
BasicOrder_basicOrderParameters_cd_offset
)
)
);
}
}

Expand Down

0 comments on commit c912945

Please sign in to comment.