From a98281095310ba5d67242d89191d8e28e04f4943 Mon Sep 17 00:00:00 2001 From: Eric Zhong Date: Wed, 17 Jul 2024 09:52:27 -0400 Subject: [PATCH] Fix 712 ordering --- ...OrderReactor-BaseExecuteSingleWithFee.snap | 2 +- ...ase-PriorityOrderReactor-ExecuteBatch.snap | 2 +- ...erReactor-ExecuteBatchMultipleOutputs.snap | 2 +- ...teBatchMultipleOutputsDifferentTokens.snap | 2 +- ...OrderReactor-ExecuteBatchNativeOutput.snap | 2 +- ...se-PriorityOrderReactor-ExecuteSingle.snap | 2 +- ...rderReactor-ExecuteSingleNativeOutput.snap | 2 +- ...yOrderReactor-ExecuteSingleValidation.snap | 2 +- src/lib/PriorityOrderLib.sol | 44 ++++++++++++++----- 9 files changed, 40 insertions(+), 20 deletions(-) diff --git a/.forge-snapshots/Base-PriorityOrderReactor-BaseExecuteSingleWithFee.snap b/.forge-snapshots/Base-PriorityOrderReactor-BaseExecuteSingleWithFee.snap index b4fc22a8..7c191793 100644 --- a/.forge-snapshots/Base-PriorityOrderReactor-BaseExecuteSingleWithFee.snap +++ b/.forge-snapshots/Base-PriorityOrderReactor-BaseExecuteSingleWithFee.snap @@ -1 +1 @@ -183901 \ No newline at end of file +183646 \ No newline at end of file diff --git a/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatch.snap b/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatch.snap index 3a644767..875e2b29 100644 --- a/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatch.snap +++ b/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatch.snap @@ -1 +1 @@ -201149 \ No newline at end of file +200635 \ No newline at end of file diff --git a/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatchMultipleOutputs.snap b/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatchMultipleOutputs.snap index 916a9531..1a34d53f 100644 --- a/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatchMultipleOutputs.snap +++ b/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatchMultipleOutputs.snap @@ -1 +1 @@ -210963 \ No newline at end of file +210447 \ No newline at end of file diff --git a/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatchMultipleOutputsDifferentTokens.snap b/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatchMultipleOutputsDifferentTokens.snap index 68ec0255..6ca8ed50 100644 --- a/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatchMultipleOutputsDifferentTokens.snap +++ b/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatchMultipleOutputsDifferentTokens.snap @@ -1 +1 @@ -264672 \ No newline at end of file +264156 \ No newline at end of file diff --git a/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatchNativeOutput.snap b/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatchNativeOutput.snap index ed4edd63..a0f4fef7 100644 --- a/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatchNativeOutput.snap +++ b/.forge-snapshots/Base-PriorityOrderReactor-ExecuteBatchNativeOutput.snap @@ -1 +1 @@ -194682 \ No newline at end of file +194161 \ No newline at end of file diff --git a/.forge-snapshots/Base-PriorityOrderReactor-ExecuteSingle.snap b/.forge-snapshots/Base-PriorityOrderReactor-ExecuteSingle.snap index 51ab15ec..662f89ad 100644 --- a/.forge-snapshots/Base-PriorityOrderReactor-ExecuteSingle.snap +++ b/.forge-snapshots/Base-PriorityOrderReactor-ExecuteSingle.snap @@ -1 +1 @@ -150292 \ No newline at end of file +150036 \ No newline at end of file diff --git a/.forge-snapshots/Base-PriorityOrderReactor-ExecuteSingleNativeOutput.snap b/.forge-snapshots/Base-PriorityOrderReactor-ExecuteSingleNativeOutput.snap index ee3dbc15..89df184b 100644 --- a/.forge-snapshots/Base-PriorityOrderReactor-ExecuteSingleNativeOutput.snap +++ b/.forge-snapshots/Base-PriorityOrderReactor-ExecuteSingleNativeOutput.snap @@ -1 +1 @@ -135854 \ No newline at end of file +135599 \ No newline at end of file diff --git a/.forge-snapshots/Base-PriorityOrderReactor-ExecuteSingleValidation.snap b/.forge-snapshots/Base-PriorityOrderReactor-ExecuteSingleValidation.snap index bf3457f3..fa4c5af8 100644 --- a/.forge-snapshots/Base-PriorityOrderReactor-ExecuteSingleValidation.snap +++ b/.forge-snapshots/Base-PriorityOrderReactor-ExecuteSingleValidation.snap @@ -1 +1 @@ -159602 \ No newline at end of file +159347 \ No newline at end of file diff --git a/src/lib/PriorityOrderLib.sol b/src/lib/PriorityOrderLib.sol index 1997e8d0..8be8541d 100644 --- a/src/lib/PriorityOrderLib.sol +++ b/src/lib/PriorityOrderLib.sol @@ -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