2018-06-21 14:28:34 +00:00
|
|
|
# This file is part of the Trezor project.
|
2017-01-03 18:40:05 +00:00
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2017-01-03 18:40:05 +00:00
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
2018-06-21 14:28:34 +00:00
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
2017-01-03 18:40:05 +00:00
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
#
|
2018-06-21 14:28:34 +00:00
|
|
|
# You should have received a copy of the License along with this library.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
2017-01-03 18:40:05 +00:00
|
|
|
|
2024-11-12 13:32:26 +00:00
|
|
|
from typing import Optional
|
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
import pytest
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
from trezorlib import btc, messages
|
2024-12-02 14:49:04 +00:00
|
|
|
from trezorlib.debuglink import SessionDebugWrapper as Session
|
2018-08-13 16:21:24 +00:00
|
|
|
from trezorlib.tools import H_, parse_path
|
|
|
|
|
2021-11-29 11:00:01 +00:00
|
|
|
from ... import bip32
|
2024-03-09 21:05:05 +00:00
|
|
|
from ...common import MNEMONIC12, is_core
|
2024-05-21 21:49:08 +00:00
|
|
|
from ...input_flows import InputFlowConfirmAllWarnings
|
2024-11-13 15:05:42 +00:00
|
|
|
from .signtx import (
|
|
|
|
forge_prevtx,
|
|
|
|
request_finished,
|
|
|
|
request_input,
|
|
|
|
request_meta,
|
|
|
|
request_output,
|
|
|
|
)
|
2018-07-03 15:26:22 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
B = messages.ButtonRequestType
|
2020-03-26 14:58:44 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
pytestmark = [pytest.mark.multisig, pytest.mark.setup_client(mnemonic=MNEMONIC12)]
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
|
|
|
|
NODE_EXT1 = bip32.deserialize(
|
|
|
|
"xpub69qexv5TppjJQtXwSGeGXNtgGWyUzvsHACMt4Rr61Be4CmCf55eFcuXX828aySNuNR7hQYUCvUgZpioNxfs2HTAZWUUSFywhErg7JfTPv3Y"
|
|
|
|
)
|
|
|
|
# m/1 => 02c0d0c5fee952620757c6128dbf327c996cd72ed3358d15d6518a1186099bc15e
|
|
|
|
# m/2 => 0375b9dfaad928ce1a7eed88df7c084e67d99e9ab74332419458a9a45779706801
|
|
|
|
|
|
|
|
NODE_EXT2 = bip32.deserialize(
|
|
|
|
"xpub69qexv5TppjJRiLLK2K1FZNCFcErkXprCo3jabCXMiqX5CFF4LHedwcXvXkTuBL9tFLWVxuGWrdeerXjiWpC1gynTNUaySDsr8SU5xMpj5R"
|
|
|
|
)
|
|
|
|
# m/1 => 0388460dc439f4c8f5bcfc268c36e11b4375cad5c3535c336cfdf8c32c3afad5c1
|
|
|
|
# m/2 => 03a04f945d5a3685729dde697d574076de4bdf38e904f813b22a851548e1110fc0
|
|
|
|
|
|
|
|
NODE_EXT3 = bip32.deserialize(
|
|
|
|
"xpub69qexv5TppjJVYtxFKSBFxcVGyaC8VJDa1RugAYwEDLVUBuaXrVgznvQB44piM8MRerfVf1pNCBK1L1NzhyKd4Ay25BVZX3S8twWfZDxmz7"
|
|
|
|
)
|
|
|
|
# m/1 => 02e0c21e2a7cf00b94c5421725acff97f9826598b91f2340c5ddda730caca7d648
|
|
|
|
# m/2 => 03928301ffb8c0d7a364b794914c716ba3107cc78a6fe581028b0d8638b22e8573
|
|
|
|
|
|
|
|
NODE_INT = bip32.deserialize(
|
|
|
|
"xpub69qexv5TppjJNEK5bfX8vQ6ASXDUQ5PohSajrHgeknHZ4SJipn7edmpRmiiBLLDtPur71mekZFazhgas8rkUMnS7quk5qp64TLLV8ShrxZJ"
|
|
|
|
)
|
|
|
|
# m/1 => 03f91460d79e4e463d7d90cb75254bcd62b515a99a950574c721efdc5f711dff35
|
|
|
|
# m/2 => 038caebd6f753bbbd2bb1f3346a43cd32140648583673a31d62f2dfb56ad0ab9e3
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig_in1 = messages.MultisigRedeemScriptType(
|
2024-11-07 13:06:09 +00:00
|
|
|
nodes=[NODE_EXT1, NODE_EXT2, NODE_INT],
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[0, 0],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig_in2 = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes=[NODE_EXT1, NODE_EXT2, NODE_INT],
|
|
|
|
address_n=[0, 1],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig_in3 = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes=[NODE_EXT1, NODE_EXT3, NODE_INT],
|
|
|
|
address_n=[0, 1],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
|
|
|
|
2024-11-13 15:05:42 +00:00
|
|
|
prev_hash_1, prev_tx_1 = forge_prevtx(
|
2024-11-07 13:06:09 +00:00
|
|
|
[("3Ltgk5WPUMLcT2QvwRXKj9CWsYuAKqeHJ8", 50_000_000)]
|
2024-11-13 15:05:42 +00:00
|
|
|
)
|
2021-11-10 21:28:11 +00:00
|
|
|
INP1 = messages.TxInputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[H_(45), 0, 0, 0],
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=50_000_000,
|
2024-11-13 15:05:42 +00:00
|
|
|
prev_hash=prev_hash_1,
|
|
|
|
prev_index=0,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDMULTISIG,
|
2021-11-10 21:19:53 +00:00
|
|
|
multisig=multisig_in1,
|
|
|
|
)
|
|
|
|
|
2024-11-13 15:05:42 +00:00
|
|
|
prev_hash_2, prev_tx_2 = forge_prevtx(
|
|
|
|
[("3Md42fbNjSH3qwnj5jDvT6CSzJKVXHiXSc", 34_500_000)]
|
|
|
|
)
|
2021-11-10 21:28:11 +00:00
|
|
|
INP2 = messages.TxInputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[H_(45), 0, 0, 1],
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=34_500_000,
|
2024-11-13 15:05:42 +00:00
|
|
|
prev_hash=prev_hash_2,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_index=0,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDMULTISIG,
|
2021-11-10 21:19:53 +00:00
|
|
|
multisig=multisig_in2,
|
|
|
|
)
|
|
|
|
|
2024-11-13 15:05:42 +00:00
|
|
|
prev_hash_3, prev_tx_3 = forge_prevtx(
|
|
|
|
[("35PBSvszuvxhEDypGYcUhEQDigvKY8C5Rc", 55_500_000)]
|
|
|
|
)
|
2021-11-10 21:28:11 +00:00
|
|
|
INP3 = messages.TxInputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[H_(45), 0, 0, 1],
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=55_500_000,
|
2024-11-13 15:05:42 +00:00
|
|
|
prev_hash=prev_hash_3,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_index=0,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDMULTISIG,
|
2021-11-10 21:19:53 +00:00
|
|
|
multisig=multisig_in3,
|
|
|
|
)
|
|
|
|
|
2024-11-13 15:05:42 +00:00
|
|
|
TX_API = {prev_hash_1: prev_tx_1, prev_hash_2: prev_tx_2, prev_hash_3: prev_tx_3}
|
|
|
|
|
2021-11-29 11:00:01 +00:00
|
|
|
|
2022-10-25 13:08:19 +00:00
|
|
|
def _responses(
|
2024-12-02 14:49:04 +00:00
|
|
|
session: Session,
|
2022-10-25 13:08:19 +00:00
|
|
|
INP1: messages.TxInputType,
|
|
|
|
INP2: messages.TxInputType,
|
2024-11-12 13:32:26 +00:00
|
|
|
change_indices: Optional[list[int]] = None,
|
|
|
|
foreign_indices: Optional[list[int]] = None,
|
2022-10-25 13:08:19 +00:00
|
|
|
):
|
2024-11-12 13:32:26 +00:00
|
|
|
if change_indices is None:
|
|
|
|
change_indices = []
|
|
|
|
if foreign_indices is None:
|
|
|
|
foreign_indices = []
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
resp = [
|
|
|
|
request_input(0),
|
|
|
|
request_input(1),
|
|
|
|
request_output(0),
|
|
|
|
]
|
2022-09-22 11:20:58 +00:00
|
|
|
|
2024-11-12 13:32:26 +00:00
|
|
|
if 1 in foreign_indices:
|
|
|
|
resp.append(messages.ButtonRequest(code=B.UnknownDerivationPath))
|
|
|
|
if 1 not in change_indices:
|
2021-11-10 21:28:11 +00:00
|
|
|
resp.append(messages.ButtonRequest(code=B.ConfirmOutput))
|
2024-12-02 14:49:04 +00:00
|
|
|
if is_core(session):
|
2022-10-25 13:08:19 +00:00
|
|
|
resp.append(messages.ButtonRequest(code=B.ConfirmOutput))
|
2022-09-22 11:20:58 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
resp.append(request_output(1))
|
2022-09-22 11:20:58 +00:00
|
|
|
|
2024-11-12 13:32:26 +00:00
|
|
|
if 2 in foreign_indices:
|
|
|
|
resp.append(messages.ButtonRequest(code=B.UnknownDerivationPath))
|
|
|
|
if 2 not in change_indices:
|
2021-11-10 21:28:11 +00:00
|
|
|
resp.append(messages.ButtonRequest(code=B.ConfirmOutput))
|
2024-12-02 14:49:04 +00:00
|
|
|
if is_core(session):
|
2022-10-25 13:08:19 +00:00
|
|
|
resp.append(messages.ButtonRequest(code=B.ConfirmOutput))
|
2022-09-22 11:20:58 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
resp += [
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.ButtonRequest(code=B.SignTx),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_input(0),
|
|
|
|
request_meta(INP1.prev_hash),
|
|
|
|
request_input(0, INP1.prev_hash),
|
|
|
|
request_output(0, INP1.prev_hash),
|
|
|
|
request_input(1),
|
|
|
|
request_meta(INP2.prev_hash),
|
|
|
|
request_input(0, INP2.prev_hash),
|
|
|
|
request_output(0, INP2.prev_hash),
|
|
|
|
request_input(0),
|
|
|
|
request_input(1),
|
|
|
|
request_output(0),
|
|
|
|
request_output(1),
|
|
|
|
request_input(0),
|
|
|
|
request_input(1),
|
|
|
|
request_output(0),
|
|
|
|
request_output(1),
|
|
|
|
request_output(0),
|
|
|
|
request_output(1),
|
|
|
|
request_finished(),
|
|
|
|
]
|
|
|
|
return resp
|
|
|
|
|
|
|
|
|
|
|
|
# both outputs are external
|
2024-12-02 14:49:04 +00:00
|
|
|
def test_external_external(session: Session):
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="1F8yBZB2NZhPZvJekhjTwjhQRRvQeTjjXr",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="1H7uXJQTVwXca2BXF2opTrvuZapk8Cm8zY",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=44_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2024-12-02 14:49:04 +00:00
|
|
|
with session:
|
|
|
|
session.set_expected_responses(_responses(session, INP1, INP2))
|
2024-11-13 15:05:42 +00:00
|
|
|
btc.sign_tx(
|
2024-12-02 14:49:04 +00:00
|
|
|
session,
|
2021-11-10 21:19:53 +00:00
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP2],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# first external, second internal
|
2024-12-02 14:49:04 +00:00
|
|
|
def test_external_internal(session: Session):
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="1F8yBZB2NZhPZvJekhjTwjhQRRvQeTjjXr",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2022-01-31 12:25:30 +00:00
|
|
|
address_n=parse_path("m/45h/0/1/1"),
|
|
|
|
amount=44_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2024-12-02 14:49:04 +00:00
|
|
|
with session, session.client as client:
|
|
|
|
session.set_expected_responses(
|
2024-10-25 11:40:19 +00:00
|
|
|
_responses(
|
2024-12-02 14:49:04 +00:00
|
|
|
session,
|
2024-10-25 11:40:19 +00:00
|
|
|
INP1,
|
|
|
|
INP2,
|
|
|
|
change_indices=[] if is_core(client) else [2],
|
|
|
|
foreign_indices=[2],
|
|
|
|
)
|
2022-09-22 11:20:58 +00:00
|
|
|
)
|
2024-12-02 14:49:04 +00:00
|
|
|
if is_core(session):
|
2024-05-21 21:49:08 +00:00
|
|
|
IF = InputFlowConfirmAllWarnings(client)
|
|
|
|
client.set_input_flow(IF.get())
|
2024-11-13 15:05:42 +00:00
|
|
|
btc.sign_tx(
|
2024-12-02 14:49:04 +00:00
|
|
|
session,
|
2021-11-10 21:19:53 +00:00
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP2],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# first internal, second external
|
2024-12-02 14:49:04 +00:00
|
|
|
def test_internal_external(session: Session):
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2022-01-31 12:25:30 +00:00
|
|
|
address_n=parse_path("m/45h/0/1/0"),
|
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="1H7uXJQTVwXca2BXF2opTrvuZapk8Cm8zY",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=44_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
|
|
|
|
2024-12-02 14:49:04 +00:00
|
|
|
with session, session.client as client:
|
|
|
|
session.set_expected_responses(
|
2024-10-25 11:40:19 +00:00
|
|
|
_responses(
|
2024-12-02 14:49:04 +00:00
|
|
|
session,
|
2024-10-25 11:40:19 +00:00
|
|
|
INP1,
|
|
|
|
INP2,
|
|
|
|
change_indices=[] if is_core(client) else [1],
|
|
|
|
foreign_indices=[1],
|
|
|
|
)
|
2022-09-22 11:20:58 +00:00
|
|
|
)
|
2024-12-02 14:49:04 +00:00
|
|
|
if is_core(session):
|
2024-05-21 21:49:08 +00:00
|
|
|
IF = InputFlowConfirmAllWarnings(client)
|
|
|
|
client.set_input_flow(IF.get())
|
2024-11-13 15:05:42 +00:00
|
|
|
btc.sign_tx(
|
2024-12-02 14:49:04 +00:00
|
|
|
session,
|
2021-11-10 21:19:53 +00:00
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP2],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# both outputs are external
|
2024-12-02 14:49:04 +00:00
|
|
|
def test_multisig_external_external(session: Session):
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="3B23k4kFBRtu49zvpG3Z9xuFzfpHvxBcwt",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="3PkXLsY7AUZCrCKGvX8FfP2EawowUBMbcg",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=44_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2024-12-02 14:49:04 +00:00
|
|
|
with session:
|
|
|
|
session.set_expected_responses(_responses(session, INP1, INP2))
|
2024-11-13 15:05:42 +00:00
|
|
|
btc.sign_tx(
|
2024-12-02 14:49:04 +00:00
|
|
|
session,
|
2021-11-10 21:19:53 +00:00
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP2],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
# inputs match, change matches (first is change)
|
2024-12-02 14:49:04 +00:00
|
|
|
def test_multisig_change_match_first(session: Session):
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig_out1 = messages.MultisigRedeemScriptType(
|
2024-11-13 15:05:42 +00:00
|
|
|
nodes=[NODE_EXT1, NODE_EXT2, NODE_INT],
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[1, 0],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[H_(45), 0, 1, 0],
|
|
|
|
multisig=multisig_out1,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOMULTISIG,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="3PkXLsY7AUZCrCKGvX8FfP2EawowUBMbcg",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=44_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2024-12-02 14:49:04 +00:00
|
|
|
with session:
|
|
|
|
session.set_expected_responses(
|
|
|
|
_responses(session, INP1, INP2, change_indices=[1])
|
2024-11-12 13:32:26 +00:00
|
|
|
)
|
2024-11-13 15:05:42 +00:00
|
|
|
btc.sign_tx(
|
2024-12-02 14:49:04 +00:00
|
|
|
session,
|
2021-11-10 21:19:53 +00:00
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP2],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
# inputs match, change matches (second is change)
|
2024-12-02 14:49:04 +00:00
|
|
|
def test_multisig_change_match_second(session: Session):
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig_out2 = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes=[NODE_EXT1, NODE_EXT2, NODE_INT],
|
|
|
|
address_n=[1, 1],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="3B23k4kFBRtu49zvpG3Z9xuFzfpHvxBcwt",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[H_(45), 0, 1, 1],
|
|
|
|
multisig=multisig_out2,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=44_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOMULTISIG,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2024-12-02 14:49:04 +00:00
|
|
|
with session:
|
|
|
|
session.set_expected_responses(
|
|
|
|
_responses(session, INP1, INP2, change_indices=[2])
|
2024-11-12 13:32:26 +00:00
|
|
|
)
|
2024-11-13 15:05:42 +00:00
|
|
|
btc.sign_tx(
|
2024-12-02 14:49:04 +00:00
|
|
|
session,
|
2021-11-10 21:19:53 +00:00
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP2],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
# inputs match, change mismatches (second tries to be change but isn't)
|
2024-12-02 14:49:04 +00:00
|
|
|
def test_multisig_mismatch_multisig_change(session: Session):
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig_out2 = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes=[NODE_EXT1, NODE_INT, NODE_EXT3],
|
|
|
|
address_n=[1, 0],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="3B23k4kFBRtu49zvpG3Z9xuFzfpHvxBcwt",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[H_(45), 0, 1, 0],
|
|
|
|
multisig=multisig_out2,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=44_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOMULTISIG,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2024-12-02 14:49:04 +00:00
|
|
|
with session:
|
|
|
|
session.set_expected_responses(_responses(session, INP1, INP2))
|
2024-10-23 14:47:15 +00:00
|
|
|
btc.sign_tx(
|
2024-12-02 14:49:04 +00:00
|
|
|
session,
|
2024-10-23 14:47:15 +00:00
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP2],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
# inputs match, change mismatches (second tries to be change but isn't)
|
|
|
|
@pytest.mark.models(skip="legacy", reason="Not fixed")
|
2024-12-02 14:49:04 +00:00
|
|
|
def test_multisig_mismatch_multisig_change_different_paths(session: Session):
|
2024-10-23 14:47:15 +00:00
|
|
|
multisig_out2 = messages.MultisigRedeemScriptType(
|
|
|
|
pubkeys=[
|
|
|
|
messages.HDNodePathType(node=NODE_EXT1, address_n=[1, 0]),
|
|
|
|
messages.HDNodePathType(node=NODE_EXT2, address_n=[1, 1]),
|
|
|
|
messages.HDNodePathType(node=NODE_INT, address_n=[1, 2]),
|
|
|
|
],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
|
|
|
|
|
|
|
out1 = messages.TxOutputType(
|
|
|
|
address="3B23k4kFBRtu49zvpG3Z9xuFzfpHvxBcwt",
|
|
|
|
amount=40_000_000,
|
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
|
|
|
)
|
|
|
|
|
|
|
|
out2 = messages.TxOutputType(
|
|
|
|
address_n=[H_(45), 0, 1, 2],
|
|
|
|
multisig=multisig_out2,
|
|
|
|
amount=44_000_000,
|
|
|
|
script_type=messages.OutputScriptType.PAYTOMULTISIG,
|
|
|
|
)
|
|
|
|
|
2024-12-02 14:49:04 +00:00
|
|
|
with session:
|
|
|
|
session.set_expected_responses(_responses(session, INP1, INP2))
|
2024-11-13 15:05:42 +00:00
|
|
|
btc.sign_tx(
|
2024-12-02 14:49:04 +00:00
|
|
|
session,
|
2021-11-10 21:19:53 +00:00
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP2],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
2017-06-23 19:31:42 +00:00
|
|
|
)
|
|
|
|
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
# inputs mismatch, change matches with first input
|
2024-12-02 14:49:04 +00:00
|
|
|
def test_multisig_mismatch_inputs(session: Session):
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig_out1 = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes=[NODE_EXT2, NODE_EXT1, NODE_INT],
|
|
|
|
address_n=[1, 0],
|
|
|
|
signatures=[b"", b"", b""],
|
|
|
|
m=2,
|
|
|
|
)
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=[H_(45), 0, 1, 0],
|
|
|
|
multisig=multisig_out1,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=40_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOMULTISIG,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2017-06-23 19:31:42 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="3PkXLsY7AUZCrCKGvX8FfP2EawowUBMbcg",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=65_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2014-12-20 17:23:03 +00:00
|
|
|
|
2024-12-02 14:49:04 +00:00
|
|
|
with session:
|
|
|
|
session.set_expected_responses(_responses(session, INP1, INP3))
|
2024-11-13 15:05:42 +00:00
|
|
|
btc.sign_tx(
|
2024-12-02 14:49:04 +00:00
|
|
|
session,
|
2021-11-10 21:19:53 +00:00
|
|
|
"Bitcoin",
|
|
|
|
[INP1, INP3],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|