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

The limit of key length for storage must be increased.

Open nujabes403 opened this issue 4 years ago • 2 comments

Currently, there is a limit for key of storage which is [1, 64] lengths.

However, it must be increased for transferring NFT token to contract.

I found this issue while I'm sending my NFT token to contract.

https://github.com/iost-official/go-iost/blob/bc3300873ce4d90c3ac01dac18bd10a893527032/vm/native/token721.go#L281

Please see the code below, this code is run while calling 'token721.iost', 'transfer'.

cost0, err = h.MapPut(
  Token721MetadataMapPrefix+tokenSym+Token721MetadataKeySeparator+to, 
  tokenID, 
  metaDataJSON, 
  publisher
)

Token721MetadataMapPrefix+tokenSym+Token721MetadataKeySeparator+to

Let's see this one.

  Token721MetadataMapPrefix    = "T721M"
  Token721MetadataKeySeparator = "#"

My NFT's tokenSym is: uniqueasset 'to' is set to some contractAddress: ContractCCx8LpBwqLdQCsrQ7hEPu8dTnd4zKFTu5jzojvAM75W6

When it is combined, "T721M" + "uniqueasset" + "#" + "ContractCCx8LpBwqLdQCsrQ7hEPu8dTnd4zKFTu5jzojvAM75W6"

image

The length exceeds [1, 64] boundary which is the reason why the transaction like this (https://www.iostabc.com/tx/7oDnRgb9XEhzsAR9JZAfLma8j89zUBvsAXJNrr7VwrHj) was failed.

To activate NFT ecosystem in IOST, there would be many scenario for transferring NFT to contract, for example NFT market.

So the key length limit must be increased.

@sswsdsn @mlj1991 @flybikeGx @ziranliu @lispc @lileicool1

nujabes403 avatar Jun 25 '20 06:06 nujabes403

After a careful code review, we think it is better not to change the 64 limit, which is a so breaking change.
Instead, we think we can change the data structure. We will change the current tokenSym + owner -> tokenId -> metaData map, to two maps, the first is tokenSym -> owner -> tokenId, the second is tokenSym -> tokenId -> metaData. This will be a less breaking change.

lispc avatar Jul 06 '20 08:07 lispc

@lispc Good!! Let me know when the code is updated. 👍

nujabes403 avatar Jul 08 '20 04:07 nujabes403