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

Incorrect recursive encoding of nested bytes arrays (bytes[]) in apitypes #30979

Open
pythonberg1997 opened this issue Jan 3, 2025 · 0 comments · May be fixed by #30987
Open

Incorrect recursive encoding of nested bytes arrays (bytes[]) in apitypes #30979

pythonberg1997 opened this issue Jan 3, 2025 · 0 comments · May be fixed by #30987
Labels

Comments

@pythonberg1997
Copy link

pythonberg1997 commented Jan 3, 2025

System information

Geth version: v1.14.12
CL client & version: Not related
OS & Version: OSX
Commit hash : (if develop)

Expected behaviour

Encode successfully

Actual behaviour

Get error:

failed to pack and hash typedData primary type: provided data '65' doesn't match type 'bytes'

Steps to reproduce the behaviour

  1. Consider a message with a field sigs of type bytes[] in Solidity. In Go, this is represented as [][]uint8.

  2. The func (typedData *TypedData) EncodeData(primaryType string, data map[string]interface{}, depth int) method recursively encodes each field. When it encounters the sigs array, it correctly identifies it as an array due to the trailing "]" in the type string.

image
  1. encodeArrayValue is called, receiving the [][]uint8 as arrayValue and bytes as parsedType (correctly parsed from bytes[]).
image
  1. The problem arises within the loop of encodeArrayValue. Each item in arrayValue (which is a []uint8 representing a Solidity bytes) is incorrectly treated as another array. This triggers a recursive call to encodeArrayValue.
image
  1. In the second, erroneous encodeArrayValue call, the []uint8 is further split into individual uint8 values. The parsedType remains bytes (because strings.Split("bytes", "[")[0] is still bytes). This leads to an error because a single uint8 cannot be parsed as bytes.

Backtrace

[backtrace]

When submitting logs: please submit them as text and not screenshots.

@pythonberg1997 pythonberg1997 changed the title Error when encoding bytes[] in `apitypes Incorrect recursive encoding of nested bytes arrays (bytes[]) in apitypes Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant