Enforce network id/protocol magic consistency for cardano show address

pull/1295/head
Rafael Korbas 4 years ago committed by Tomas Susanka
parent 638977db7d
commit 66dbdc2462

@ -42,7 +42,7 @@
"path": "m/44'/1815'/0'/0/0", "path": "m/44'/1815'/0'/0/0",
"address_type": "byron", "address_type": "byron",
"protocol_magic": 42, "protocol_magic": 42,
"network_id": 1 "network_id": 0
}, },
"result": { "result": {
"expected_address": "2657WMsDfac5F3zbgs9BwNWx3dhGAJERkAL93gPa68NJ2i8mbCHm2pLUHWSj8Mfea" "expected_address": "2657WMsDfac5F3zbgs9BwNWx3dhGAJERkAL93gPa68NJ2i8mbCHm2pLUHWSj8Mfea"
@ -53,7 +53,7 @@
"path": "m/44'/1815'/0'/0/1", "path": "m/44'/1815'/0'/0/1",
"address_type": "byron", "address_type": "byron",
"protocol_magic": 42, "protocol_magic": 42,
"network_id": 1 "network_id": 0
}, },
"result": { "result": {
"expected_address": "2657WMsDfac6ezKWszxLFqJjSUgpg9NgxKc1koqi24sVpRaPhiwMaExk4useKn5HA" "expected_address": "2657WMsDfac6ezKWszxLFqJjSUgpg9NgxKc1koqi24sVpRaPhiwMaExk4useKn5HA"
@ -64,7 +64,7 @@
"path": "m/44'/1815'/0'/0/2", "path": "m/44'/1815'/0'/0/2",
"address_type": "byron", "address_type": "byron",
"protocol_magic": 42, "protocol_magic": 42,
"network_id": 1 "network_id": 0
}, },
"result": { "result": {
"expected_address": "2657WMsDfac7hr1ioJGr6g7r6JRx4r1My8Rj91tcPTeVjJDpfBYKURrPG2zVLx2Sq" "expected_address": "2657WMsDfac7hr1ioJGr6g7r6JRx4r1My8Rj91tcPTeVjJDpfBYKURrPG2zVLx2Sq"

@ -46,7 +46,7 @@
"path": "m/44'/1815'/0'/0/0", "path": "m/44'/1815'/0'/0/0",
"address_type": "byron", "address_type": "byron",
"protocol_magic": 42, "protocol_magic": 42,
"network_id": 1 "network_id": 0
}, },
"result": { "result": {
"expected_address": "2657WMsDfac7SH1rhA2PWBggGAPrKyLt1r9SL9gajPxxcH15ZxuCUb4aK9mQ9w7dU" "expected_address": "2657WMsDfac7SH1rhA2PWBggGAPrKyLt1r9SL9gajPxxcH15ZxuCUb4aK9mQ9w7dU"
@ -57,7 +57,7 @@
"path": "m/44'/1815'/0'/0/1", "path": "m/44'/1815'/0'/0/1",
"address_type": "byron", "address_type": "byron",
"protocol_magic": 42, "protocol_magic": 42,
"network_id": 1 "network_id": 0
}, },
"result": { "result": {
"expected_address": "2657WMsDfac6Cmfg4Varph2qyLKGi2K9E8jrtvjHVzfSjmbTMGy5sY3HpxCKsmtDA" "expected_address": "2657WMsDfac6Cmfg4Varph2qyLKGi2K9E8jrtvjHVzfSjmbTMGy5sY3HpxCKsmtDA"
@ -68,7 +68,7 @@
"path": "m/44'/1815'/0'/0/2", "path": "m/44'/1815'/0'/0/2",
"address_type": "byron", "address_type": "byron",
"protocol_magic": 42, "protocol_magic": 42,
"network_id": 1 "network_id": 0
}, },
"result": { "result": {
"expected_address": "2657WMsDfac5ANb5Mw6Rbgdz6nvs2Tu675vGbbVSzXQbAkQuMWtqBvEeKTrHNtXY7" "expected_address": "2657WMsDfac5ANb5Mw6Rbgdz6nvs2Tu675vGbbVSzXQbAkQuMWtqBvEeKTrHNtXY7"

@ -22,7 +22,7 @@
"address_type": "base", "address_type": "base",
"staking_path": "m/1852'/1815'/4'/2/0", "staking_path": "m/1852'/1815'/4'/2/0",
"network_id": 0, "network_id": 0,
"protocol_magic": 764824073 "protocol_magic": 42
}, },
"result": { "result": {
"expected_address": "addr_test1qrv42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wnrqua2vw243tmjfjt0h5wsru6appuz8c0pfd75ur7myyeqnsc9fs" "expected_address": "addr_test1qrv42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wnrqua2vw243tmjfjt0h5wsru6appuz8c0pfd75ur7myyeqnsc9fs"

@ -22,7 +22,7 @@
"address_type": "base", "address_type": "base",
"staking_key_hash": "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff", "staking_key_hash": "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff",
"network_id": 0, "network_id": 0,
"protocol_magic": 764824073 "protocol_magic": 42
}, },
"result": { "result": {
"expected_address": "addr_test1qrv42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wsmcs5wgus8qt4atk45lvt4xfxpjtwfhdmvchdf2m3u3hls8m96xf" "expected_address": "addr_test1qrv42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wsmcs5wgus8qt4atk45lvt4xfxpjtwfhdmvchdf2m3u3hls8m96xf"
@ -46,7 +46,7 @@
"address_type": "base", "address_type": "base",
"staking_key_hash": "122a946b9ad3d2ddf029d3a828f0468aece76895f15c9efbd69b4277", "staking_key_hash": "122a946b9ad3d2ddf029d3a828f0468aece76895f15c9efbd69b4277",
"network_id": 0, "network_id": 0,
"protocol_magic": 764824073 "protocol_magic": 42
}, },
"result": { "result": {
"expected_address": "addr_test1qzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92sj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsu8d9w5" "expected_address": "addr_test1qzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92sj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsu8d9w5"
@ -58,7 +58,7 @@
"address_type": "base", "address_type": "base",
"staking_key_hash": "122a946b9ad3d2ddf029d3a828f0468aece76895f15c9efbd69b4277", "staking_key_hash": "122a946b9ad3d2ddf029d3a828f0468aece76895f15c9efbd69b4277",
"network_id": 0, "network_id": 0,
"protocol_magic": 764824073 "protocol_magic": 42
}, },
"result": { "result": {
"expected_address": "addr_test1qrv42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wsj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsvvdk2q" "expected_address": "addr_test1qrv42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wsj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsvvdk2q"

@ -22,7 +22,7 @@
"address_type": "enterprise", "address_type": "enterprise",
"staking_key_hash": "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff", "staking_key_hash": "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff",
"network_id": 0, "network_id": 0,
"protocol_magic": 764824073 "protocol_magic": 42
}, },
"result": { "result": {
"expected_address": "addr_test1vzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92s8k2y47" "expected_address": "addr_test1vzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92s8k2y47"

@ -26,7 +26,7 @@
"tx_index": 177, "tx_index": 177,
"certificate_index": 42, "certificate_index": 42,
"network_id": 0, "network_id": 0,
"protocol_magic": 764824073 "protocol_magic": 42
}, },
"result": { "result": {
"expected_address": "addr_test1gzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z925ph3wczvf2ag2x9t" "expected_address": "addr_test1gzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z925ph3wczvf2ag2x9t"

@ -20,7 +20,7 @@
"path": "m/1852'/1815'/0'/2/0", "path": "m/1852'/1815'/0'/2/0",
"address_type": "reward", "address_type": "reward",
"network_id": 0, "network_id": 0,
"protocol_magic": 764824073 "protocol_magic": 42
}, },
"result": { "result": {
"expected_address": "stake_test1uqfz49rtntfa9h0s98f6s28sg69weemgjhc4e8hm66d5yac643znq" "expected_address": "stake_test1uqfz49rtntfa9h0s98f6s28sg69weemgjhc4e8hm66d5yac643znq"

@ -13,6 +13,7 @@ from .layout import (
show_warning_address_foreign_staking_key, show_warning_address_foreign_staking_key,
show_warning_address_pointer, show_warning_address_pointer,
) )
from .sign_tx import validate_network_info
if False: if False:
from trezor.messages import CardanoAddressParametersType, CardanoGetAddress from trezor.messages import CardanoAddressParametersType, CardanoGetAddress
@ -28,6 +29,8 @@ async def get_address(
ctx, validate_full_path, keychain, address_parameters.address_n, CURVE ctx, validate_full_path, keychain, address_parameters.address_n, CURVE
) )
validate_network_info(msg.network_id, msg.protocol_magic)
try: try:
address = derive_human_readable_address( address = derive_human_readable_address(
keychain, address_parameters, msg.protocol_magic, msg.network_id keychain, address_parameters, msg.protocol_magic, msg.network_id
@ -54,9 +57,9 @@ async def _display_address(
) -> None: ) -> None:
await _show_staking_warnings(ctx, keychain, address_parameters) await _show_staking_warnings(ctx, keychain, address_parameters)
network = None network_name = None
if not protocol_magics.is_mainnet(protocol_magic): if not protocol_magics.is_mainnet(protocol_magic):
network = protocol_magic network_name = protocol_magics.to_ui_string(protocol_magic)
while True: while True:
if await show_address( if await show_address(
@ -64,7 +67,7 @@ async def _display_address(
address, address,
address_parameters.address_type, address_parameters.address_type,
address_parameters.address_n, address_parameters.address_n,
network=network, network=network_name,
): ):
break break
if await show_qr( if await show_qr(

@ -193,7 +193,7 @@ async def show_address(
address: str, address: str,
address_type: EnumTypeCardanoAddressType, address_type: EnumTypeCardanoAddressType,
path: List[int], path: List[int],
network: int = None, network: str = None,
) -> bool: ) -> bool:
""" """
Custom show_address function is needed because cardano addresses don't Custom show_address function is needed because cardano addresses don't
@ -204,28 +204,28 @@ async def show_address(
t1 = Text(address_type_label, ui.ICON_RECEIVE, ui.GREEN) t1 = Text(address_type_label, ui.ICON_RECEIVE, ui.GREEN)
lines_per_page = 5 lines_per_page = 5
first_page_lines_used = 0 lines_used_on_first_page = 0
# assemble first page to be displayed (path + network + whatever part of the address fits) # assemble first page to be displayed (path + network + whatever part of the address fits)
if network is not None: if network is not None:
t1.normal("%s network" % protocol_magics.to_ui_string(network)) t1.normal("%s network" % network)
first_page_lines_used += 1 lines_used_on_first_page += 1
path_str = address_n_to_str(path) path_str = address_n_to_str(path)
t1.mono(path_str) t1.mono(path_str)
first_page_lines_used = min( lines_used_on_first_page = min(
first_page_lines_used + math.ceil(len(path_str) / _MAX_MONO_LINE), lines_used_on_first_page + math.ceil(len(path_str) / _MAX_MONO_LINE),
lines_per_page, lines_per_page,
) )
address_lines = list(chunks(address, 17)) address_lines = list(chunks(address, 17))
for address_line in address_lines[: lines_per_page - first_page_lines_used]: for address_line in address_lines[: lines_per_page - lines_used_on_first_page]:
t1.bold(address_line) t1.bold(address_line)
# append remaining pages containing the rest of the address # append remaining pages containing the rest of the address
pages = [t1] + _paginate_lines( pages = [t1] + _paginate_lines(
address_lines, address_lines,
lines_per_page - first_page_lines_used, lines_per_page - lines_used_on_first_page,
address_type_label, address_type_label,
ui.ICON_RECEIVE, ui.ICON_RECEIVE,
lines_per_page, lines_per_page,

@ -72,7 +72,7 @@ async def sign_tx(
if msg.fee > LOVELACE_MAX_SUPPLY: if msg.fee > LOVELACE_MAX_SUPPLY:
raise wire.ProcessError("Fee is out of range!") raise wire.ProcessError("Fee is out of range!")
_validate_network_info(msg.network_id, msg.protocol_magic) validate_network_info(msg.network_id, msg.protocol_magic)
for i in msg.inputs: for i in msg.inputs:
await validate_path(ctx, validate_full_path, keychain, i.address_n, CURVE) await validate_path(ctx, validate_full_path, keychain, i.address_n, CURVE)
@ -97,7 +97,7 @@ async def sign_tx(
return tx return tx
def _validate_network_info(network_id: int, protocol_magic: int) -> None: def validate_network_info(network_id: int, protocol_magic: int) -> None:
""" """
We are only concerned about checking that both network_id and protocol_magic We are only concerned about checking that both network_id and protocol_magic
belong to the mainnet or that both belong to a testnet. We don't need to check for belong to the mainnet or that both belong to a testnet. We don't need to check for

Loading…
Cancel
Save