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

Use byte arrays to store non-unicode fate strings #291

Merged
merged 1 commit into from
Oct 9, 2024
Merged

Conversation

davidyuk
Copy link
Member

@davidyuk davidyuk commented Oct 5, 2024

extracted from #287

This PR is supported by the Æternity Foundation

unicode strings implementation - why and how

Firstly, if a contract uses fate strings as bytes, then these bytes can be broken by converting them to strings on js side. To avoid that I propose to keep data as bytes, keeping the same API except that valueOf will return bytes instead of a string if the payload is non-unicode.

The issue I had is that some arguments in contract instructions are raw strings, the current implementation breaks them while decoding making impossible to encode them back. For example:

  {
    id: '1f734048',
    name: 'test_bls12_381_fp',
    attributes: [],
    args: { name: 'tuple', valueTypes: [ { name: 'int' } ] },
    returnType: { name: 'bytes', size: 48n },
    instructions: [
      [
        {
          mnemonic: 'PUSH',
          args: [ { mod: 'arg', arg: 0n, type: { name: 'int' } } ]
        },
        {
          mnemonic: 'CALL_T',
          args: [
            {
              mod: 'immediate',
              arg: '��u�', // OR Uint8Array(4) [ 243, 237, 117, 150 ] after this PR
              type: { name: 'string' }
            }
          ]
        }
      ]
    ]
  },

@davidyuk davidyuk requested a review from dincho October 5, 2024 02:31
@dincho
Copy link
Member

dincho commented Oct 8, 2024

The issue I had is that some arguments in contract instructions are raw strings,

Maybe we shouldn't decode such arguments as strings but byte arrays? I'll take a closer look.

The PR idea is common-sense at first, but the results are a bit controversial for me still. The Unicode check is also heart-breaking.

Copy link
Member

@dincho dincho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really happy, but it is what it is as FATE strings are really byte arrays. I don't have better ideas.

@dincho dincho merged commit 0c2300d into master Oct 9, 2024
2 checks passed
@dincho dincho deleted the raw-strings branch October 9, 2024 11:10
@dincho dincho added the bug Something isn't working label Nov 29, 2024
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 this pull request may close these issues.

2 participants