fix(core): support structs as array elements (fixes #2167)

pull/2172/head
matejcik 2 years ago committed by matejcik
parent 5c803ab19d
commit 0b9f7db742

@ -547,12 +547,216 @@
}
},
"domain_separator_hash": "0xf2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090f",
"message_hash": "eb4221181ff3f1a83ea7313993ca9218496e424604ba9492bb4052c03d5c3df8"
"message_hash": "0xeb4221181ff3f1a83ea7313993ca9218496e424604ba9492bb4052c03d5c3df8"
},
"result": {
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
"sig": "0x1d778d9ae559161f4ea57aad9135035eb7e26e5e4cf5b571c58736ee265b649b17c38730ede957efbcf7de4f30906b133a4262b9e4bb8e4ba3927a48512e3a561c"
}
},
{
"name": "array_of_structs",
"comment": "Struct used only as an array element (issue #2167)",
"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": "0x7be2cca6dd2e37cf3e8ab76ab19df174e369ad48e3fd0088c7f99137cbf6a2d8",
"domain_separator_hash": "0x6192106f129ce05c9075d319c1fa6ea9b3ae37cbd0c1ef92e2be7137bb07baa1"
},
"result": {
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
"sig": "0x5c7fe30cc1889a59177864c58c2e5f46e4c5fd4ad7b565a6a6c0416a2d1370d233da9c2c40fc95b694af21b8cb1e027d9d664118fa021f71e2fd0d8eada7fd5d1c"
}
},
{
"name": "injective_testcase",
"comment": "Full Injective Protocol testcase (issue #2167)",
"parameters": {
"path": "m/44'/60'/0'/0/0",
"metamask_v4_compat": true,
"data": {
"types": {
"Coin": [
{
"name": "denom",
"type": "string"
},
{
"name": "amount",
"type": "string"
}
],
"EIP712Domain": [
{
"name": "name",
"type": "string"
},
{
"name": "version",
"type": "string"
},
{
"name": "chainId",
"type": "uint256"
},
{
"name": "verifyingContract",
"type": "string"
},
{
"name": "salt",
"type": "string"
}
],
"Fee": [
{
"name": "amount",
"type": "Coin[]"
},
{
"name": "gas",
"type": "string"
}
],
"Msg": [
{
"name": "type",
"type": "string"
},
{
"name": "value",
"type": "MsgValue"
}
],
"MsgValue": [
{
"name": "delegator_address",
"type": "string"
},
{
"name": "validator_address",
"type": "string"
},
{
"name": "amount",
"type": "TypeAmount"
}
],
"Tx": [
{
"name": "account_number",
"type": "string"
},
{
"name": "chain_id",
"type": "string"
},
{
"name": "fee",
"type": "Fee"
},
{
"name": "memo",
"type": "string"
},
{
"name": "msgs",
"type": "Msg[]"
},
{
"name": "sequence",
"type": "string"
},
{
"name": "timeout_height",
"type": "string"
}
],
"TypeAmount": [
{
"name": "denom",
"type": "string"
},
{
"name": "amount",
"type": "string"
}
]
},
"primaryType": "Tx",
"domain": {
"name": "Injective Web3",
"version": "1.0.0",
"chainId": 1,
"verifyingContract": "cosmos",
"salt": "1646906878039"
},
"message": {
"account_number": "5712",
"chain_id": "injective-1",
"fee": {
"amount": [
{
"amount": "200000000000000",
"denom": "inj"
}
],
"gas": "400000"
},
"memo": "",
"msgs": [
{
"type": "cosmos-sdk/MsgDelegate",
"value": {
"amount": {
"amount": "100000000000000000",
"denom": "inj"
},
"delegator_address": "inj17vy49gw9xnx700z8zwqqv4exl2rgdhanv75c4r",
"validator_address": "injvaloper1w3psm8a9td2qz06s46cxss03mz5umxaxegvhhs"
}
}
],
"sequence": "0",
"timeout_height": "8545415"
}
},
"message_hash": "0x07df743324b2b3f805790b2bbd497e7b7571a1e3fe4e2d86b67f35ca9a120d90",
"domain_separator_hash": "0x8e96520578ec587b6ad9d06fe5fc352b34e98090044921089e1a9cbc1290901c"
},
"result": {
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
"sig": "0x4873bf73cf22e35776d8b23a249f93f38a6d5aa8c1a121281675094f5fac64b55a3b6cf28e140930f9185156d07f171a17e06925b5cebd95a2a8761d074e43f91c"
}
}
]
}

@ -0,0 +1 @@
Support EIP-712 messages where a struct type is only used as an array element.

