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

Guideline for bytes encoding for JSON input and outuput types (smart contracts) #490

Open
robert-zaremba opened this issue Jul 25, 2023 · 1 comment
Labels
WG-contract-standards Contract Standards Work Group should be accountable WG-tools Tools Working Group should be accountable.

Comments

@robert-zaremba
Copy link
Contributor

robert-zaremba commented Jul 25, 2023

I want to start discussion about hash encoding.
For response types, a hash should be encoded as a String. Currently the NFT standard uses base64 for hash encoding.

In the SBT standard, we followed up with that design and also set base64 there.

I'm working on a guideline for metadata, and now I am coming to reflection that base64 is not a good option:

  • many standards
  • implementation dependent

In various other works where consensus and interoperability is critical we decided to not use base64. In Cosmos, the decision was to stick with hex.

So, I would like to start a discussion to rather use z-base32 or base32 or hex. My personal preference is z-base32.
The problem is when base64 formatted string is returned from a function and expected to interoperate with various other implementations. For consensus base64 is not unique.
It's not a problem for cross-contract calls which operate in the same environment (eg: near wasm), but could be a problem where additional consensus for relayers is required.

I think it's important to quickly analyze this and update if needed, and establish a guideline in NEAR.

Reference: https://en.wikipedia.org/wiki/Base32#Advantages

@robert-zaremba robert-zaremba added WG-contract-standards Contract Standards Work Group should be accountable WG-tools Tools Working Group should be accountable. labels Jul 25, 2023
@frol
Copy link
Collaborator

frol commented Jul 30, 2023

There has been quite an old discussion on nearcore about different encoding schemes: near/nearcore#2100

Personally, I prefer hex as it is commonly used for hash representation, straightforward, URI-friendly, stable in length (always 64 characters for 32 bytes input), and the only downside is the length of the payload (but it is not that bad)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WG-contract-standards Contract Standards Work Group should be accountable WG-tools Tools Working Group should be accountable.
Projects
None yet
Development

No branches or pull requests

2 participants