Skip to content

Inaccurate documentation for bytes encoding #15303

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

Open
Amit0617 opened this issue Jul 26, 2024 · 4 comments · May be fixed by #16006
Open

Inaccurate documentation for bytes encoding #15303

Amit0617 opened this issue Jul 26, 2024 · 4 comments · May be fixed by #16006

Comments

@Amit0617
Copy link

Amit0617 commented Jul 26, 2024

Page

https://docs.soliditylang.org/en/latest/abi-spec.html#examples

Abstract

Encoding process of bytes and string is confusing(wrong). In the first example function bar(bytes3[2] memory), two arguments are passed ["abc", "def"] which are getting encoded to their ASCII equivalent and get right padded. This suggests, function signature should look like bar(string[2] memory) as mentioned in Formal Specification of the Encoding for string except for the length part.

  • string:

    enc(X) = enc(enc_utf8(X)), i.e. X is UTF-8 encoded and this value is interpreted as of bytes type and encoded further. Note that the length used in this subsequent encoding is the number of bytes of the UTF-8 encoded string, not its number of characters.

Otherwise, if the function signature is bar(bytes3[2] memory) then directly bytes should be passed into functions which would be 616263 and 646566. After encoding these would become 0x6162630000000000000000000000000000000000000000000000000000000000 and 0x6465660000000000000000000000000000000000000000000000000000000000

Pull request

@Amit0617
Copy link
Author

Similar issue with third example too for dave.

Copy link

This issue has been marked as stale due to inactivity for the last 90 days.
It will be automatically closed in 7 days.

@github-actions github-actions bot added the stale The issue/PR was marked as stale because it has been open for too long. label Oct 28, 2024
@Amit0617 Amit0617 changed the title Unclear documentation for bytes encoding Inaccurate documentation for bytes encoding Oct 29, 2024
@Amit0617
Copy link
Author

Amit0617 commented Oct 29, 2024

It is simply wrong, string values are passed as bytes in those examples. I had raised this issue on foundry too, if they are lacking functionality and probably lacking specifications compliance. But this is just problematic technically, mixing string and bytes will create inconsistent encoding values. For example, if a function receives abc as input, it can be already hex encoded bytes value, and it can be a valid string also. This creates confusion whether it is already encoded value and needs to be padded only or encoding still needs to be done on the given value.

@github-actions github-actions bot removed the stale The issue/PR was marked as stale because it has been open for too long. label Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
@Amit0617 and others