1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

feat(tests): add tests for blind EIP-712 signing

Co-authored-by: Martin Milata <martin@martinmilata.cz>
Co-authored-by: grdddj <jiri.musil06@seznam.cz>
This commit is contained in:
matejcik 2021-12-16 17:47:08 +01:00 committed by matejcik
parent 77ab865386
commit d2ac4e7a9c
3 changed files with 129 additions and 5 deletions

View File

@ -72,7 +72,9 @@
},
"contents": "Hello, Bob!"
}
}
},
"message_hash": "0xea6529f0ee9eb0b207b5a8b0ebfa673d398d6a78262818da1d270bd138f81f03",
"domain_separator_hash": "0x97d6f53774b810fbda27e091c03c6a6d6815dd1270c2e62e82c6917c1eff774b"
},
"result": {
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
@ -209,7 +211,9 @@
"Hope you're fine"
]
}
}
},
"message_hash": "0xdbafe746b1c47e4870f6f77205660d3c49a94db9a80939809bfca7bf43919df5",
"domain_separator_hash": "0xc4f4e0cd1376e27837fe933e3f77b7bd6213211b377f0e19815a0dbd194731cc"
},
"result": {
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
@ -290,7 +294,9 @@
],
"contents": "Hello, guys!"
}
}
},
"message_hash": "0xc16c4b0b9a45a8e9c34c4074d8deb589686f7de3b83e80596ec79f815a17276e",
"domain_separator_hash": "0x97d6f53774b810fbda27e091c03c6a6d6815dd1270c2e62e82c6917c1eff774b"
},
"result": {
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
@ -371,12 +377,111 @@
],
"contents": "Hello, guys!"
}
}
},
"message_hash": "0x6ba2528513daa98abdbec7363a77751fc79ca38fe6d37bdbb983e310e5c1444e",
"domain_separator_hash": "0x97d6f53774b810fbda27e091c03c6a6d6815dd1270c2e62e82c6917c1eff774b"
},
"result": {
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
"sig": "0xba6658fd95d8f6048150c8ac64a596d974184522d1069237a57d0e170835fff661ff6f10c5049906a8a508c18d58145dcff91508e70e7e3c186193e3e3bb7dd61b"
}
},
{
"name": "structs_arrays_v4",
"parameters": {
"path": "m/44'/60'/0'/0/0",
"metamask_v4_compat": true,
"data": {
"domain": {
"chainId": 1,
"name": "Ether Mail",
"verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
"version": "1"
},
"message": {
"contents": "Hello, Bob!",
"attachedMoneyInEth": 4.2,
"from": {
"name": "Cow",
"wallets": [
"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
"0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF"
]
},
"to": [
{
"name": "Bob",
"wallets": [
"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
"0xB0BdaBea57B0BDABeA57b0bdABEA57b0BDabEa57",
"0xB0B0b0b0b0b0B000000000000000000000000000"
]
}
]
},
"primaryType": "Mail",
"types": {
"EIP712Domain": [
{
"name": "name",
"type": "string"
},
{
"name": "version",
"type": "string"
},
{
"name": "chainId",
"type": "uint256"
},
{
"name": "verifyingContract",
"type": "address"
}
],
"Group": [
{
"name": "name",
"type": "string"
},
{
"name": "members",
"type": "Person[]"
}
],
"Mail": [
{
"name": "from",
"type": "Person"
},
{
"name": "to",
"type": "Person[]"
},
{
"name": "contents",
"type": "string"
}
],
"Person": [
{
"name": "name",
"type": "string"
},
{
"name": "wallets",
"type": "address[]"
}
]
}
},
"domain_separator_hash": "0xf2cee375fa42b42143804025fc449deafd50cc031ca257e0b194a650a912090f",
"message_hash": "eb4221181ff3f1a83ea7313993ca9218496e424604ba9492bb4052c03d5c3df8"
},
"result": {
"address": "0x73d0385F4d8E00C5e6504C6030F47BF6212736A8",
"sig": "0x1d778d9ae559161f4ea57aad9135035eb7e26e5e4cf5b571c58736ee265b649b17c38730ede957efbcf7de4f30906b133a4262b9e4bb8e4ba3927a48512e3a561c"
}
}
]
}

View File

@ -23,9 +23,10 @@ from ...common import parametrize_using_common_fixtures
SHOW_MORE = (143, 167)
pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum, pytest.mark.skip_t1]
pytestmark = [pytest.mark.altcoin, pytest.mark.ethereum]
@pytest.mark.skip_t1
@parametrize_using_common_fixtures("ethereum/sign_typed_data.json")
def test_ethereum_sign_typed_data(client, parameters, result):
with client:
@ -40,6 +41,21 @@ def test_ethereum_sign_typed_data(client, parameters, result):
assert f"0x{ret.signature.hex()}" == result["sig"]
@pytest.mark.skip_t2
@parametrize_using_common_fixtures("ethereum/sign_typed_data.json")
def test_ethereum_sign_typed_data_blind(client, parameters, result):
with client:
address_n = parse_path(parameters["path"])
ret = ethereum.sign_typed_data_hash(
client,
address_n,
ethereum.decode_hex(parameters["domain_separator_hash"]),
ethereum.decode_hex(parameters["message_hash"]),
)
assert ret.address == result["address"]
assert f"0x{ret.signature.hex()}" == result["sig"]
# Being the same as the first object in ethereum/sign_typed_data.json
DATA = {
"types": {
@ -120,6 +136,7 @@ def input_flow_cancel(client):
client.debug.press_no()
@pytest.mark.skip_t1
def test_ethereum_sign_typed_data_show_more_button(client):
with client:
client.watch_layout()
@ -132,6 +149,7 @@ def test_ethereum_sign_typed_data_show_more_button(client):
)
@pytest.mark.skip_t1
def test_ethereum_sign_typed_data_cancel(client):
with client, pytest.raises(exceptions.Cancelled):
client.watch_layout()

View File

@ -593,6 +593,7 @@
"ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data[complex_data]": "275a8630a795c966419f6fc6de834bb576bfc3dbc16a1fd7605aa2b8ceae666e",
"ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data[struct_list_non_v4]": "7dd23b14bd273b937836a24cf056c745e7b3461139f895caefd4624e0d5545f5",
"ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data[struct_list_v4]": "b7e3475d4906942bc0e8d62203ae91a13ea0d702c3a7a53b9777bea670c4a7f7",
"ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data[structs_arrays_v4]": "31cc5b5c1d9d94f0761208f5dc6423d283b9118b12b87cf878d20fa144f4f252",
"ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data_cancel": "08712efae2d007610289bbfb3a8fe6800547e884636c83c5bf0e25f33728789e",
"ethereum-test_sign_typed_data.py::test_ethereum_sign_typed_data_show_more_button": "1adbea797586685ce09aae58b0a2b89e1617e4eaad23a8c1ac6fc10b041e57a5",
"ethereum-test_sign_verify_message.py::test_signmessage[parameters0-result0]": "7aa14b29e5005d8fdc0a8b497ed5d3ebea15c7017f9c457d09214f2d05fbc532",