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

feat: hash orderinfo separately #135

Merged
merged 5 commits into from
Apr 26, 2023
Merged

feat: hash orderinfo separately #135

merged 5 commits into from
Apr 26, 2023

Conversation

marktoda
Copy link
Collaborator

Avoids stack too deep without bricking EIP712 and cleaner

"uint256 startTime,",
"uint256 endTime,",
"address inputToken,",
"uint256 inputStartAmount,",
"uint256 inputEndAmount,",
"DutchOutput[] outputs)",
DUTCH_OUTPUT_TYPE
DUTCH_OUTPUT_TYPE,
OrderInfoLib.ORDER_INFO_TYPE
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is Dutch before OrderInfo because of alphabetical?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah exactly


bytes internal constant ORDER_TYPE = abi.encodePacked(
bytes internal constant EXCLUSIVE_DUTCH_LIMIT_ORDER_TYPE = abi.encodePacked(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: inconsistency that sometimes you defined a TYPE constant just using a singular string, and sometimes you use encodePacked - even with this one that doesnt use any variables.
For readability you could use a multi-line encodePacked everywhere? Just a nit though, feel free to ignore

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea my general approach has been: if small, single line else multiline

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but will switch around for consistency

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually ehhh it looks pretty ugly for single liners

    bytes internal constant TOKEN_PERMISSIONS_TYPE =
        abi.encodePacked("TokenPermissions(", "address token", "uint256 amount)");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mm yeah i think single line fine to just keep w/o abi.encodePacked

@@ -42,25 +43,23 @@ struct DutchLimitOrder {

/// @notice helpers for handling dutch limit order objects
library DutchLimitOrderLib {
using OrderInfoLib for OrderInfo;

bytes internal constant DUTCH_OUTPUT_TYPE =
"DutchOutput(address token,uint256 startAmount,uint256 endAmount,address recipient,bool isFeeOutput)";
bytes32 internal constant DUTCH_OUTPUT_TYPE_HASH = keccak256(DUTCH_OUTPUT_TYPE);

bytes internal constant ORDER_TYPE = abi.encodePacked(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could be neat to separate this out like you do with EXCLUSIVE_DUTCH_LIMIT_ORDER_TYPE?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

truu

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strangely this changes gas even though its a constant?

hensha256
hensha256 previously approved these changes Apr 25, 2023
Copy link
Collaborator

@hensha256 hensha256 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of nits, but LGTM

snreynolds
snreynolds previously approved these changes Apr 25, 2023
Copy link
Member

@snreynolds snreynolds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only thing is that we should add some tests to make sure these match wallet standard

);

bytes internal constant ORDER_TYPE =
abi.encodePacked(DUTCH_LIMIT_ORDER_TYPE, DUTCH_OUTPUT_TYPE, OrderInfoLib.ORDER_INFO_TYPE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we leave a comment about it being important that we encode the types in alphabetical order.. feel like thats a nuanced bit in the 712 standard for nested types.


bytes internal constant ORDER_TYPE = abi.encodePacked(
bytes internal constant EXCLUSIVE_DUTCH_LIMIT_ORDER_TYPE = abi.encodePacked(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mm yeah i think single line fine to just keep w/o abi.encodePacked

@marktoda
Copy link
Collaborator Author

only thing is that we should add some tests to make sure these match wallet standard

how do you do that in foundry? without foundry-rs/foundry#4818

@snreynolds
Copy link
Member

only thing is that we should add some tests to make sure these match wallet standard

how do you do that in foundry? without foundry-rs/foundry#4818

Yeah I think can just make it a future todo, but we have some static/hardcoded tests in permit2 comparing signatures generated from mm.

@marktoda marktoda merged commit f2799c3 into main Apr 26, 2023
2 checks passed
willpote pushed a commit that referenced this pull request Jul 17, 2023
* feat: hash orderinfo separately

Avoids stack too deep without bricking EIP712 and cleaner

* fix: struct ordering

* fix: alice comments

* feat: add comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants