-
Notifications
You must be signed in to change notification settings - Fork 834
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: add EIP712 support for multiple messages and schemas #1390
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #1390 +/- ##
==========================================
+ Coverage 72.31% 72.70% +0.38%
==========================================
Files 260 265 +5
Lines 17732 18206 +474
==========================================
+ Hits 12823 13236 +413
- Misses 4337 4380 +43
- Partials 572 590 +18
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @austinchandra !! Left a few comments and a question
ENG-1490 Re-open EIP-712 support for multiple messages on Evmos
Was originally open on Ethermint, reopen on Evmos. |
Pull request was converted to draft
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Great work @austinchandra !! There are some lint errors related to constants using all capital letters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK with minor comments. Great work @austinchandra
Description
Reopens the original PR from Ethermint: evmos/ethermint#1593
In addition to the changes listed in the original PR:
eip712.go
intoeip712/types.go
,eip712/message.go
,eip712/domain.go
, andeip712/eip712.go
for better modularity and code-clarity.feePayer
as it's no longer necessary.Closes ENG-1490
Refactor the EIP-712
Types
andTypedData
generation algorithm to provide more flexibility in type-generation and signing.Reference
https://www.notion.so/evmos/EIP-712-Refactor-Different-Types-of-Messages-1ae3ddf5bc66428997722634f091d346
Motivation
The current EIP-712
TypedData
generation algorithm groups all messages into one array. Due to the way EIP-712's typing system is defined, all items in an array must share the same schema. This means that Cosmos payloads with different types of messages, or messages with the same type of schema, cannot be signed using the current algorithm.When it comes to users and developers, this issue limits Ledger and Metamask users in terms of their overall capabilities, since they cannot sign certain payloads—the same applies to developers aiming to provide certain functionality to users.
Implementation
Fundamentally, this refactor changes the EIP-712 algorithm from using the
sdk.Msg
Go object to generate types to using the payload message in JSON to generate types.In the process, we flatten the JSON payload messages, converting them from an array of JSON objects to numbered
field: value
pairs. This allows us to define a custom schema for each message when necessary, to support multiple types of messages.This change also fixes a bug with omitted optional values—we currently check if a given field has value of zero, and exclude it if so, which has the unintended side-effect of removing all zero values that are present. When we use the JSON payload to generate types instead, we automatically exclude values that are missing.
Outcomes
Support messages of different types & schemas
The current implementation groups all payload messages into an array when building the EIP-712 object. Since EIP-712 arrays are strongly typed, this has the side-effect of enforcing all messages to share a single schema. With this change, we can begin to support different messages and different schemas within a single transaction.
Fix bug with omitted values
The current EIP-712 implementation omits values from type generation if they are equal to zero, in order to filter omitted values in the payload when building the types. This creates false negatives, in which values that are included but equal to zero are also filtered, such as
false
boolean values or numerical values equal to zero.Legacy Support
The previous implementation is kept in the codebase as
eip712_legacy.go
andencoding_legacy.go
, in order to supports backwards-compatibility with existing products and integrations. This provides Evmos developers a chance to migrate to the new implementation (or a new version of EvmosJS) before we completely remove support for the legacy encoding.Tests
ethereum/eip712/eip712_fuzzer_test.go
)app/ante_test.go
)ethereum/eip712/eip712_test.go
)