Skip to content

Commit

Permalink
Merge pull request #26 from ProjectOpenSea/bypass-solc-badisms
Browse files Browse the repository at this point in the history
Bypass solc badisms
  • Loading branch information
0age authored Feb 19, 2024
2 parents d065e19 + 6cec649 commit 0482548
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 74 deletions.
18 changes: 9 additions & 9 deletions src/core/lib/Consideration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ contract Consideration is ConsiderationInterface, OrderCombiner {
CalldataStart.pptr()
),
_toCriteriaResolversReturnType(_decodeCriteriaResolvers)(
CalldataStart.pptr(
CalldataStart.pptrOffset(
Offset_fulfillAdvancedOrder_criteriaResolvers
)
),
Expand Down Expand Up @@ -346,14 +346,14 @@ contract Consideration is ConsiderationInterface, OrderCombiner {
_toNestedFulfillmentComponentsReturnType(
_decodeNestedFulfillmentComponents
)(
CalldataStart.pptr(
CalldataStart.pptrOffset(
Offset_fulfillAvailableOrders_offerFulfillments
)
),
_toNestedFulfillmentComponentsReturnType(
_decodeNestedFulfillmentComponents
)(
CalldataStart.pptr(
CalldataStart.pptrOffset(
Offset_fulfillAvailableOrders_considerationFulfillments
)
),
Expand Down Expand Up @@ -476,21 +476,21 @@ contract Consideration is ConsiderationInterface, OrderCombiner {
CalldataStart.pptr()
),
_toCriteriaResolversReturnType(_decodeCriteriaResolvers)(
CalldataStart.pptr(
CalldataStart.pptrOffset(
Offset_fulfillAvailableAdvancedOrders_criteriaResolvers
)
),
_toNestedFulfillmentComponentsReturnType(
_decodeNestedFulfillmentComponents
)(
CalldataStart.pptr(
CalldataStart.pptrOffset(
Offset_fulfillAvailableAdvancedOrders_offerFulfillments
)
),
_toNestedFulfillmentComponentsReturnType(
_decodeNestedFulfillmentComponents
)(
CalldataStart.pptr(
CalldataStart.pptrOffset(
Offset_fulfillAvailableAdvancedOrders_cnsdrationFlflmnts
)
),
Expand Down Expand Up @@ -551,7 +551,7 @@ contract Consideration is ConsiderationInterface, OrderCombiner {
),
new CriteriaResolver[](0), // No criteria resolvers supplied.
_toFulfillmentsReturnType(_decodeFulfillments)(
CalldataStart.pptr(Offset_matchOrders_fulfillments)
CalldataStart.pptrOffset(Offset_matchOrders_fulfillments)
),
msg.sender
);
Expand Down Expand Up @@ -635,10 +635,10 @@ contract Consideration is ConsiderationInterface, OrderCombiner {
CalldataStart.pptr()
),
_toCriteriaResolversReturnType(_decodeCriteriaResolvers)(
CalldataStart.pptr(Offset_matchAdvancedOrders_criteriaResolvers)
CalldataStart.pptrOffset(Offset_matchAdvancedOrders_criteriaResolvers)
),
_toFulfillmentsReturnType(_decodeFulfillments)(
CalldataStart.pptr(Offset_matchAdvancedOrders_fulfillments)
CalldataStart.pptrOffset(Offset_matchAdvancedOrders_fulfillments)
),
_substituteCallerForEmptyRecipient(recipient)
);
Expand Down
32 changes: 16 additions & 16 deletions src/core/lib/ConsiderationDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ contract ConsiderationDecoder {
// Resolve the offer calldata offset, use that to decode and copy offer
// from calldata, and write resultant memory offset to head in memory.
mPtr.offset(OrderParameters_offer_head_offset).write(
_decodeOffer(cdPtr.pptr(OrderParameters_offer_head_offset))
_decodeOffer(cdPtr.pptrOffset(OrderParameters_offer_head_offset))
);

// Resolve consideration calldata offset, use that to copy consideration
// from calldata, and write resultant memory offset to head in memory.
mPtr.offset(OrderParameters_consideration_head_offset).write(
_decodeConsideration(
cdPtr.pptr(OrderParameters_consideration_head_offset)
cdPtr.pptrOffset(OrderParameters_consideration_head_offset)
)
);
}
Expand Down Expand Up @@ -311,7 +311,7 @@ contract ConsiderationDecoder {
// Resolve signature calldata offset, use that to decode and copy from
// calldata, and write resultant memory offset to head in memory.
mPtr.offset(Order_signature_offset).write(
_decodeBytes(cdPtr.pptr(Order_signature_offset))
_decodeBytes(cdPtr.pptrOffset(Order_signature_offset))
);
}

Expand Down Expand Up @@ -350,13 +350,13 @@ contract ConsiderationDecoder {
// Resolve signature calldata offset, use that to decode and copy from
// calldata, and write resultant memory offset to head in memory.
mPtr.offset(AdvancedOrder_signature_offset).write(
_decodeBytes(cdPtr.pptr(AdvancedOrder_signature_offset))
_decodeBytes(cdPtr.pptrOffset(AdvancedOrder_signature_offset))
);

// Resolve extraData calldata offset, use that to decode and copy from
// calldata, and write resultant memory offset to head in memory.
mPtr.offset(AdvancedOrder_extraData_offset).write(
_decodeBytes(cdPtr.pptr(AdvancedOrder_extraData_offset))
_decodeBytes(cdPtr.pptrOffset(AdvancedOrder_extraData_offset))
);
}

Expand Down Expand Up @@ -407,7 +407,7 @@ contract ConsiderationDecoder {
// Resolve signature calldata offset, use that to decode and copy from
// calldata, and write resultant memory offset to head in memory.
mPtr.offset(AdvancedOrder_signature_offset).write(
_decodeBytes(cdPtr.pptr(Order_signature_offset))
_decodeBytes(cdPtr.pptrOffset(Order_signature_offset))
);

// Resolve extraData calldata offset, use that to decode and copy from
Expand Down Expand Up @@ -454,7 +454,7 @@ contract ConsiderationDecoder {
// Resolve Order calldata offset, use it to decode and copy from
// calldata, and write resultant AdvancedOrder offset to memory.
mPtrHead.offset(offset).write(
_decodeOrderAsAdvancedOrder(cdPtrHead.pptr(offset))
_decodeOrderAsAdvancedOrder(cdPtrHead.pptrOffset(offset))
);
}
}
Expand Down Expand Up @@ -515,7 +515,7 @@ contract ConsiderationDecoder {
// from calldata, and write resultant memory offset to head in memory.
mPtr.offset(CriteriaResolver_criteriaProof_offset).write(
_decodeCriteriaProof(
cdPtr.pptr(CriteriaResolver_criteriaProof_offset)
cdPtr.pptrOffset(CriteriaResolver_criteriaProof_offset)
)
);
}
Expand Down Expand Up @@ -559,7 +559,7 @@ contract ConsiderationDecoder {
// Resolve CriteriaResolver calldata offset, use it to decode
// and copy from calldata, and write resultant memory offset.
mPtrHead.offset(offset).write(
_decodeCriteriaResolver(cdPtrHead.pptr(offset))
_decodeCriteriaResolver(cdPtrHead.pptrOffset(offset))
);
}
}
Expand Down Expand Up @@ -601,7 +601,7 @@ contract ConsiderationDecoder {
// Resolve Order calldata offset, use it to decode and copy
// from calldata, and write resultant memory offset.
mPtrHead.offset(offset).write(
_decodeOrder(cdPtrHead.pptr(offset))
_decodeOrder(cdPtrHead.pptrOffset(offset))
);
}
}
Expand Down Expand Up @@ -691,7 +691,7 @@ contract ConsiderationDecoder {
// Resolve FulfillmentComponents array calldata offset, use it
// to decode and copy from calldata, and write memory offset.
mPtrHead.offset(offset).write(
_decodeFulfillmentComponents(cdPtrHead.pptr(offset))
_decodeFulfillmentComponents(cdPtrHead.pptrOffset(offset))
);
}
}
Expand Down Expand Up @@ -736,7 +736,7 @@ contract ConsiderationDecoder {
// Resolve AdvancedOrder calldata offset, use it to decode and
// copy from calldata, and write resultant memory offset.
mPtrHead.offset(offset).write(
_decodeAdvancedOrder(cdPtrHead.pptr(offset))
_decodeAdvancedOrder(cdPtrHead.pptrOffset(offset))
);
}
}
Expand Down Expand Up @@ -767,7 +767,7 @@ contract ConsiderationDecoder {
// copy from calldata, and write resultant memory offset to memory head.
mPtr.offset(Fulfillment_considerationComponents_offset).write(
_decodeFulfillmentComponents(
cdPtr.pptr(Fulfillment_considerationComponents_offset)
cdPtr.pptrOffset(Fulfillment_considerationComponents_offset)
)
);
}
Expand Down Expand Up @@ -811,7 +811,7 @@ contract ConsiderationDecoder {
// Resolve Fulfillment calldata offset, use it to decode and
// copy from calldata, and write resultant memory offset.
mPtrHead.offset(offset).write(
_decodeFulfillment(cdPtrHead.pptr(offset))
_decodeFulfillment(cdPtrHead.pptrOffset(offset))
);
}
}
Expand Down Expand Up @@ -841,13 +841,13 @@ contract ConsiderationDecoder {
// Resolve the offer calldata offset, use that to decode and copy offer
// from calldata, and write resultant memory offset to head in memory.
mPtr.offset(OrderParameters_offer_head_offset).write(
_decodeOffer(cdPtr.pptr(OrderParameters_offer_head_offset))
_decodeOffer(cdPtr.pptrOffset(OrderParameters_offer_head_offset))
);

// Resolve consideration calldata offset, use that to copy consideration
// from calldata, and write resultant memory offset to head in memory.
MemoryPointer consideration = _decodeConsideration(
cdPtr.pptr(OrderParameters_consideration_head_offset)
cdPtr.pptrOffset(OrderParameters_consideration_head_offset)
);
mPtr.offset(OrderParameters_consideration_head_offset).write(
consideration
Expand Down
2 changes: 1 addition & 1 deletion src/core/lib/CriteriaResolution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ contract CriteriaResolution is CriteriaResolutionErrors {
// Using the array directly has a significant impact on
// the optimized compiler output.
MemoryPointer considerationPtr = orderParameters
.toMemoryPointer().pptr(
.toMemoryPointer().pptrOffset(
OrderParameters_consideration_head_offset
);

Expand Down
54 changes: 54 additions & 0 deletions src/core/lib/LowLevelHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
ThirtyOneBytes
} from "seaport-types/src/lib/ConsiderationConstants.sol";

import { MemoryPointer, MemoryPointerLib } from "seaport-types/src/helpers/PointerLibraries.sol";

import { AdvancedOrder } from "seaport-types/src/lib/ConsiderationStructs.sol";

/**
* @title LowLevelHelpers
* @author 0age
Expand Down Expand Up @@ -107,4 +111,54 @@ contract LowLevelHelpers {
u := b
}
}

/**
* @dev Internal pure function to cast the `pptrOffset` function from
* `MemoryPointerLib` to a function that takes a memory array of
* `AdvancedOrder` and an offset in memory and returns the
* `AdvancedOrder` whose pointer is stored at that offset from the
* array length.
*/
function _getReadAdvancedOrderByOffset(
// function (MemoryPointer, uint256) internal pure returns (MemoryPointer) fn1
) internal pure returns (
function (AdvancedOrder[] memory, uint256) internal pure returns (AdvancedOrder memory) fn2
) {
function (MemoryPointer, uint256) internal pure returns (MemoryPointer) fn1 = MemoryPointerLib.pptrOffset;
assembly {
fn2 := fn1
}
}

/**
* @dev Internal pure function to return a `true` value that solc
* will not recognize as a compile time constant.
*
* This function is used to bypass function specialization for
* functions which take a constant boolean as an input parameter.
*
* This should only be used in cases where specialization has a
* negligible impact on the gas cost of the function.
*
* Note: assumes the calldatasize is non-zero.
*/
function _runTimeConstantTrue() internal pure returns (bool) {
return msg.data.length > 0;
}

/**
* @dev Internal pure function to return a `false` value that solc
* will not recognize as a compile time constant.
*
* This function is used to bypass function specialization for
* functions which take a constant boolean as an input parameter.
*
* This should only be used in cases where specialization has a
* negligible impact on the gas cost of the function.
*
* Note: assumes the calldatasize is non-zero.
*/
function _runTimeConstantFalse() internal pure returns (bool) {
return msg.data.length == 0;
}
}
Loading

0 comments on commit 0482548

Please sign in to comment.