Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nkrishang committed Mar 26, 2024
1 parent 0b26e81 commit 85b889b
Showing 1 changed file with 103 additions and 134 deletions.
237 changes: 103 additions & 134 deletions contracts/extension/SeaportOrderParser.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,54 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.11;

import { OrderParameters } from "seaport-types/src/lib/ConsiderationStructs.sol";
import { EIP_712_PREFIX, EIP712_ConsiderationItem_size, EIP712_DigestPayload_size, EIP712_DomainSeparator_offset, EIP712_OfferItem_size, EIP712_Order_size, EIP712_OrderHash_offset, OneWord, OneWordShift, OrderParameters_consideration_head_offset, OrderParameters_counter_offset, OrderParameters_offer_head_offset, TwoWords, BulkOrderProof_keyShift, BulkOrderProof_keySize, BulkOrder_Typehash_Height_One, BulkOrder_Typehash_Height_Two, BulkOrder_Typehash_Height_Three, BulkOrder_Typehash_Height_Four, BulkOrder_Typehash_Height_Five, BulkOrder_Typehash_Height_Six, BulkOrder_Typehash_Height_Seven, BulkOrder_Typehash_Height_Eight, BulkOrder_Typehash_Height_Nine, BulkOrder_Typehash_Height_Ten, BulkOrder_Typehash_Height_Eleven, BulkOrder_Typehash_Height_Twelve, BulkOrder_Typehash_Height_Thirteen, BulkOrder_Typehash_Height_Fourteen, BulkOrder_Typehash_Height_Fifteen, BulkOrder_Typehash_Height_Sixteen, BulkOrder_Typehash_Height_Seventeen, BulkOrder_Typehash_Height_Eighteen, BulkOrder_Typehash_Height_Nineteen, BulkOrder_Typehash_Height_Twenty, BulkOrder_Typehash_Height_TwentyOne, BulkOrder_Typehash_Height_TwentyTwo, BulkOrder_Typehash_Height_TwentyThree, BulkOrder_Typehash_Height_TwentyFour, FreeMemoryPointerSlot } from "seaport-types/src/lib/ConsiderationConstants.sol";
/* solhint-disable */

import {OrderParameters} from "seaport-types/src/lib/ConsiderationStructs.sol";
import {
EIP_712_PREFIX,
EIP712_ConsiderationItem_size,
EIP712_DigestPayload_size,
EIP712_DomainSeparator_offset,
EIP712_OfferItem_size,
EIP712_Order_size,
EIP712_OrderHash_offset,
OneWord,
OneWordShift,
OrderParameters_consideration_head_offset,
OrderParameters_counter_offset,
OrderParameters_offer_head_offset,
TwoWords,
BulkOrderProof_keyShift,
BulkOrderProof_keySize,
BulkOrder_Typehash_Height_One,
BulkOrder_Typehash_Height_Two,
BulkOrder_Typehash_Height_Three,
BulkOrder_Typehash_Height_Four,
BulkOrder_Typehash_Height_Five,
BulkOrder_Typehash_Height_Six,
BulkOrder_Typehash_Height_Seven,
BulkOrder_Typehash_Height_Eight,
BulkOrder_Typehash_Height_Nine,
BulkOrder_Typehash_Height_Ten,
BulkOrder_Typehash_Height_Eleven,
BulkOrder_Typehash_Height_Twelve,
BulkOrder_Typehash_Height_Thirteen,
BulkOrder_Typehash_Height_Fourteen,
BulkOrder_Typehash_Height_Fifteen,
BulkOrder_Typehash_Height_Sixteen,
BulkOrder_Typehash_Height_Seventeen,
BulkOrder_Typehash_Height_Eighteen,
BulkOrder_Typehash_Height_Nineteen,
BulkOrder_Typehash_Height_Twenty,
BulkOrder_Typehash_Height_TwentyOne,
BulkOrder_Typehash_Height_TwentyTwo,
BulkOrder_Typehash_Height_TwentyThree,
BulkOrder_Typehash_Height_TwentyFour,
FreeMemoryPointerSlot
} from "seaport-types/src/lib/ConsiderationConstants.sol";

