Skip to content

Inaccurate documentation for bytes encoding #15303

Open
@Amit0617

Description

@Amit0617

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions