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: generate domain separator per 712 spec #23

Merged
merged 4 commits into from
Jan 8, 2024
Merged

Conversation

moldy530
Copy link
Collaborator

@moldy530 moldy530 commented Dec 13, 2023

Motivation

I was testing adding the correct 1271 signature verification in aa-sdk and couldn't generate matching signatures. After diving into it a little bit, the reason was the viem was generating the domainSeparator part of the 712 hash differently than LightAccount was. This is because LightAccount used abi.encode for the name and version fields, but it should actually be the keccak hash result of those fields.

Domain Separator Spec: https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator
Defintion of encodeData which calls out keccak256(bytes(string)): https://eips.ethereum.org/EIPS/eip-712#definition-of-encodedata

Solution

Update the generation of the domainSeparator to match what client do naturally. This is the same thing that MSCA does as well.

Copy link
Collaborator

@howydev howydev left a comment

Choose a reason for hiding this comment

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

good catch, LGTM

Copy link
Collaborator

@jaypaik jaypaik left a comment

Choose a reason for hiding this comment

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

Assuming we'll be updating the script (factory address and salt) in a subsequent PR.

Also, thoughts on using getMessageHash within isValidSignature?

Comment on lines 65 to 67
bytes32 private constant _LA_MSG_TYPEHASH = 0x5e3baca2936049843f06038876a12f03627b5edc98025751ecf2ac7562640199;
bytes32 private constant _NAME_HASH = keccak256(bytes("LightAccount"));
bytes32 private constant _VERSION_HASH = keccak256(bytes("1"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: keccak256(bytes("foo")) yields the same result as keccak256("foo") and our comments above omit the bytes wrapper. But the ERC and OZ implementations follow this pattern so I think it's fine to keep it this way too.

Also, might be good to have consistent usage between precomputed values vs. inline expressions. It seems we can assign the commented expressions to _DOMAIN_SEPARATOR_TYPEHASH and _LA_MSG_TYPEHASH (they won't get recomputed at runtime). It actually might save gas on deployment too (double check me on this).

| lib/account-abstraction/contracts/core/EntryPoint.sol:EntryPoint contract | | | | | |
|---------------------------------------------------------------------------|-----------------|--------|--------|--------|---------|
| Deployment Cost | Deployment Size | | | | |
| 4128022 | 20516 | | | | |
| 4781904 | 23781 | | | | |
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you know why these numbers increased?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm not sure. That dependency hasn't changed since this file was last generated.

@@ -26,7 +26,7 @@ contract Deploy_LightAccountFactory is Script {
abi.encodePacked(type(LightAccountFactory).creationCode, bytes32(uint256(uint160(address(entryPoint)))))
);

if (initCodeHash != 0x2ad62a8bb3850247ef0c4f04e30b584e6eee7caa0e063745e90956653b90eb84) {
if (initCodeHash != 0xd77df77274118ffc7c7b2edced505093b1f8695e3b5ced2b2fd2a5b27e4e2b78) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I must be missing sth here. If entrypoint and factory code don't change, how come the hash is different?

Copy link
Collaborator

Choose a reason for hiding this comment

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

There was a change to the formatting of the factory code (which changes the hash of the source file), and since the metadata hash is a part of the bytecode, the init code hash changes even without a logical code change.

But also the LightAccount bytecode is included (and that changed) since LightAccountFactory imports and uses it.

@jaypaik jaypaik merged commit 7cb2ff1 into main Jan 8, 2024
2 checks passed
@jaypaik jaypaik deleted the moldy/test-LA-sdk branch January 8, 2024 20:41
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.

5 participants