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

Packet data unmarshaling doesn't error when there is an unknown field #6215

Closed
3 tasks
srdtrk opened this issue Apr 23, 2024 · 3 comments
Closed
3 tasks

Packet data unmarshaling doesn't error when there is an unknown field #6215

srdtrk opened this issue Apr 23, 2024 · 3 comments
Assignees
Labels
20-transfer type: bug Something isn't working as expected
Milestone

Comments

@srdtrk
Copy link
Member

srdtrk commented Apr 23, 2024

Summary of Bug

Whether or not this is a bug needs discussion. A recently made commit (#5778) has the unintended consequence of allowing unknown fields in transfer packet data.

Description

In #5778, we have removed ModuleCdc in favor of encoding/json. (This PR hasn't made its way to any releases yet). The module codec used protojson to decode the packet data which has the default behavior of returning an error if it sees an unknown field. However, encoding/json ignores the unknown fields and proceeds with deserialization.

Expected Behavior

Consider the following transfer packet data:

{
  "denom": "denom",
  "amount": "100",
  "sender": "%s",
  "receiver": "%s",
  "memo": "memo",
  "new_field": "value"
}

This cannot be deserialized in release versions of ibc-go. But can be deserialized in main.

Version

Only main. This hasn't made its way back to any releases yet.

Steps to Reproduce

See the tests I wrote here


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged/assigned
@srdtrk srdtrk added 20-transfer needs discussion Issues that need discussion before they can be worked on labels Apr 23, 2024
@srdtrk srdtrk changed the title Packet data unmarshaling doesn't error even if there is an unknown field Packet data unmarshaling doesn't error when there is an unknown field Apr 23, 2024
@colin-axner colin-axner added the type: bug Something isn't working as expected label Apr 24, 2024
@colin-axner
Copy link
Contributor

Oh my, nice find! Tagging bug, as allowing unmarshaling of unknown fields sounds problematic. We often make use of new fields to introduce new features. If I send a packet to chain X using a new field it doesn't understand (memo for example), I'd expect it to fail, not succeed ignoring my addition input

I suppose there's no easy way to error on unknown fields with std json lib?

@srdtrk
Copy link
Member Author

srdtrk commented Apr 24, 2024

We can override the unmarshaling behaviour of encoding/json for FungibleTokenPacketData by implementing json.Unmarshaler on it. We would write our custom UnmarshalJSON function. Wouldn't be too difficult

@crodriguezvega crodriguezvega added this to the v9.0.0 milestone May 6, 2024
@colin-axner
Copy link
Contributor

We have decided to implement the json.Unmarshaler with our custom function. If anything goes awry we can fallback to protojson for the time being (so as not to block v9 release)

@colin-axner colin-axner removed the needs discussion Issues that need discussion before they can be worked on label May 20, 2024
@colin-axner colin-axner moved this to Todo 🏃 in ibc-go May 20, 2024
@DimitrisJim DimitrisJim moved this from Todo 🏃 to In progress 👷 in ibc-go May 30, 2024
@DimitrisJim DimitrisJim moved this from In progress 👷 to In review 👀 in ibc-go May 30, 2024
@github-project-automation github-project-automation bot moved this from In review 👀 to Done 🥳 in ibc-go May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
20-transfer type: bug Something isn't working as expected
Projects
Archived in project
Development

No branches or pull requests

4 participants