You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Consider a message with a field sigs of type bytes[] in Solidity. In Go, this is represented as [][]uint8.
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.
encodeArrayValue is called, receiving the [][]uint8 as arrayValue and bytes as parsedType (correctly parsed from bytes[]).
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.
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.
The text was updated successfully, but these errors were encountered:
pythonberg1997
changed the title
Error when encoding bytes[] in `apitypes
Incorrect recursive encoding of nested bytes arrays (bytes[]) in apitypes
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:
Steps to reproduce the behaviour
Consider a message with a field
sigs
of typebytes[]
in Solidity. In Go, this is represented as[][]uint8
.The
func (typedData *TypedData) EncodeData(primaryType string, data map[string]interface{}, depth int)
method recursively encodes each field. When it encounters thesigs
array, it correctly identifies it as an array due to the trailing "]" in the type string.encodeArrayValue
is called, receiving the[][]uint8
asarrayValue
andbytes
asparsedType
(correctly parsed frombytes[]
).encodeArrayValue
. Each item inarrayValue
(which is a[]uint8
representing a Soliditybytes
) is incorrectly treated as another array. This triggers a recursive call toencodeArrayValue
.encodeArrayValue
call, the[]uint8
is further split into individualuint8
values. TheparsedType
remainsbytes
(becausestrings.Split("bytes", "[")[0]
is stillbytes
). This leads to an error because a singleuint8
cannot be parsed asbytes
.Backtrace
When submitting logs: please submit them as text and not screenshots.
The text was updated successfully, but these errors were encountered: