neo-go icon indicating copy to clipboard operation
neo-go copied to clipboard

packmap operation keeps duplicate entries

Open Slava0135 opened this issue 1 year ago • 2 comments

Current Behavior

packmap keeps duplicate keys (and entries) behavior might be considered undefined, though its probably better to copy C# implementation

image

[
  {
    "type": "Map",
    "value": [
      {
        "key": {
          "type": "Integer",
          "value": "1"
        },
        "value": {
          "type": "Integer",
          "value": "1"
        }
      },
      {
        "key": {
          "type": "Integer",
          "value": "1"
        },
        "value": {
          "type": "Integer",
          "value": "1"
        }
      }
    ]
  }
]

Expected Behavior

C# results:

[
  {
    "type": "Map",
    "value": [
      {
        "key": {
          "type": "Integer",
          "value": "1"
        },
        "value": {
          "type": "Integer",
          "value": "1"
        }
      }
    ]
  }
]

Possible Solution

Steps to Reproduce

  1. ./bin/neo-go vm
  2. loadbase64 ERERERK+
  3. run

Your Environment

  • Version of the product used: master (a9242535db757faba860e21c194033f30c679f48)

Slava0135 avatar Oct 14 '24 09:10 Slava0135

Wow, a really unexpected bug! Sure, it should be aligned with C# implementation. They use an ordered dictionary for the internal Map item implementation, so the bug is legit. https://github.com/neo-project/neo/blob/3f2f78c1fcf71ea51f2c40c3a0e67062ac390aed/src/Neo.VM/JumpTable/JumpTable.Compound.cs#L45 https://github.com/neo-project/neo/blob/3f2f78c1fcf71ea51f2c40c3a0e67062ac390aed/src/Neo.VM/Types/Map.cs#L63

AnnaShaleva avatar Oct 14 '24 10:10 AnnaShaleva

And it's a map, it can't have duplicate keys, one key --- one value.

roman-khimov avatar Oct 14 '24 11:10 roman-khimov