ERC725Alliance / erc725.js

Package to interact with ERC725 smart contracts
Apache License 2.0
38 stars 29 forks source link

Missing length for `CompactBytesArray` encoding / `uint32` #397

Open Hugoo opened 6 months ago

Hugoo commented 6 months ago

It seems that there is an encoding issue for the following:

✅ decodeData

ERC725.decodeData(
    [
      {
        keyName: "LSP18RoyaltiesRecipients",
        value: "0x001c24871b3dbf969fdccf9d9beee0b56bdaef2a73a6eb885c5900001388",
      },
    ],
    [
      {
        name: "LSP18RoyaltiesRecipients",
        key: "0xc0569ca6c9180acc2c3590f36330a36ae19015a19f4e85c28a7631e3317e6b9d",
        keyType: "Singleton",
        valueType: "(bytes4,address,uint32)[CompactBytesArray]",
        valueContent: "(Bytes4,Address,Number)",
      },
    ]
  );

Returns:

{
  key: '0xc0569ca6c9180acc2c3590f36330a36ae19015a19f4e85c28a7631e3317e6b9d',
  name: 'LSP18RoyaltiesRecipients',
  value: [
    [
      '0x24871b3d',
      '0xbF969fdCCf9D9bEEe0b56bdaEF2a73a6eb885C59',
      5000
    ]
  ]
}

❌ encodeData

The encoding is wrong

ERC725.encodeData(
    [
      {
        keyName: "LSP18RoyaltiesRecipients",
        value: [
          "0x24871b3d",
          "0xbF969fdCCf9D9bEEe0b56bdaEF2a73a6eb885C59",
          "5000",
        ],
      },
    ],
    [
      {
        name: "LSP18RoyaltiesRecipients",
        key: "0xc0569ca6c9180acc2c3590f36330a36ae19015a19f4e85c28a7631e3317e6b9d",
        keyType: "Singleton",
        valueType: "(bytes4,address,uint32)[CompactBytesArray]",
        valueContent: "(Bytes4,Address,Number)",
      },
    ]
  );

Returns:

{
  keys: ['0xc0569ca6c9180acc2c3590f36330a36ae19015a19f4e85c28a7631e3317e6b9d'],
  values: ['0x24871b3dbf969fdccf9d9beee0b56bdaef2a73a6eb885c591388']
}

Expected value:

  1. Missing length
  2. Missing 0000 for the utin32
❌ 0x%%%%24871b3dbf969fdccf9d9beee0b56bdaef2a73a6eb885c59%%%%1388
✅ 0x001c24871b3dbf969fdccf9d9beee0b56bdaef2a73a6eb885c5900001388

Related to:

m4r-v1n commented 4 months ago

Version 0.27.0 couldn't properly parse tuples with CompactBytesArray:

error: Could not encode 4200. Value type uint32)[CompactBytesArray is unknown

It gets uint32 as uint32)[CompactBytesArray ...