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

Encode accepts non-conformant JS Values for OrToken #2544

Closed
Innkst opened this issue Jun 22, 2023 · 0 comments · Fixed by #2611
Closed

Encode accepts non-conformant JS Values for OrToken #2544

Innkst opened this issue Jun 22, 2023 · 0 comments · Fixed by #2611
Assignees
Labels
bug Something isn't working Michelson 🥸 Related to Michelson language and Taquito's handling of same Michelson-encoder ux/dx Related to Developer Experience
Milestone

Comments

@Innkst
Copy link
Contributor

Innkst commented Jun 22, 2023

Description
In the spirit of enforcing type checking on the JS side that is equivalent to that on the Micheline side, OrToken.Encode(val) should only accept an object with a single key, one that corresponds to a Micheline Left-Right position, and one whose type is consistent with the Micheline type found in that Left-Right position of the root OrToken.

The current OrToken.Encode(val) accepts objects with multiple keys. It traverses the root OrToken looking for non-or Token with a matching key. Processing terminates with the first one found. This allows a developer to erroneously conclude that they have successfully encoded a JS object with multiple keys, as an equivalent JSON encoded Micheline value. In the spirit of tight type checking any attempt to OrToken.Encode a val with more than one key should fail.

Steps To Reproduce
Consider the following:

Or1
   Or2
      int
      string
      %A
   Bool

Or1.Execute(val) maps conformant JSON-encoded Micheline values to a flat object with a single key.

Left (Left 5) maps to {“0”: 5}
Left (Right “foo”) maps to {“1”: “foo”}
Right True maps to {“2”: true}

However, Or1.Encode( {“0”: 5, “1”: “foo”, “2”: true}) returns a JSON-encoded value for:
Left (Left 5). The other key-value pairs of are simply ignored. A correct result would be for the Encode to raise an invalid-type error.

Expected behavior
Add logic to OrToken.Encode(val) to ensure that any attempt to encode a val with more than one key fails.

Additional context
Refer to AS-IS OrToken document

@Innkst Innkst added bug Something isn't working Michelson 🥸 Related to Michelson language and Taquito's handling of same Michelson-encoder labels Jun 22, 2023
@Innkst Innkst added this to the v17.2 milestone Jun 22, 2023
@Innkst Innkst added the ux/dx Related to Developer Experience label Jun 23, 2023
@Innkst Innkst modified the milestones: v17.2, v17.3 Jul 13, 2023
@Innkst Innkst modified the milestones: v17.2, v17.3 Aug 1, 2023
@ac10n ac10n self-assigned this Aug 16, 2023
@ac10n ac10n mentioned this issue Aug 24, 2023
9 tasks
@ac10n ac10n moved this to Done in Taquito Dev Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Michelson 🥸 Related to Michelson language and Taquito's handling of same Michelson-encoder ux/dx Related to Developer Experience
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants