Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 712 ordering for Priority Orders #258

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1 @@
183901
183646
Original file line number Diff line number Diff line change
@@ -1 +1 @@
201149
200635
Original file line number Diff line number Diff line change
@@ -1 +1 @@
210963
210447
Original file line number Diff line number Diff line change
@@ -1 +1 @@
264672
264156
Original file line number Diff line number Diff line change
@@ -1 +1 @@
194682
194161
Original file line number Diff line number Diff line change
@@ -1 +1 @@
150292
150036
Original file line number Diff line number Diff line change
@@ -1 +1 @@
135854
135599
Original file line number Diff line number Diff line change
@@ -1 +1 @@
159602
159347
44 changes: 32 additions & 12 deletions src/lib/PriorityOrderLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,54 @@ struct PriorityOrder {
library PriorityOrderLib {
using OrderInfoLib for OrderInfo;

bytes private constant PRIORITY_INPUT_TOKEN_TYPE =
bytes internal constant PRIORITY_INPUT_TOKEN_TYPE =
"PriorityInput(address token,uint256 amount,uint256 mpsPerPriorityFeeWei)";

bytes32 private constant PRIORITY_INPUT_TOKEN_TYPE_HASH = keccak256(PRIORITY_INPUT_TOKEN_TYPE);
bytes32 internal constant PRIORITY_INPUT_TOKEN_TYPE_HASH = keccak256(PRIORITY_INPUT_TOKEN_TYPE);

bytes private constant PRIORITY_OUTPUT_TOKEN_TYPE =
bytes internal constant PRIORITY_OUTPUT_TOKEN_TYPE =
"PriorityOutput(address token,uint256 amount,uint256 mpsPerPriorityFeeWei,address recipient)";

bytes32 private constant PRIORITY_OUTPUT_TOKEN_TYPE_HASH = keccak256(PRIORITY_OUTPUT_TOKEN_TYPE);
bytes32 internal constant PRIORITY_OUTPUT_TOKEN_TYPE_HASH = keccak256(PRIORITY_OUTPUT_TOKEN_TYPE);

string internal constant TOKEN_PERMISSIONS_TYPE = "TokenPermissions(address token,uint256 amount)";

// EIP712 notes that nested structs should be ordered alphabetically.
// With our added PriorityOrder witness, the top level type becomes
// "PermitWitnessTransferFrom(TokenPermissions permitted,address spender,uint256 nonce,uint256 deadline,PriorityOrder witness)"
// Meaning we order the nested structs as follows:
// OrderInfo, PriorityInput, PriorityOrder, PriorityOutput
string internal constant PERMIT2_ORDER_TYPE = string(
abi.encodePacked(
"PriorityOrder witness)",
OrderInfoLib.ORDER_INFO_TYPE,
PriorityOrderLib.PRIORITY_INPUT_TOKEN_TYPE,
PriorityOrderLib.TOPLEVEL_PRIORITY_ORDER_TYPE,
PriorityOrderLib.PRIORITY_OUTPUT_TOKEN_TYPE,
TOKEN_PERMISSIONS_TYPE
)
);

bytes internal constant ORDER_TYPE = abi.encodePacked(
bytes internal constant TOPLEVEL_PRIORITY_ORDER_TYPE = abi.encodePacked(
"PriorityOrder(",
"OrderInfo info,",
"address cosigner,",
"uint256 auctionStartBlock,",
"uint256 baselinePriorityFeeWei,",
"PriorityInput input,",
"PriorityOutput[] outputs)",
"PriorityOutput[] outputs)"
);

// EIP712 notes that nested structs should be ordered alphabetically:
// OrderInfo, PriorityInput, PriorityOutput
bytes internal constant ORDER_TYPE = abi.encodePacked(
PriorityOrderLib.TOPLEVEL_PRIORITY_ORDER_TYPE,
OrderInfoLib.ORDER_INFO_TYPE,
PRIORITY_INPUT_TOKEN_TYPE,
PRIORITY_OUTPUT_TOKEN_TYPE
PriorityOrderLib.PRIORITY_INPUT_TOKEN_TYPE,
PriorityOrderLib.PRIORITY_OUTPUT_TOKEN_TYPE
);
bytes32 internal constant ORDER_TYPE_HASH = keccak256(ORDER_TYPE);

string private constant TOKEN_PERMISSIONS_TYPE = "TokenPermissions(address token,uint256 amount)";
string internal constant PERMIT2_ORDER_TYPE =
string(abi.encodePacked("PriorityOrder witness)", ORDER_TYPE, TOKEN_PERMISSIONS_TYPE));

/// @notice returns the hash of an input token struct
function hash(PriorityInput memory input) private pure returns (bytes32) {
return
Expand Down
Loading