@ -144,13 +144,17 @@ class TypedDataEnvelope:
current_type = await self.ctx.call(req, EthereumTypedDataStructAck)
self.types[type_name] = current_type
for member in current_type.members:
validate_field_type(member.type)
member_type = member.type
validate_field_type(member_type)
while member_type.data_type == EthereumDataType.ARRAY:
assert member_type.entry_type is not None # validate_field_type
member_type = member_type.entry_type
if (
member.type.data_type == EthereumDataType.STRUCT
and member.type.struct_name not in self.types
member_type.data_type == EthereumDataType.STRUCT
and member_type.struct_name not in self.types
):
assert member.type.struct_name is not None # validate_field_type
await self._collect_types(member.type.struct_name)
assert member_type.struct_name is not None # validate_field_type
await self._collect_types(member_type.struct_name)
async def hash_struct(
self,

@ -333,10 +333,12 @@
"T1_ethereum-test_getpublickey.py::test_ethereum_getpublickey[parameters0-result0]": "37e446e17465ce9823c34c9162d94e4ad3c84faa86bae7966c753be5c5fd77a2",
"T1_ethereum-test_getpublickey.py::test_ethereum_getpublickey[parameters1-result1]": "37e446e17465ce9823c34c9162d94e4ad3c84faa86bae7966c753be5c5fd77a2",
"T1_ethereum-test_getpublickey.py::test_ethereum_getpublickey[parameters2-result2]": "37e446e17465ce9823c34c9162d94e4ad3c84faa86bae7966c753be5c5fd77a2",
"T1_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data_blind[array_of_structs]": "04b94ca842aa77fdc6b75b07bbe178c4ea99c35e6dae630588fa5d9cb67b9090",
"T1_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data_blind[bare_minimum]": "730a5d3bf1389ac14aec7ee9f65e2cbf516957e5077acc0e07a7541f667e2f0b",
"T1_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data_blind[basic_data]": "fd99dc685a4a125db0f3f8d2a16ffa242bd57e4ff714d66cc9c4161c486f53be",
"T1_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data_blind[complex_data]": "24957177a20a1aacba25207e210ee3d97a9ca0b62b19e2fa9598d77bd27f3cde",
"T1_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data_blind[full_domain_empty_message]": "68d748b8407f9d9005d293b5c6c122051f7376761c3628ea4968255ecbc1df39",
"T1_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data_blind[injective_testcase]": "586a48367b619266abb0ddd39ae825156fcc1945ae01170e5f4ee7ba66c83360",
"T1_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data_blind[struct_list_non_v4]": "eb17b48c8495ae235345920089c1662f5aa36fbb6e90f0c0c4b270c7bb2f2ea8",
"T1_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data_blind[struct_list_v4]": "b0ce2ac7326df63ae12badf47a58db955fe2b17a327fcdc6eee1fd06375a25f7",
"T1_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data_blind[structs_arrays_v4]": "a38f3ef2571424b460cd7351cd7263c8fc19684041d57f32f5599588c89046bf",
@ -1211,10 +1213,12 @@
"TT_ethereum-test_getpublickey.py::test_ethereum_getpublickey[parameters0-result0]": "095af81ec79e9b510c90d9fa34fed343f3840807190c67bc237af885695ae687",
"TT_ethereum-test_getpublickey.py::test_ethereum_getpublickey[parameters1-result1]": "095af81ec79e9b510c90d9fa34fed343f3840807190c67bc237af885695ae687",
"TT_ethereum-test_getpublickey.py::test_ethereum_getpublickey[parameters2-result2]": "095af81ec79e9b510c90d9fa34fed343f3840807190c67bc237af885695ae687",
"TT_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data[array_of_structs]": "beab149b40301175664a8851714a1379239bd505c9e59301cd7a1c6683c4c634",
"TT_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data[bare_minimum]": "e13b237f58a9977c6edf1917730748b881749acecc3d040b1fd9d794e6e02299",
"TT_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data[basic_data]": "84f1d23e031919fedb4ef6b3f3dc1cb667836b9efcd0c5a0da586010e38e1fd6",
"TT_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data[complex_data]": "27ee23894c19e5704d02ae684d50a0f0d14678d3f74a95e67fc4975818a1faa8",
"TT_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data[full_domain_empty_message]": "c3c299087e9cac4d7554314abc8637d041da69f0c0ee2863c5526f1f89448ae2",
"TT_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data[injective_testcase]": "283366c3271fd08d23df747fb1ef0236e31ef307484851cb101472ee75f5d249",
"TT_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data[struct_list_non_v4]": "84f1d23e031919fedb4ef6b3f3dc1cb667836b9efcd0c5a0da586010e38e1fd6",
"TT_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data[struct_list_v4]": "84f1d23e031919fedb4ef6b3f3dc1cb667836b9efcd0c5a0da586010e38e1fd6",
"TT_ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data[structs_arrays_v4]": "84f1d23e031919fedb4ef6b3f3dc1cb667836b9efcd0c5a0da586010e38e1fd6",

Loading…
Cancel
Save