IntersectMBO / cardano-node

The core component that is used to participate in a Cardano decentralised blockchain.
https://cardano.org
Apache License 2.0
3.06k stars 720 forks source link

[BUG] - Native tokens with non-UTF8 names break cardano-cli query utxo #2999

Closed Quantumplation closed 2 years ago

Quantumplation commented 3 years ago

External

Area Native Tokens Related to Native Tokens (Mary). Plutus Related to Plutus Scripts (Alonzo).

Summary

If you create a native token with an assetName that isn't valid UTF-8, cardano-cli is unable to render it as part of cardano-cli query utxo.

image

image

Steps to reproduce Create a native token by constructing and serializing the transaction from haskell, using an "allow all" minting policy, which has an asset name that is not valid UTF-8.

In our case, we are setting the asset name to the bytes from a sha256 hash, since that fits perfectly in the 32 bytes allowed for the asset name.

Expected behavior

One of two possibilities seems sensible:

We've patched cardano-cli locally with the latter:

$ cardano-cli query utxo --whole-utxo --testnet-magic 31415
                         TxHash                                              TxIx               Amount
--------------------------------------------------------------------------------------------------------------------------
4264cb256d94533b6e152da59256638bc6adfda3efc5550d7607d4e6e45592fc                0               10000000 lovelace + 100 ba372dc1677a26ef3396bc357c31765ef0287e94d0c41629ad3.{ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb}

We wrap the assetName with curly brackets to give some indication that it's base16 encoded, rather than the actual asset name.

If there's interest in this approach, we're happy to submit a pull request!

System info (please complete the following information):

Screenshots and attachments

Additional context

savaki commented 3 years ago

For clarification, the cardano-cli prints all the utxos up to the point where it encounters the first utxo with a non-UTF8 asset name and then bombs there.

dcoutts commented 3 years ago

Yeah, it's just a presentation issue, and should be fixed as a presentation issue. The asset names are not required to be UTF8 (they have to support the use case of hashes for example).

Quantumplation commented 3 years ago

@dcoutts would you accept a pull request?

If so, would you prefer:

gitmachtl commented 3 years ago

please be careful with such transactions, i don't see a way for the "normal" cardano-cli user to handle such tokens in his utxos rather than filtering out the incoming utxo in total. so, not a good think for the mainnet atm.

Quantumplation commented 3 years ago

@gitmachtl In particular, this is needed for protocol tokens whose names are the SHA256 hash of some data. Asset names are the perfect size to hold a SHA256 hash, and hex-encoding them first would make them too big.

The fix we have in our locally-patched cardano-cli locally is, if UTF8 encoding fails, print policyID.{[hex-encoded]}, such as ba372dc1677a26ef3396bc357c31765ef0287e94d0c41629ad3.{ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb}. When reading token names from the CLI, we apply a similar reverse translation.

Quantumplation commented 3 years ago

(But yes, we have held off running our contracts on the public Alonzo White / Alonzo Purple testnets to avoid breaking anyone; we have been using a private alonzo purple instance instead)

gitmachtl commented 3 years ago

solved in https://github.com/input-output-hk/cardano-node/pull/3211

cblp commented 2 years ago

Must be fixed in master

cblp commented 2 years ago

If reproduced, comment here to reopen.