contract SeaportOrderParser {
uint256 constant ECDSA_MaxLength = 65;
uint256 constant ECDSA_MAXLENGTH = 65;

bytes32 private immutable _NAME_HASH;
bytes32 private immutable _VERSION_HASH;
Expand All @@ -31,14 +74,14 @@ contract SeaportOrderParser {
}

function _buildSeaportDomainSeparator(address _domainAddress) internal view returns (bytes32) {
return
keccak256(abi.encode(_EIP_712_DOMAIN_TYPEHASH, _NAME_HASH, _VERSION_HASH, block.chainid, _domainAddress));
return keccak256(abi.encode(_EIP_712_DOMAIN_TYPEHASH, _NAME_HASH, _VERSION_HASH, block.chainid, _domainAddress));

Check warning on line 77 in contracts/extension/SeaportOrderParser.sol

View check run for this annotation

Codecov / codecov/patch

contracts/extension/SeaportOrderParser.sol#L77

Added line #L77 was not covered by tests
}

function _deriveOrderHash(
OrderParameters memory orderParameters,
uint256 counter
) internal view returns (bytes32 orderHash) {
function _deriveOrderHash(OrderParameters memory orderParameters, uint256 counter)
internal
view
returns (bytes32 orderHash)
{
// Get length of original consideration array and place it on the stack.
uint256 originalConsiderationLength = (orderParameters.totalOriginalConsiderationItems);

Check warning on line 86 in contracts/extension/SeaportOrderParser.sol

View check run for this annotation

Codecov / codecov/patch

contracts/extension/SeaportOrderParser.sol#L86

Added line #L86 was not covered by tests

Expand Down Expand Up @@ -70,11 +113,7 @@ contract SeaportOrderParser {
offerArrPtr := add(offerArrPtr, OneWord)

Check warning on line 113 in contracts/extension/SeaportOrderParser.sol

View check run for this annotation

Codecov / codecov/patch

contracts/extension/SeaportOrderParser.sol#L113

Added line #L113 was not covered by tests

// Iterate over the offer items.
for {
let i := 0
} lt(i, offerLength) {
i := add(i, 1)
} {
for { let i := 0 } lt(i, offerLength) { i := add(i, 1) } {
// Read the pointer to the offer data and subtract one word
// to get typeHash pointer.
let ptr := sub(mload(offerArrPtr), OneWord)
Expand Down Expand Up @@ -112,17 +151,11 @@ contract SeaportOrderParser {
let hashArrPtr := mload(FreeMemoryPointerSlot)

// Get the pointer to the consideration array.
let considerationArrPtr := add(
mload(add(orderParameters, OrderParameters_consideration_head_offset)),
OneWord
)
let considerationArrPtr :=
add(mload(add(orderParameters, OrderParameters_consideration_head_offset)), OneWord)

// Iterate over the consideration items (not including tips).
for {
let i := 0
} lt(i, originalConsiderationLength) {
i := add(i, 1)
} {
for { let i := 0 } lt(i, originalConsiderationLength) { i := add(i, 1) } {
// Read the pointer to the consideration data and subtract one
// word to get typeHash pointer.
let ptr := sub(mload(considerationArrPtr), OneWord)
Expand Down Expand Up @@ -223,54 +256,26 @@ contract SeaportOrderParser {

// Construct the OfferItem type string.
bytes memory offerItemTypeString = bytes(

Check warning on line 258 in contracts/extension/SeaportOrderParser.sol

View check run for this annotation

Codecov / codecov/patch

contracts/extension/SeaportOrderParser.sol#L258

Added line #L258 was not covered by tests
"OfferItem("
"uint8 itemType,"
"address token,"
"uint256 identifierOrCriteria,"
"uint256 startAmount,"
"uint256 endAmount"
")"
"OfferItem(" "uint8 itemType," "address token," "uint256 identifierOrCriteria," "uint256 startAmount,"
"uint256 endAmount" ")"
);

// Construct the ConsiderationItem type string.
bytes memory considerationItemTypeString = bytes(

Check warning on line 264 in contracts/extension/SeaportOrderParser.sol

View check run for this annotation

Codecov / codecov/patch

contracts/extension/SeaportOrderParser.sol#L264

Added line #L264 was not covered by tests
"ConsiderationItem("
"uint8 itemType,"
"address token,"
"uint256 identifierOrCriteria,"
"uint256 startAmount,"
"uint256 endAmount,"
"address recipient"
")"
"ConsiderationItem(" "uint8 itemType," "address token," "uint256 identifierOrCriteria,"
"uint256 startAmount," "uint256 endAmount," "address recipient" ")"
);

// Construct the OrderComponents type string, not including the above.
bytes memory orderComponentsPartialTypeString = bytes(

Check warning on line 270 in contracts/extension/SeaportOrderParser.sol

View check run for this annotation

Codecov / codecov/patch

contracts/extension/SeaportOrderParser.sol#L270

Added line #L270 was not covered by tests
"OrderComponents("
"address offerer,"
"address zone,"
"OfferItem[] offer,"
"ConsiderationItem[] consideration,"
"uint8 orderType,"
"uint256 startTime,"
"uint256 endTime,"
"bytes32 zoneHash,"
"uint256 salt,"
"bytes32 conduitKey,"
"uint256 counter"
")"
"OrderComponents(" "address offerer," "address zone," "OfferItem[] offer,"
"ConsiderationItem[] consideration," "uint8 orderType," "uint256 startTime," "uint256 endTime,"
"bytes32 zoneHash," "uint256 salt," "bytes32 conduitKey," "uint256 counter" ")"
);

// Construct the primary EIP-712 domain type string.
eip712DomainTypehash = keccak256(

Check warning on line 277 in contracts/extension/SeaportOrderParser.sol

View check run for this annotation

Codecov / codecov/patch

contracts/extension/SeaportOrderParser.sol#L277

Added line #L277 was not covered by tests
bytes(
"EIP712Domain("
"string name,"
"string version,"
"uint256 chainId,"
"address verifyingContract"
")"
)
bytes("EIP712Domain(" "string name," "string version," "uint256 chainId," "address verifyingContract" ")")
);

// Derive the OfferItem type hash using the corresponding type string.
Expand All @@ -279,20 +284,18 @@ contract SeaportOrderParser {
// Derive ConsiderationItem type hash using corresponding type string.
considerationItemTypehash = keccak256(considerationItemTypeString);

Check warning on line 285 in contracts/extension/SeaportOrderParser.sol

View check run for this annotation

Codecov / codecov/patch

contracts/extension/SeaportOrderParser.sol#L285

Added line #L285 was not covered by tests

bytes memory orderTypeString = bytes.concat(
orderComponentsPartialTypeString,
considerationItemTypeString,
offerItemTypeString
);
bytes memory orderTypeString =
bytes.concat(orderComponentsPartialTypeString, considerationItemTypeString, offerItemTypeString);

Check warning on line 288 in contracts/extension/SeaportOrderParser.sol

View check run for this annotation

Codecov / codecov/patch

contracts/extension/SeaportOrderParser.sol#L287-L288

Added lines #L287 - L288 were not covered by tests

// Derive OrderItem type hash via combination of relevant type strings.
orderTypehash = keccak256(orderTypeString);

Check warning on line 291 in contracts/extension/SeaportOrderParser.sol

View check run for this annotation

Codecov / codecov/patch

contracts/extension/SeaportOrderParser.sol#L291

Added line #L291 was not covered by tests
}

function _computeBulkOrderProof(
bytes memory proofAndSignature,
bytes32 leaf
) internal pure returns (bytes32 bulkOrderHash) {
function _computeBulkOrderProof(bytes memory proofAndSignature, bytes32 leaf)
internal
pure
returns (bytes32 bulkOrderHash)
{
// Declare arguments for the root hash and the height of the proof.
bytes32 root;
uint256 height;

Check warning on line 301 in contracts/extension/SeaportOrderParser.sol

View check run for this annotation

Codecov / codecov/patch

contracts/extension/SeaportOrderParser.sol#L300-L301

Added lines #L300 - L301 were not covered by tests
Expand All @@ -304,7 +307,7 @@ contract SeaportOrderParser {

// If proofAndSignature has odd length, it is a compact signature
// with 64 bytes.
let signatureLength := sub(ECDSA_MaxLength, and(fullLength, 1))
let signatureLength := sub(ECDSA_MAXLENGTH, and(fullLength, 1))

// Derive height (or depth of tree) with signature and proof length.
height := shr(OneWordShift, sub(fullLength, signatureLength))

Check warning on line 313 in contracts/extension/SeaportOrderParser.sol

View check run for this annotation

Codecov / codecov/patch

contracts/extension/SeaportOrderParser.sol#L313

Added line #L313 was not covered by tests
Expand All @@ -328,11 +331,7 @@ contract SeaportOrderParser {
mstore(xor(scratchPtr1, OneWord), mload(proof))

// Compute remaining proofs.
for {
let i := 1
} lt(i, height) {
i := add(i, 1)
} {
for { let i := 1 } lt(i, height) { i := add(i, 1) } {
proof := add(proof, OneWord)
let scratchPtr := shl(OneWordShift, and(shr(i, key), 1))
mstore(scratchPtr, keccak256(0, TwoWords))
Expand Down Expand Up @@ -367,22 +366,16 @@ contract SeaportOrderParser {
// Handle tree heights one and two.
if lt(treeHeight, 3) {
// Utilize branchless logic to determine typehash.
typeHash := ternary(
eq(treeHeight, 1),
BulkOrder_Typehash_Height_One,
BulkOrder_Typehash_Height_Two
)
typeHash :=
ternary(eq(treeHeight, 1), BulkOrder_Typehash_Height_One, BulkOrder_Typehash_Height_Two)

// Exit the function once typehash has been located.
leave
}

// Handle height three and four via branchless logic.
typeHash := ternary(
eq(treeHeight, 3),
BulkOrder_Typehash_Height_Three,
BulkOrder_Typehash_Height_Four
)
typeHash :=
ternary(eq(treeHeight, 3), BulkOrder_Typehash_Height_Three, BulkOrder_Typehash_Height_Four)

// Exit the function once typehash has been located.
leave
Expand All @@ -391,22 +384,16 @@ contract SeaportOrderParser {
// Handle tree height five and six.
if lt(treeHeight, 7) {
// Utilize branchless logic to determine typehash.
typeHash := ternary(
eq(treeHeight, 5),
BulkOrder_Typehash_Height_Five,
BulkOrder_Typehash_Height_Six
)
typeHash :=
ternary(eq(treeHeight, 5), BulkOrder_Typehash_Height_Five, BulkOrder_Typehash_Height_Six)

// Exit the function once typehash has been located.
leave
}

// Handle height seven and eight via branchless logic.
typeHash := ternary(
eq(treeHeight, 7),
BulkOrder_Typehash_Height_Seven,
BulkOrder_Typehash_Height_Eight
)
typeHash :=
ternary(eq(treeHeight, 7), BulkOrder_Typehash_Height_Seven, BulkOrder_Typehash_Height_Eight)

// Exit the function once typehash has been located.
leave
Expand All @@ -419,22 +406,16 @@ contract SeaportOrderParser {
// Handle tree height nine and ten.
if lt(treeHeight, 11) {
// Utilize branchless logic to determine typehash.
typeHash := ternary(
eq(treeHeight, 9),
BulkOrder_Typehash_Height_Nine,
BulkOrder_Typehash_Height_Ten
)
typeHash :=
ternary(eq(treeHeight, 9), BulkOrder_Typehash_Height_Nine, BulkOrder_Typehash_Height_Ten)

// Exit the function once typehash has been located.
leave
}

// Handle height eleven and twelve via branchless logic.
typeHash := ternary(
eq(treeHeight, 11),
BulkOrder_Typehash_Height_Eleven,
BulkOrder_Typehash_Height_Twelve
)
typeHash :=
ternary(eq(treeHeight, 11), BulkOrder_Typehash_Height_Eleven, BulkOrder_Typehash_Height_Twelve)

// Exit the function once typehash has been located.
leave
Expand All @@ -443,21 +424,17 @@ contract SeaportOrderParser {
// Handle tree height thirteen and fourteen.
if lt(treeHeight, 15) {
// Utilize branchless logic to determine typehash.
typeHash := ternary(
eq(treeHeight, 13),
BulkOrder_Typehash_Height_Thirteen,
BulkOrder_Typehash_Height_Fourteen
)
typeHash :=
ternary(
eq(treeHeight, 13), BulkOrder_Typehash_Height_Thirteen, BulkOrder_Typehash_Height_Fourteen
)

// Exit the function once typehash has been located.
leave
}
// Handle height fifteen and sixteen via branchless logic.
typeHash := ternary(
eq(treeHeight, 15),
BulkOrder_Typehash_Height_Fifteen,
BulkOrder_Typehash_Height_Sixteen
)
typeHash :=
ternary(eq(treeHeight, 15), BulkOrder_Typehash_Height_Fifteen, BulkOrder_Typehash_Height_Sixteen)

// Exit the function once typehash has been located.
leave
Expand All @@ -468,22 +445,18 @@ contract SeaportOrderParser {
// Handle tree height seventeen and eighteen.
if lt(treeHeight, 19) {
// Utilize branchless logic to determine typehash.
typeHash := ternary(
eq(treeHeight, 17),
BulkOrder_Typehash_Height_Seventeen,
BulkOrder_Typehash_Height_Eighteen
)
typeHash :=
ternary(
eq(treeHeight, 17), BulkOrder_Typehash_Height_Seventeen, BulkOrder_Typehash_Height_Eighteen
)

// Exit the function once typehash has been located.
leave
}

// Handle height nineteen and twenty via branchless logic.
typeHash := ternary(
eq(treeHeight, 19),
BulkOrder_Typehash_Height_Nineteen,
BulkOrder_Typehash_Height_Twenty
)
typeHash :=
ternary(eq(treeHeight, 19), BulkOrder_Typehash_Height_Nineteen, BulkOrder_Typehash_Height_Twenty)

// Exit the function once typehash has been located.
leave
Expand All @@ -492,22 +465,18 @@ contract SeaportOrderParser {
// Handle tree height twenty-one and twenty-two.
if lt(treeHeight, 23) {
// Utilize branchless logic to determine typehash.
typeHash := ternary(
eq(treeHeight, 21),
BulkOrder_Typehash_Height_TwentyOne,
BulkOrder_Typehash_Height_TwentyTwo
)
typeHash :=
ternary(
eq(treeHeight, 21), BulkOrder_Typehash_Height_TwentyOne, BulkOrder_Typehash_Height_TwentyTwo
)

// Exit the function once typehash has been located.
leave
}

// Handle height twenty-three & twenty-four w/ branchless logic.
typeHash := ternary(
eq(treeHeight, 23),
BulkOrder_Typehash_Height_TwentyThree,
BulkOrder_Typehash_Height_TwentyFour
)
typeHash :=
ternary(eq(treeHeight, 23), BulkOrder_Typehash_Height_TwentyThree, BulkOrder_Typehash_Height_TwentyFour)

// Exit the function once typehash has been located.
leave
Expand Down

0 comments on commit 85b889b

Please sign in to comment.