Skip to content

stringify json for EIP 712 encoding - #1248

Open
codehans wants to merge 2 commits into
cosmos:mainfrom
codehans:eip712/json
Open

codehans wants to merge 2 commits into
cosmos:mainfrom
codehans:eip712/json

Conversation

@codehans

@codehans codehans commented Aug 4, 2026

Copy link
Copy Markdown

CosmWasm msg payloads are encoded as json objects in amino representation, which breaks EIP-712's strict typic requirements. This PR stringifies untyped JSON objects to make it compatible with EIP-712 signing

@codehans
codehans requested a review from a team as a code owner August 4, 2026 12:25
Comment on lines +58 to +65
// stringifyJSONMsgFields converts object- and array-valued "msg" fields to
// strings. Message fields conventionally contain opaque JSON (for example,
// CosmWasm contract messages), whose runtime shape cannot be represented by a
// stable EIP-712 type. Existing string values are left alone so ordinary
// string fields and already-stringified JSON are not changed.
//
// The conversion only affects the derived EIP-712 payload. The protobuf
// transaction still contains the original value used during execution.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AI description--please make it more concise.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Not sure whether to be offended or not 😅. This is all hand written

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry for offending, I should have explained more the particular thing I didn't like about the comment.

It's a bit verbose for an internal method comment that is doing regular json stringify. Also it specifically calls out CosmWasm contract messages as the thing it's solving for which is something that LLMs typically do when making small changes on behalf of a specific prompt.

On second read I think it's mostly fine, but I would still like to drop the CosmWasm callout.

@Eric-Warehime

Copy link
Copy Markdown
Contributor

@greptile review

@greptile-apps

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes object- and array-valued msg fields EIP-712-compatible by representing their opaque JSON as strings before deriving the typed-data schema.

  • Recursively transforms structured msg fields while preserving ordinary strings and unrelated typed objects.
  • Adds tests for CosmWasm payloads, nested authz messages, array payloads, existing strings, and typed sibling objects.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking issue identified.

The transformation is confined to the derived EIP-712 payload, preserves opaque JSON content as a string, and is applied consistently when typed data is reconstructed for verification.

Important Files Changed

Filename Overview
ethereum/eip712/message.go Adds recursive preprocessing that stringifies structured msg values before flattening and EIP-712 schema derivation; no actionable defect was established.
ethereum/eip712/message_test.go Adds focused coverage for object, array, nested, pre-stringified, ordinary string, and unrelated typed-object behavior.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Amino JSON SignDoc] --> B[Parse JSON payload]
  B --> C[Recursively locate structured msg fields]
  C --> D[Stringify opaque JSON values]
  D --> E[Flatten heterogeneous msgs array]
  E --> F[Derive EIP-712 types and message]
  F --> G[Wallet signs typed data]
  G --> H[Verifier reconstructs identical typed data]
Loading

Reviews (1): Last reviewed commit: "Merge branch 'main' into eip712/json" | Re-trigger Greptile

@Eric-Warehime

Copy link
Copy Markdown
Contributor

Seems good to merge when you update the comment.

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.45%. Comparing base (430eaed) to head (be0ce91).

Files with missing lines Patch % Lines
ethereum/eip712/message.go 75.00% 4 Missing and 4 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1248      +/-   ##
==========================================
+ Coverage   67.44%   67.45%   +0.01%     
==========================================
  Files         320      320              
  Lines       23456    23488      +32     
==========================================
+ Hits        15819    15843      +24     
- Misses       6456     6460       +4     
- Partials     1181     1185       +4     
Files with missing lines Coverage Δ
ethereum/eip712/message.go 81.44% <75.00%> (-3.18%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines +58 to +65
// stringifyJSONMsgFields converts object- and array-valued "msg" fields to
// strings. Message fields conventionally contain opaque JSON (for example,
// CosmWasm contract messages), whose runtime shape cannot be represented by a
// stable EIP-712 type. Existing string values are left alone so ordinary
// string fields and already-stringified JSON are not changed.
//
// The conversion only affects the derived EIP-712 payload. The protobuf
// transaction still contains the original value used during execution.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry for offending, I should have explained more the particular thing I didn't like about the comment.

It's a bit verbose for an internal method comment that is doing regular json stringify. Also it specifically calls out CosmWasm contract messages as the thing it's solving for which is something that LLMs typically do when making small changes on behalf of a specific prompt.

On second read I think it's mostly fine, but I would still like to drop the CosmWasm callout.

Comment on lines +58 to +62
// stringifyJSONMsgFields converts object- and array-valued "msg" fields to
// strings. Message fields conventionally contain opaque JSON (for example,
// CosmWasm contract messages), whose runtime shape cannot be represented by a
// stable EIP-712 type. Existing string values are left alone so ordinary
// string fields and already-stringified JSON are not changed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// stringifyJSONMsgFields converts object- and array-valued "msg" fields to
// strings. Message fields conventionally contain opaque JSON (for example,
// CosmWasm contract messages), whose runtime shape cannot be represented by a
// stable EIP-712 type. Existing string values are left alone so ordinary
// string fields and already-stringified JSON are not changed.
// stringifyJSONMsgFields converts object- and array-valued "msg" fields to
// strings. Message fields conventionally contain opaque JSON
// whose runtime shape cannot be represented by a stable EIP-712 type.
// Existing string values are left alone so ordinary
// string fields and already-stringified JSON are not changed.

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.

2 participants