1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

fix(core): add EIP-712 nested arrays support (#2963)

This commit is contained in:
Jan Hnatek 2024-09-05 11:47:10 +02:00
parent d98b5fe064
commit d4391d883a
4 changed files with 92 additions and 4 deletions

View File

@ -757,6 +757,86 @@
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8", "address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
"sig": "0x4873bf73cf22e35776d8b23a249f93f38a6d5aa8c1a121281675094f5fac64b55a3b6cf28e140930f9185156d07f171a17e06925b5cebd95a2a8761d074e43f91c" "sig": "0x4873bf73cf22e35776d8b23a249f93f38a6d5aa8c1a121281675094f5fac64b55a3b6cf28e140930f9185156d07f171a17e06925b5cebd95a2a8761d074e43f91c"
} }
},
{
"name": "nested_array_of_string",
"comment": "Nested arrays (issue #2963)",
"parameters": {
"path": "m/44'/60'/0'/0/0",
"metamask_v4_compat": true,
"data": {
"types": {
"EIP712Domain": [],
"Message": [
{
"name": "text",
"type": "string[][]"
}
]
},
"primaryType": "Message",
"message": {
"text": [
["1", "2"],
["3", "4"]
]
},
"domain": {}
},
"message_hash": "0xc40dc798242ec8a6a0f2974e8f687583c118a6b74f161dc39cd79025d228ca1d",
"domain_separator_hash": null
},
"result": {
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
"sig": "0x26df1807221e9a0ce4d3f0a6422c55f9cca7de55268a9d6c4772fd28893730b8755f3d23cef14ea02ea74c9045a3a8ae6a3f1ceb252cd2a6f3a43832d8a0c7b01c"
}
},
{
"name": "nested_array_of_object",
"comment": "Nested arrays (issue #2963)",
"parameters": {
"path": "m/44'/60'/0'/0/0",
"metamask_v4_compat": true,
"data": {
"types": {
"EIP712Domain": [],
"Message": [
{
"name": "element",
"type": "Element[][]"
}
],
"Element": [
{
"name": "foo",
"type": "int8"
}
]
},
"primaryType": "Message",
"message": {
"element": [
[
{
"foo": 1
}
],
[
{
"foo": 2
}
]
]
},
"domain": {}
},
"message_hash": "0x56034f4b5afe2fb032f1e60b3bc649c8725396d1e9b4d85725bdff1d366a86e6",
"domain_separator_hash": null
},
"result": {
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
"sig": "0x6f2c2e2392ca20374679b4d34a2e910cf2357c32ce06c25592c1ebe5a77e76433e4b38d853ccce71930df085861a90c36611a24ba673964bf6a889a063c568311b"
}
} }
] ]
} }

View File

@ -0,0 +1 @@
Fixed EIP-712 nested arrays support.

View File

@ -374,7 +374,6 @@ class TypedDataEnvelope:
for i in range(array_size): for i in range(array_size):
field_member_path[-1] = i field_member_path[-1] = i
# TODO: we do not support arrays of arrays, check if we should
if entry_type.data_type == EthereumDataType.STRUCT: if entry_type.data_type == EthereumDataType.STRUCT:
assert entry_type.struct_name is not None # validate_field_type assert entry_type.struct_name is not None # validate_field_type
@ -387,6 +386,17 @@ class TypedDataEnvelope:
is_array_member=True, is_array_member=True,
) )
elif entry_type.data_type == EthereumDataType.ARRAY:
await self.encode_array(
arr_w,
array_name,
entry_type,
field_member_path,
show_array,
parent_objects,
current_parent_objects,
)
else: else:
await self.encode_nonref( await self.encode_nonref(
arr_w, arr_w,

View File

@ -87,9 +87,6 @@ def get_field_type(type_name: str, types: dict) -> messages.EthereumFieldType:
size = parse_array_n(type_name) size = parse_array_n(type_name)
member_typename = typeof_array(type_name) member_typename = typeof_array(type_name)
entry_type = get_field_type(member_typename, types) entry_type = get_field_type(member_typename, types)
# Not supporting nested arrays currently
if entry_type.data_type == messages.EthereumDataType.ARRAY:
raise NotImplementedError("Nested arrays are not supported")
elif type_name.startswith("uint"): elif type_name.startswith("uint"):
data_type = messages.EthereumDataType.UINT data_type = messages.EthereumDataType.UINT
size = get_byte_size_for_int_type(type_name) size = get_byte_size_for_int_type(type_name)