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

Closed
pythonberg1997 opened this issue Jan 3, 2025 · 0 comments · Fixed by #31049
Closed

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

pythonberg1997 opened this issue Jan 3, 2025 · 0 comments · Fixed by #31049
Assignees
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
@holiman holiman self-assigned this Jan 9, 2025
@jwasinger jwasinger self-assigned this Jan 16, 2025
buddh0 pushed a commit to buddh0/bsc that referenced this issue Feb 27, 2025
Fixes an incorrect encoding of recursive bytes types.
closes ethereum/go-ethereum#30979
buddh0 pushed a commit to buddh0/bsc that referenced this issue Feb 27, 2025
Fixes an incorrect encoding of recursive bytes types.
closes ethereum/go-ethereum#30979
Donk3ys pushed a commit to Libex-LLC/lbx-chain that referenced this issue Mar 4, 2025
Fixes an incorrect encoding of recursive bytes types.
closes ethereum/go-ethereum#30979
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment