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

Null characters rendered in assets codes of built-in Stellar Asset Contract #1032

Closed
leighmcculloch opened this issue Sep 1, 2023 · 1 comment · Fixed by #1041
Closed
Assignees
Labels
bug Something isn't working

Comments

@leighmcculloch
Copy link
Member

leighmcculloch commented Sep 1, 2023

What version are you using?

What did you do?

soroban lab token wrap --network local --source me --asset USD:GDP7GGFMNMWABGWTF6BUB45MN6TPOCFY43KJVK5LDBCSJ2QTMQYYU3DA
CAW7SH5JG45U6YLCFB6YD2KVSOZQHMNEJQPN6KDZOCGSXWR72ZIFBBMPsoroban contract invoke --network local --source me --id CAW7SH5JG45U6YLCFB6YD2KVSOZQHMNEJQPN6KDZOCGSXWR72ZIFBBMP -- name

The local network is a local quickstart running the commits above.

The me source is the networks root account.

What did you expect to see?

soroban contract invoke --network local --source me --id CAW7SH5JG45U6YLCFB6YD2KVSOZQHMNEJQPN6KDZOCGSXWR72ZIFBBMP -- name
"USD:GDP7GGFMNMWABGWTF6BUB45MN6TPOCFY43KJVK5LDBCSJ2QTMQYYU3DA"

What did you see instead?

soroban contract invoke --network local --source me --id CAW7SH5JG45U6YLCFB6YD2KVSOZQHMNEJQPN6KDZOCGSXWR72ZIFBBMP -- name
"USD\u0000:GDP7GGFMNMWABGWTF6BUB45MN6TPOCFY43KJVK5LDBCSJ2QTMQYYU3DA"

Discussion

Stellar assets have two types of asset codes, a 4 byte and 12 byte code. The specification of less than a 4 byte asset code when wrapping is selecting the 4 byte asset type, and the remaining characters are null (\u0000).

When rendering the asset to a string, it should be rendered without the null bytes. The null bytes are indicative of the string ending early, and not of characters that are meaningfully part of the code itself.

See SEP-11 for the correct rendering of the asset code.

@leighmcculloch leighmcculloch added the bug Something isn't working label Sep 1, 2023
@graydon
Copy link
Contributor

graydon commented Sep 1, 2023

Ok I think this is basically originating here which is delegating to the native-contract wrapper type String that wraps the host type String, and asking it to render itself as a Rust String. The whole codepath there is actually fairly weak and wrong (doesn't do metering, doesn't do any of the suggested SEP-11 stuff) and arguably Rust Strings shouldn't be involved at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants