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

3 level Michelson structure missing elements when transformed to JS in for PairToken #2540

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

3 level Michelson structure missing elements when transformed to JS in for PairToken #2540

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

Comments

@Innkst
Copy link
Contributor

Innkst commented Jun 22, 2023

Description
The transformation from JSON encoded Micheline value into JS representation skips flattens 3 level schema into 2 levels and skips an element.

Steps To Reproduce
This bug manifests when we have three-levels of pair nesting:

  • Pair1
    • Pair2
      • Pair3
        • Int
        • Int
        • %A
      • Int
    • bool

Pair1, Pair2, Pair3 return PairToken.Execute Object1, Object2, Object3 results respectively.
Pair2 knows that Pair3 is annotated with “A3'' and Pair2.Execute returns Object2, a JS object with a nested JS object accessed via the A3 key. However, Pair2 erroneously establishes an idx value to its rightValue as if both Object3 keys are visible at the Object2 level (i.e., an idx=2). When Pairing1 retrieves a Pairing2 result it correctly establishes an idx value for its rightValue based on the number of keys contained in Object 2 (once again, an idx=2). As a result, the rightValue.Execute result for Pair1 may contribute a value for the “2” key which overwrites a “2” key value contributed by Pair2.

Expected behavior
Micheline pairs correspond to a kind of record structure. As such they are mapped to JavaScript (JS) objects. In the case where an unannotated pair is referenced by a parent pair, the nesting is abstracted away in the mapping of a Micheline Pair to a JS object. In the case where an annotated pair is referenced by a parent pair, the nesting is preserved in the mapping of a Micheline Pair to a JS object; a new JS object is nested in the parent object with the Micheline pair annotation serving as the parent object key.

Pseudo code for PairToken.Execute( val, idx)

keyCount = 1;
typ1.idx = idx;

If typ1 is a PairToken with no annotations then    	% abstract away unannotated pair nesting
 	leftValue = typ1.Execute(val1);                      
 	keyCount= Object.keys(leftValue).length;	% count leftValue keys
else
 	leftValue = {[typ1.annot()]: typ1.Execute(val1)};    % wrap leftValue with its annotation
endif;

typ2.idx = idx + keyCount;
If typ2 is a PairToken with no annotations then    	% abstract away unannotated pair nesting
 	rightValue = typ2.Execute(val2);   
else
 	rightValue = {[typ2.annot()]: typ2.Execute(val2)}; % wrap rightValue with its annotation
endif;
 
return { …leftValue, …rightValue};             	% merge left, right values into a single object

PairToken idx management ensures that mapped-to objects have their own default property namespace. This corresponds naturally with the notion of object property namespaces in JS.

Additional context
A coding experiment was conducted to illustrate this.

For a JSON encoded Micheline schema,

{prim: "pair", args: [{prim: "pair", args: [{prim: "pair", 
    args: [{prim: "int"}, {prim: "int"}],annots: ["%A3"]}, 
    {prim: "int"}]}, {prim: "bool"}]}

We constructed the JSON encoded Micheline value,

const MichelsonValue = { prim: "Pair", args:[{prim: "Pair",
    args: [{prim: "Pair",args: [{int: "11"},{int: "22"}]},
    {int: "33"}]}, {prim: "True"}]};

And obtained a result for
const JSValue = storageSchema.Execute(MichelsonValue);

namely:

{
  "2": true,
  "A3": {
    "0": "11",
    "1": "22"
  }
}

Here we can see that the Boolean true value from the rightValue.Execute for Pair1 has contributed a value for the “2” key which has overwritten the “2” key value (“33”) contributed by Pair2.

The correct result is:

{
“1”: “33”,  
"2": true,
  "A3": {
    "0": "11",
    "1": "22"
  }
}

Request access to the google document when working on this issue from Inna

@Innkst Innkst added bug Something isn't working Michelson 🥸 Related to Michelson language and Taquito's handling of same labels Jun 22, 2023
@Innkst Innkst added this to the v17.2 milestone Jun 22, 2023
@Innkst Innkst changed the title 3 level Michelson structure missing elements when transformed to JS 3 level Michelson structure missing elements when transformed to JS (PairToken) Jun 22, 2023
@Innkst Innkst changed the title 3 level Michelson structure missing elements when transformed to JS (PairToken) 3 level Michelson structure missing elements when transformed to JS in for PairToken Jun 22, 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 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
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants