From eea3ac91eb76907022a116c12f0509b770cd29b3 Mon Sep 17 00:00:00 2001 From: 0age <0age@protonmail.com> Date: Wed, 6 Mar 2024 15:55:52 -0500 Subject: [PATCH] general cleanup --- src/core/lib/BasicOrderFulfiller.sol | 25 +++++++++++++----------- src/core/lib/ConsiderationDecoder.sol | 9 +++++---- src/core/lib/ConsiderationEncoder.sol | 12 +++++++----- src/core/lib/FulfillmentApplier.sol | 6 +++++- src/core/lib/OrderCombiner.sol | 2 +- src/core/lib/OrderValidator.sol | 8 ++++---- src/types/lib/ConsiderationConstants.sol | 10 +++++++--- 7 files changed, 43 insertions(+), 29 deletions(-) diff --git a/src/core/lib/BasicOrderFulfiller.sol b/src/core/lib/BasicOrderFulfiller.sol index a673cfc..fff9a7e 100644 --- a/src/core/lib/BasicOrderFulfiller.sol +++ b/src/core/lib/BasicOrderFulfiller.sol @@ -91,9 +91,9 @@ import { OrderFulfilled_offer_body_offset, OrderFulfilled_offer_head_offset, OrderFulfilled_offer_length_baseOffset, - OrderFulfilled_offer_length_baseOffset_relativeTo_OrderFulfilled_baseOffset, - OrderFulfilled_offer_itemType_baseOffset_relativeTo_OrderFulfilled_baseOffset, - OrderFulfilled_offer_token_baseOffset_relativeTo_OrderFulfilled_baseOffset, + OrderFulfilled_offer_length_offset_relativeTo_baseOffset, + OrderFulfilled_offer_itemType_offset_relativeTo_baseOffset, + OrderFulfilled_offer_token_offset_relativeTo_baseOffset, OrderFulfilled_post_memory_region_reservedBytes, OrderFulfilled_selector, ReceivedItem_amount_offset, @@ -1012,7 +1012,7 @@ contract BasicOrderFulfiller is OrderValidator { mstore( add( eventDataPtr, - OrderFulfilled_offer_length_baseOffset_relativeTo_OrderFulfilled_baseOffset + OrderFulfilled_offer_length_offset_relativeTo_baseOffset ), 1 ) @@ -1021,7 +1021,7 @@ contract BasicOrderFulfiller is OrderValidator { mstore( add( eventDataPtr, - OrderFulfilled_offer_itemType_baseOffset_relativeTo_OrderFulfilled_baseOffset + OrderFulfilled_offer_itemType_offset_relativeTo_baseOffset ), offeredItemType ) @@ -1032,7 +1032,7 @@ contract BasicOrderFulfiller is OrderValidator { calldatacopy( add( eventDataPtr, - OrderFulfilled_offer_token_baseOffset_relativeTo_OrderFulfilled_baseOffset + OrderFulfilled_offer_token_offset_relativeTo_baseOffset ), BasicOrder_offerToken_cdPtr, ThreeWords @@ -1074,11 +1074,14 @@ contract BasicOrderFulfiller is OrderValidator { mstore(FreeMemoryPointerSlot, add( eventDataPtr, - // reserve extra 3 words to be used by `authorizeOrder` and - // `validatateOrder` if pre-post exection hook to the zone is - // required. These 3 memory slots will be used for the extra data/context - // and order hashes of the calldata. - add(dataSize, OrderFulfilled_post_memory_region_reservedBytes) + // Reserve extra 3 words to be used by `authorizeOrder` and + // `validatateOrder` if pre-post exection hook to the zone + // is required. These 3 memory slots will be used for the + // extra data/context and order hashes of the calldata. + add( + dataSize, + OrderFulfilled_post_memory_region_reservedBytes + ) ) ) } diff --git a/src/core/lib/ConsiderationDecoder.sol b/src/core/lib/ConsiderationDecoder.sol index 638cf55..4bc64ed 100644 --- a/src/core/lib/ConsiderationDecoder.sol +++ b/src/core/lib/ConsiderationDecoder.sol @@ -890,8 +890,8 @@ contract ConsiderationDecoder { // 1. offerOffset // 2. considerationOffset // 3. offerLength & considerationLength might occupy just one word - // if offerOffset & considerationOffset would point to the same offset - // and the arrays have length 0. + // if offerOffset & considerationOffset would point to the same + // offset and the arrays have length 0. invalidEncoding := lt(returndatasize(), ThreeWords) let offsetOffer @@ -907,7 +907,8 @@ contract ConsiderationDecoder { offsetOffer := mload(0) offsetConsideration := mload(OneWord) - // If valid length, check that offsets word boundaries are within returndata. + // If valid length, check that offsets word boundaries are + // within returndata. let invalidOfferOffset := gt( add(offsetOffer, OneWord), @@ -932,7 +933,7 @@ contract ConsiderationDecoder { considerationLength := mload(OneWord) { - // Calculate end offsets of offer & consideration arrays. + // Derive end offsets for offer & consideration arrays. let offerEndOffset := add( add(offsetOffer, OneWord), diff --git a/src/core/lib/ConsiderationEncoder.sol b/src/core/lib/ConsiderationEncoder.sol index 811a86b..0f7965c 100644 --- a/src/core/lib/ConsiderationEncoder.sol +++ b/src/core/lib/ConsiderationEncoder.sol @@ -555,11 +555,13 @@ contract ConsiderationEncoder { /** * @dev Takes an order hash and BasicOrderParameters struct (from calldata) - * and encodes it as `authorizeOrder` calldata. Note that memory data is reused - * from `OrderFulfilled` event data, and the rest of the calldata is prefixed and - * postfixed to this memory region. Importantly the memory region before the - * `OrderFulfilled`'s spent and received items are overwritten to. So this - * function will need to be modified if the layout of that event data changes. + * and encodes it as `authorizeOrder` calldata. Note that memory data + * is reused from `OrderFulfilled` event data, and the rest of the + * calldata is prefixed and postfixed to this memory region. Note that + * the memory region before the spent and received items on the + * `OrderFulfilled` event are overwritten, which implies that this + * function will need to be modified should the layout of that event + * data change in the future. * * @param orderHash The order hash. * diff --git a/src/core/lib/FulfillmentApplier.sol b/src/core/lib/FulfillmentApplier.sol index 045c3af..6a030fb 100644 --- a/src/core/lib/FulfillmentApplier.sol +++ b/src/core/lib/FulfillmentApplier.sol @@ -546,7 +546,7 @@ contract FulfillmentApplier is FulfillmentApplicationErrors { * using supplied directives on which component items are candidates * for aggregation, skipping items on orders that are not available. * Note that this function depends on memory layout affected by an - * earlier call to _validateOrdersAndPrepareToFulfill. The memory for + * earlier call to _validateOrdersAndPrepareToFulfill. The memory for * the consideration arrays needs to be updated before calling * _aggregateValidFulfillmentConsiderationItems. * _validateOrdersAndPrepareToFulfill is called in _matchAdvancedOrders @@ -559,6 +559,10 @@ contract FulfillmentApplier is FulfillmentApplicationErrors { * of each candidate consideration item for * aggregation. * @param execution The execution to apply the aggregation to. + * @param offerer The address of the offerer to set on the + * execution. + * @param conduitKey A bytes32 value indicating the conduit key + * to set on the execution. */ function _aggregateValidFulfillmentConsiderationItems( AdvancedOrder[] memory advancedOrders, diff --git a/src/core/lib/OrderCombiner.sol b/src/core/lib/OrderCombiner.sol index 0df5e2b..7ad669a 100644 --- a/src/core/lib/OrderCombiner.sol +++ b/src/core/lib/OrderCombiner.sol @@ -444,7 +444,7 @@ contract OrderCombiner is OrderFulfiller, FulfillmentApplier { let considerationItemRecipientPtr := add( considerationItem, - ConsiderationItem_recipient_offset // recipient + ConsiderationItem_recipient_offset ) // Write recipient to endAmount, as endAmount is not diff --git a/src/core/lib/OrderValidator.sol b/src/core/lib/OrderValidator.sol index c9fee7c..e150b8e 100644 --- a/src/core/lib/OrderValidator.sol +++ b/src/core/lib/OrderValidator.sol @@ -112,7 +112,7 @@ contract OrderValidator is Executor, ZoneInteraction { ); unchecked { - // If the order is not already validated, verify the supplied signature. + // If the order is not already validated, verify supplied signature. if (!orderStatus.isValidated) { _verifySignature( offerer, @@ -125,8 +125,8 @@ contract OrderValidator is Executor, ZoneInteraction { CalldataPointer .wrap(BasicOrder_signature_cdPtr) .readMaskedUint256() + - // Add the BasicOrderParameters struct offset to the - // relative pointer. + // Add the BasicOrderParameters struct offset to + // the relative pointer. BasicOrder_basicOrderParameters_cd_offset ) ) @@ -517,7 +517,7 @@ contract OrderValidator is Executor, ZoneInteraction { out := _a } - // Determine the amount to scale down the new filled fraction. + // Determine amount to scale down the new filled fraction. let scaleDown := gcd(filledNumerator, denominator) // Ensure that the divisor is at least one. diff --git a/src/types/lib/ConsiderationConstants.sol b/src/types/lib/ConsiderationConstants.sol index ba85dd5..81c42b0 100644 --- a/src/types/lib/ConsiderationConstants.sol +++ b/src/types/lib/ConsiderationConstants.sol @@ -288,9 +288,13 @@ uint256 constant OrderFulfilled_baseOffset = 0x180; uint256 constant OrderFulfilled_consideration_length_baseOffset = 0x2a0; uint256 constant OrderFulfilled_offer_length_baseOffset = 0x200; -uint256 constant OrderFulfilled_offer_length_baseOffset_relativeTo_OrderFulfilled_baseOffset = 0x80; -uint256 constant OrderFulfilled_offer_itemType_baseOffset_relativeTo_OrderFulfilled_baseOffset = 0xa0; -uint256 constant OrderFulfilled_offer_token_baseOffset_relativeTo_OrderFulfilled_baseOffset = 0xc0; +uint256 constant OrderFulfilled_offer_length_offset_relativeTo_baseOffset = ( + 0x80 +); +uint256 constant OrderFulfilled_offer_itemType_offset_relativeTo_baseOffset = ( + 0xa0 +); +uint256 constant OrderFulfilled_offer_token_offset_relativeTo_baseOffset = 0xc0; // Related constants used for restricted order checks on basic orders. uint256 constant OrderFulfilled_baseDataSize = 0x160;