Skip to content

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

@pythonberg1997

Description

@pythonberg1997

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.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions