signer/core: fix encoding of `bytes` nested within array (#31049)
Fixes an incorrect encoding of recursive bytes types. closes https://github.com/ethereum/go-ethereum/issues/30979
This commit is contained in:
parent
53e8e1fdf2
commit
5552ada486
|
@ -501,7 +501,16 @@ func (typedData *TypedData) encodeArrayValue(encValue interface{}, encType strin
|
||||||
for _, item := range arrayValue {
|
for _, item := range arrayValue {
|
||||||
if reflect.TypeOf(item).Kind() == reflect.Slice ||
|
if reflect.TypeOf(item).Kind() == reflect.Slice ||
|
||||||
reflect.TypeOf(item).Kind() == reflect.Array {
|
reflect.TypeOf(item).Kind() == reflect.Array {
|
||||||
encodedData, err := typedData.encodeArrayValue(item, parsedType, depth+1)
|
var (
|
||||||
|
encodedData hexutil.Bytes
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
if reflect.TypeOf(item).Elem().Kind() == reflect.Uint8 {
|
||||||
|
// the item type is bytes. encode the bytes array directly instead of recursing.
|
||||||
|
encodedData, err = typedData.EncodePrimitiveValue(parsedType, item, depth+1)
|
||||||
|
} else {
|
||||||
|
encodedData, err = typedData.encodeArrayValue(item, parsedType, depth+1)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1014,3 +1014,49 @@ func TestComplexTypedDataWithLowercaseReftype(t *testing.T) {
|
||||||
t.Fatalf("Error, got %x, wanted %x", sighash, expSigHash)
|
t.Fatalf("Error, got %x, wanted %x", sighash, expSigHash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var recursiveBytesTypesStandard = apitypes.Types{
|
||||||
|
"EIP712Domain": {
|
||||||
|
{
|
||||||
|
Name: "name",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "version",
|
||||||
|
Type: "string",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "chainId",
|
||||||
|
Type: "uint256",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "verifyingContract",
|
||||||
|
Type: "address",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Val": {
|
||||||
|
{
|
||||||
|
Name: "field",
|
||||||
|
Type: "bytes[][]",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var recursiveBytesMessageStandard = map[string]interface{}{
|
||||||
|
"field": [][][]byte{{{1}, {2}}, {{3}, {4}}},
|
||||||
|
}
|
||||||
|
|
||||||
|
var recursiveBytesTypedData = apitypes.TypedData{
|
||||||
|
Types: recursiveBytesTypesStandard,
|
||||||
|
PrimaryType: "Val",
|
||||||
|
Domain: domainStandard,
|
||||||
|
Message: recursiveBytesMessageStandard,
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEncodeDataRecursiveBytes(t *testing.T) {
|
||||||
|
typedData := recursiveBytesTypedData
|
||||||
|
_, err := typedData.EncodeData(typedData.PrimaryType, typedData.Message, 0)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("got err %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue