Inaccurate documentation for bytes encoding
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
## 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](https://docs.soliditylang.org/en/latest/abi-spec.html#formal-specification-of-the-encoding) 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
Contributor guide
Research direction
Start with the ABI specification examples at the linked documentation page and compare the bytes3[2] example with the formal string encoding section. Verify whether the argument notation, function signature, and encoded values agree, then update the documentation so the example clearly distinguishes string inputs from fixed-size byte inputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- solidity
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100