2018-06-21 14:28:34 +00:00
|
|
|
# This file is part of the Trezor project.
|
2017-12-18 10:55:41 +00:00
|
|
|
#
|
2019-05-29 16:44:09 +00:00
|
|
|
# Copyright (C) 2012-2019 SatoshiLabs and contributors
|
2017-12-18 10:55:41 +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-12-18 10:55:41 +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-12-18 10:55:41 +00:00
|
|
|
|
2018-08-13 16:21:24 +00:00
|
|
|
import pytest
|
2017-12-18 10:55:41 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
from trezorlib import btc, messages
|
2024-11-15 16:31:22 +00:00
|
|
|
from trezorlib.debuglink import SessionDebugWrapper as Session
|
2018-04-18 13:53:40 +00:00
|
|
|
from trezorlib.tools import parse_path
|
2017-12-18 10:55:41 +00:00
|
|
|
|
2024-03-09 21:05:05 +00:00
|
|
|
from ...common import is_core
|
2021-11-29 11:00:01 +00:00
|
|
|
from ...tx_cache import TxCache
|
2022-01-24 20:23:58 +00:00
|
|
|
from .signtx import request_finished, request_input, request_meta, request_output
|
2017-12-18 10:55:41 +00:00
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
B = messages.ButtonRequestType
|
2020-03-03 16:29:02 +00:00
|
|
|
TX_API = TxCache("Decred Testnet")
|
2018-08-13 16:21:24 +00:00
|
|
|
|
|
|
|
|
2022-01-24 20:23:58 +00:00
|
|
|
FAKE_TXHASH_4d8acd = bytes.fromhex(
|
|
|
|
"4d8acde26d5efc7f5df1b3cdada6b11027616520c883e09c919b88f0f0cb6410"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2022-01-24 20:23:58 +00:00
|
|
|
FAKE_TXHASH_f341fd = bytes.fromhex(
|
|
|
|
"f341fde6a78c2e150619d1c5ecbd90fabeb9e278024cc38ea4190d0b4a6d61d8"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2022-01-24 20:23:58 +00:00
|
|
|
FAKE_TXHASH_5f3a7d = bytes.fromhex(
|
|
|
|
"5f3a7d29623eba20788e967439c1ccf122688589dfc07cddcedd1b27dc14b568"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2022-01-24 20:23:58 +00:00
|
|
|
FAKE_TXHASH_9ac7d2 = bytes.fromhex(
|
|
|
|
"9ac7d222f4460ccf4ef38eee047eaf8b3a09505364afe4fe27b765e4c5508fd1"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2022-01-24 20:23:58 +00:00
|
|
|
FAKE_TXHASH_48f5b8 = bytes.fromhex(
|
|
|
|
"48f5b85f8b1cf796d0d07388ced491f154e2d26b0615529d2d6ba9c170542df3"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2022-12-23 07:38:57 +00:00
|
|
|
FAKE_TXHASH_8b6890 = bytes.fromhex(
|
|
|
|
"8b6890c10a3764fe6f378bc5b7e438148df176e9be1dde704ce866361149e254"
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2022-12-23 07:38:57 +00:00
|
|
|
FAKE_TXHASH_1f00fc = bytes.fromhex(
|
|
|
|
"1f00fc54530d7c4877f5032e91b6c507f6a1531861dede2ab134e5c0b5dfe8c8"
|
multi: Add decred staking.
Add two new input and four output script types.
Decred ticket purchases consist of a stake submission, op returns, and
change addresses. Although change addresses are allowed by consensus,
they are no longer used in practice and so have been given the
restrictions of a null pubkey and no value. Stake scripts are almost
identical to p2pkh or p2sh except for an extra opcode in front. Inputs
are currently only used in the form of one input three outputs with the
first output, or stake submission, paying to a public key hash, or with
two inputs and five outputs with the stake submission paying to a
multisig script hash. The op returns are directed to the user in the
case of one and the voting service provider and user in the case of two.
One of the sstx commitment for a ticket must pay back to the trezor
wallet. This is checked and an error is thrown if we don't find the
expected public key hash.
Because this adds the ability to create new types of outputs once the
ticket votes, two new input script types are also needed. A successful
vote will lead to a stake generation script that must be spent, and an
unsuccessful vote will lead to a revocation script that must be spent.
If we allowed stake change scripts to have a valid pubkey, that too
would require another op code, but we disallow those for output.
2020-09-26 09:30:56 +00:00
|
|
|
)
|
2017-12-18 10:55:41 +00:00
|
|
|
|
2024-03-09 21:05:05 +00:00
|
|
|
pytestmark = [
|
|
|
|
pytest.mark.altcoin,
|
|
|
|
pytest.mark.decred,
|
2024-09-02 11:01:16 +00:00
|
|
|
pytest.mark.models("t1b1", "t2t1"),
|
2024-03-09 21:05:05 +00:00
|
|
|
]
|
2021-11-10 21:19:53 +00:00
|
|
|
|
|
|
|
|
2024-11-15 16:31:22 +00:00
|
|
|
def test_send_decred(session: Session):
|
2022-01-24 20:23:58 +00:00
|
|
|
# NOTE: fake input tx used
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
inp1 = messages.TxInputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
# TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz
|
2022-01-31 12:25:30 +00:00
|
|
|
address_n=parse_path("m/44h/1h/0h/0/0"),
|
2022-01-24 20:23:58 +00:00
|
|
|
prev_hash=FAKE_TXHASH_4d8acd,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_index=1,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=200_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
decred_tree=0,
|
|
|
|
)
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=190_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
|
|
|
|
2024-11-15 16:31:22 +00:00
|
|
|
with session:
|
|
|
|
session.set_expected_responses(
|
2021-11-10 21:19:53 +00:00
|
|
|
[
|
|
|
|
request_input(0),
|
|
|
|
request_output(0),
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.ButtonRequest(code=B.ConfirmOutput),
|
2024-11-15 16:31:22 +00:00
|
|
|
(is_core(session), messages.ButtonRequest(code=B.ConfirmOutput)),
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.ButtonRequest(code=B.FeeOverThreshold),
|
|
|
|
messages.ButtonRequest(code=B.SignTx),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_input(0),
|
2022-01-24 20:23:58 +00:00
|
|
|
request_meta(FAKE_TXHASH_4d8acd),
|
|
|
|
request_input(0, FAKE_TXHASH_4d8acd),
|
|
|
|
request_output(0, FAKE_TXHASH_4d8acd),
|
|
|
|
request_output(1, FAKE_TXHASH_4d8acd),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_input(0),
|
|
|
|
request_finished(),
|
|
|
|
]
|
2017-12-18 10:55:41 +00:00
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
2024-11-15 16:31:22 +00:00
|
|
|
session, "Decred Testnet", [inp1], [out1], prev_txes=TX_API
|
2017-12-18 10:55:41 +00:00
|
|
|
)
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
serialized_tx.hex()
|
2022-01-24 20:23:58 +00:00
|
|
|
== "01000000011064cbf0f0889b919ce083c82065612710b1a6adcdb3f15d7ffc5e6de2cd8a4d0100000000ffffffff01802b530b0000000000001976a914819d291a2f7fbf770e784bfd78b5ce92c58e95ea88ac00000000000000000100c2eb0b0000000000000000ffffffff6a47304402202f77445fd8b2d47f6d28fa6087d4bc3ac6986904bf9009c41e527245905d21870220227f463d1dbfba492514e1ee78e32060bfdb4ca9251c4e0557c232e740515eb70121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0"
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-09-02 11:01:16 +00:00
|
|
|
@pytest.mark.models("core")
|
2024-11-15 16:31:22 +00:00
|
|
|
def test_purchase_ticket_decred(session: Session):
|
2022-01-24 20:23:58 +00:00
|
|
|
# NOTE: fake input tx used
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
inp1 = messages.TxInputType(
|
2022-01-31 12:25:30 +00:00
|
|
|
address_n=parse_path("m/44h/1h/0h/0/0"),
|
2022-01-24 20:23:58 +00:00
|
|
|
prev_hash=FAKE_TXHASH_4d8acd,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_index=1,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=200_000_000,
|
2021-11-10 21:19:53 +00:00
|
|
|
decred_tree=0,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz",
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=199_900_000,
|
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/44h/1h/0h/0/0"),
|
|
|
|
amount=200_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
2021-11-10 21:28:11 +00:00
|
|
|
out3 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="TsR28UZRprhgQQhzWns2M6cAwchrNVvbYq2",
|
|
|
|
amount=0,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
|
|
|
|
2024-11-15 16:31:22 +00:00
|
|
|
with session:
|
|
|
|
session.set_expected_responses(
|
2021-11-10 21:19:53 +00:00
|
|
|
[
|
|
|
|
request_input(0),
|
|
|
|
request_output(0),
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.ButtonRequest(code=B.ConfirmOutput),
|
2022-10-25 13:08:19 +00:00
|
|
|
messages.ButtonRequest(code=B.ConfirmOutput),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_output(1),
|
|
|
|
request_output(2),
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.ButtonRequest(code=B.SignTx),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_input(0),
|
2022-01-24 20:23:58 +00:00
|
|
|
request_meta(FAKE_TXHASH_4d8acd),
|
|
|
|
request_input(0, FAKE_TXHASH_4d8acd),
|
|
|
|
request_output(0, FAKE_TXHASH_4d8acd),
|
|
|
|
request_output(1, FAKE_TXHASH_4d8acd),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_input(0),
|
|
|
|
request_finished(),
|
|
|
|
]
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
2024-11-15 16:31:22 +00:00
|
|
|
session,
|
2021-11-10 21:19:53 +00:00
|
|
|
"Decred Testnet",
|
|
|
|
[inp1],
|
|
|
|
[out1, out2, out3],
|
|
|
|
prev_txes=TX_API,
|
|
|
|
decred_staking_ticket=True,
|
multi: Add decred staking.
Add two new input and four output script types.
Decred ticket purchases consist of a stake submission, op returns, and
change addresses. Although change addresses are allowed by consensus,
they are no longer used in practice and so have been given the
restrictions of a null pubkey and no value. Stake scripts are almost
identical to p2pkh or p2sh except for an extra opcode in front. Inputs
are currently only used in the form of one input three outputs with the
first output, or stake submission, paying to a public key hash, or with
two inputs and five outputs with the stake submission paying to a
multisig script hash. The op returns are directed to the user in the
case of one and the voting service provider and user in the case of two.
One of the sstx commitment for a ticket must pay back to the trezor
wallet. This is checked and an error is thrown if we don't find the
expected public key hash.
Because this adds the ability to create new types of outputs once the
ticket votes, two new input script types are also needed. A successful
vote will lead to a stake generation script that must be spent, and an
unsuccessful vote will lead to a revocation script that must be spent.
If we allowed stake change scripts to have a valid pubkey, that too
would require another op code, but we disallow those for output.
2020-09-26 09:30:56 +00:00
|
|
|
)
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
serialized_tx.hex()
|
2022-01-24 20:23:58 +00:00
|
|
|
== "01000000011064cbf0f0889b919ce083c82065612710b1a6adcdb3f15d7ffc5e6de2cd8a4d0100000000ffffffff03603bea0b0000000000001aba76a914819d291a2f7fbf770e784bfd78b5ce92c58e95ea88ac00000000000000000000206a1edc1a98d791735eb9a8715a2a219c23680edcedad00c2eb0b000000000058000000000000000000001abd76a914000000000000000000000000000000000000000088ac00000000000000000100c2eb0b0000000000000000ffffffff6b483045022100b3a11ff4befcc035623de7665aaa76dacc9252e53aabf2a5d61238151e696532022004cbcc537c1d539e04c823140bac4524bdba09f528f5c4b76f3f1022b7dc0ad40121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0"
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-09-02 11:01:16 +00:00
|
|
|
@pytest.mark.models("core")
|
2024-11-15 16:31:22 +00:00
|
|
|
def test_spend_from_stake_generation_and_revocation_decred(session: Session):
|
2022-01-24 20:23:58 +00:00
|
|
|
# NOTE: fake input tx used
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
inp1 = messages.TxInputType(
|
2022-01-31 12:25:30 +00:00
|
|
|
address_n=parse_path("m/44h/1h/0h/0/0"),
|
2022-12-23 07:38:57 +00:00
|
|
|
prev_hash=FAKE_TXHASH_8b6890,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_index=2,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=200_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDADDRESS,
|
|
|
|
decred_staking_spend=messages.DecredStakingSpendType.SSGen,
|
2021-11-10 21:19:53 +00:00
|
|
|
decred_tree=1,
|
|
|
|
)
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
inp2 = messages.TxInputType(
|
2022-01-31 12:25:30 +00:00
|
|
|
address_n=parse_path("m/44h/1h/0h/0/0"),
|
2022-12-23 07:38:57 +00:00
|
|
|
prev_hash=FAKE_TXHASH_1f00fc,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_index=0,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=200_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDADDRESS,
|
|
|
|
decred_staking_spend=messages.DecredStakingSpendType.SSRTX,
|
2021-11-10 21:19:53 +00:00
|
|
|
decred_tree=1,
|
|
|
|
)
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=399_900_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
|
|
|
|
2024-11-15 16:31:22 +00:00
|
|
|
with session:
|
|
|
|
session.set_expected_responses(
|
2021-11-10 21:19:53 +00:00
|
|
|
[
|
|
|
|
request_input(0),
|
|
|
|
request_input(1),
|
|
|
|
request_output(0),
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.ButtonRequest(code=B.ConfirmOutput),
|
2024-11-15 16:31:22 +00:00
|
|
|
(is_core(session), messages.ButtonRequest(code=B.ConfirmOutput)),
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.ButtonRequest(code=B.SignTx),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_input(0),
|
2022-12-23 07:38:57 +00:00
|
|
|
request_meta(FAKE_TXHASH_8b6890),
|
|
|
|
request_input(0, FAKE_TXHASH_8b6890),
|
|
|
|
request_input(1, FAKE_TXHASH_8b6890),
|
|
|
|
request_output(0, FAKE_TXHASH_8b6890),
|
|
|
|
request_output(1, FAKE_TXHASH_8b6890),
|
|
|
|
request_output(2, FAKE_TXHASH_8b6890),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_input(1),
|
2022-12-23 07:38:57 +00:00
|
|
|
request_meta(FAKE_TXHASH_1f00fc),
|
|
|
|
request_input(0, FAKE_TXHASH_1f00fc),
|
|
|
|
request_output(0, FAKE_TXHASH_1f00fc),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_input(0),
|
|
|
|
request_input(1),
|
|
|
|
request_finished(),
|
|
|
|
]
|
multi: Add decred staking.
Add two new input and four output script types.
Decred ticket purchases consist of a stake submission, op returns, and
change addresses. Although change addresses are allowed by consensus,
they are no longer used in practice and so have been given the
restrictions of a null pubkey and no value. Stake scripts are almost
identical to p2pkh or p2sh except for an extra opcode in front. Inputs
are currently only used in the form of one input three outputs with the
first output, or stake submission, paying to a public key hash, or with
two inputs and five outputs with the stake submission paying to a
multisig script hash. The op returns are directed to the user in the
case of one and the voting service provider and user in the case of two.
One of the sstx commitment for a ticket must pay back to the trezor
wallet. This is checked and an error is thrown if we don't find the
expected public key hash.
Because this adds the ability to create new types of outputs once the
ticket votes, two new input script types are also needed. A successful
vote will lead to a stake generation script that must be spent, and an
unsuccessful vote will lead to a revocation script that must be spent.
If we allowed stake change scripts to have a valid pubkey, that too
would require another op code, but we disallow those for output.
2020-09-26 09:30:56 +00:00
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
2024-11-15 16:31:22 +00:00
|
|
|
session, "Decred Testnet", [inp1, inp2], [out1], prev_txes=TX_API
|
multi: Add decred staking.
Add two new input and four output script types.
Decred ticket purchases consist of a stake submission, op returns, and
change addresses. Although change addresses are allowed by consensus,
they are no longer used in practice and so have been given the
restrictions of a null pubkey and no value. Stake scripts are almost
identical to p2pkh or p2sh except for an extra opcode in front. Inputs
are currently only used in the form of one input three outputs with the
first output, or stake submission, paying to a public key hash, or with
two inputs and five outputs with the stake submission paying to a
multisig script hash. The op returns are directed to the user in the
case of one and the voting service provider and user in the case of two.
One of the sstx commitment for a ticket must pay back to the trezor
wallet. This is checked and an error is thrown if we don't find the
expected public key hash.
Because this adds the ability to create new types of outputs once the
ticket votes, two new input script types are also needed. A successful
vote will lead to a stake generation script that must be spent, and an
unsuccessful vote will lead to a revocation script that must be spent.
If we allowed stake change scripts to have a valid pubkey, that too
would require another op code, but we disallow those for output.
2020-09-26 09:30:56 +00:00
|
|
|
)
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
serialized_tx.hex()
|
2022-12-23 07:38:57 +00:00
|
|
|
== "010000000254e249113666e84c70de1dbee976f18d1438e4b7c58b376ffe64370ac190688b0200000001ffffffffc8e8dfb5c0e534b12adede611853a1f607c5b6912e03f577487c0d5354fc001f0000000001ffffffff0160fdd5170000000000001976a914819d291a2f7fbf770e784bfd78b5ce92c58e95ea88ac00000000000000000200c2eb0b0000000000000000ffffffff6b483045022100bdcb877c97d72db74eca06fefa21a7f7b00afcd5d916fce2155ed7df1ca5546102201e1f9efd7d652b449474c2c70171bfc4535544927bed62021f7334447d1ea4740121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd000c2eb0b0000000000000000ffffffff6a473044022030c5743c442bd696d19dcf73d54e95526e726de965c2e2b4b9fd70248eaae21d02201305a3bcc2bb0e33122277763990e3b48f317d61264a68d190fb8acfc004cc640121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0"
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-11-15 16:31:22 +00:00
|
|
|
def test_send_decred_change(session: Session):
|
2022-01-24 20:23:58 +00:00
|
|
|
# NOTE: fake input tx used
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
inp1 = messages.TxInputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
# TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz
|
2022-01-31 12:25:30 +00:00
|
|
|
address_n=parse_path("m/44h/1h/0h/0/0"),
|
2022-01-24 20:23:58 +00:00
|
|
|
prev_hash=FAKE_TXHASH_4d8acd,
|
|
|
|
prev_index=1,
|
|
|
|
amount=200_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
decred_tree=0,
|
|
|
|
)
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
inp2 = messages.TxInputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
# TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz
|
2022-01-31 12:25:30 +00:00
|
|
|
address_n=parse_path("m/44h/1h/0h/0/0"),
|
|
|
|
amount=200_000_000,
|
2022-01-24 20:23:58 +00:00
|
|
|
prev_hash=FAKE_TXHASH_f341fd,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_index=1,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
decred_tree=0,
|
|
|
|
)
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
inp3 = messages.TxInputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
# Tskt39YEvzoJ5KBDH4f1auNzG3jViVjZ2RV
|
2022-01-31 12:25:30 +00:00
|
|
|
address_n=parse_path("m/44h/1h/0h/0/1"),
|
|
|
|
amount=200_000_000,
|
2022-01-24 20:23:58 +00:00
|
|
|
prev_hash=FAKE_TXHASH_5f3a7d,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_index=0,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
decred_tree=0,
|
|
|
|
)
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="TsWjioPrP8E1TuTMmTrVMM2BA4iPrjQXBpR",
|
2022-01-24 20:23:58 +00:00
|
|
|
amount=499_975_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
# TsaSFRwfN9muW5F6ZX36iSksc9hruiC5F97
|
2022-01-31 12:25:30 +00:00
|
|
|
address_n=parse_path("m/44h/1h/0h/1/0"),
|
|
|
|
amount=100_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
|
|
|
|
2024-11-15 16:31:22 +00:00
|
|
|
with session:
|
|
|
|
session.set_expected_responses(
|
2021-11-10 21:19:53 +00:00
|
|
|
[
|
|
|
|
request_input(0),
|
|
|
|
request_input(1),
|
|
|
|
request_input(2),
|
|
|
|
request_output(0),
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.ButtonRequest(code=B.ConfirmOutput),
|
2024-11-15 16:31:22 +00:00
|
|
|
(is_core(session), messages.ButtonRequest(code=B.ConfirmOutput)),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_output(1),
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.ButtonRequest(code=B.SignTx),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_input(0),
|
2022-01-24 20:23:58 +00:00
|
|
|
request_meta(FAKE_TXHASH_4d8acd),
|
|
|
|
request_input(0, FAKE_TXHASH_4d8acd),
|
|
|
|
request_output(0, FAKE_TXHASH_4d8acd),
|
|
|
|
request_output(1, FAKE_TXHASH_4d8acd),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_input(1),
|
2022-01-24 20:23:58 +00:00
|
|
|
request_meta(FAKE_TXHASH_f341fd),
|
|
|
|
request_input(0, FAKE_TXHASH_f341fd),
|
|
|
|
request_output(0, FAKE_TXHASH_f341fd),
|
|
|
|
request_output(1, FAKE_TXHASH_f341fd),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_input(2),
|
2022-01-24 20:23:58 +00:00
|
|
|
request_meta(FAKE_TXHASH_5f3a7d),
|
|
|
|
request_input(0, FAKE_TXHASH_5f3a7d),
|
|
|
|
request_output(0, FAKE_TXHASH_5f3a7d),
|
|
|
|
request_output(1, FAKE_TXHASH_5f3a7d),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_input(0),
|
|
|
|
request_input(1),
|
|
|
|
request_input(2),
|
|
|
|
request_finished(),
|
|
|
|
]
|
multi: Add decred staking.
Add two new input and four output script types.
Decred ticket purchases consist of a stake submission, op returns, and
change addresses. Although change addresses are allowed by consensus,
they are no longer used in practice and so have been given the
restrictions of a null pubkey and no value. Stake scripts are almost
identical to p2pkh or p2sh except for an extra opcode in front. Inputs
are currently only used in the form of one input three outputs with the
first output, or stake submission, paying to a public key hash, or with
two inputs and five outputs with the stake submission paying to a
multisig script hash. The op returns are directed to the user in the
case of one and the voting service provider and user in the case of two.
One of the sstx commitment for a ticket must pay back to the trezor
wallet. This is checked and an error is thrown if we don't find the
expected public key hash.
Because this adds the ability to create new types of outputs once the
ticket votes, two new input script types are also needed. A successful
vote will lead to a stake generation script that must be spent, and an
unsuccessful vote will lead to a revocation script that must be spent.
If we allowed stake change scripts to have a valid pubkey, that too
would require another op code, but we disallow those for output.
2020-09-26 09:30:56 +00:00
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
_, serialized_tx = btc.sign_tx(
|
2024-11-15 16:31:22 +00:00
|
|
|
session,
|
2021-11-10 21:19:53 +00:00
|
|
|
"Decred Testnet",
|
|
|
|
[inp1, inp2, inp3],
|
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
multi: Add decred staking.
Add two new input and four output script types.
Decred ticket purchases consist of a stake submission, op returns, and
change addresses. Although change addresses are allowed by consensus,
they are no longer used in practice and so have been given the
restrictions of a null pubkey and no value. Stake scripts are almost
identical to p2pkh or p2sh except for an extra opcode in front. Inputs
are currently only used in the form of one input three outputs with the
first output, or stake submission, paying to a public key hash, or with
two inputs and five outputs with the stake submission paying to a
multisig script hash. The op returns are directed to the user in the
case of one and the voting service provider and user in the case of two.
One of the sstx commitment for a ticket must pay back to the trezor
wallet. This is checked and an error is thrown if we don't find the
expected public key hash.
Because this adds the ability to create new types of outputs once the
ticket votes, two new input script types are also needed. A successful
vote will lead to a stake generation script that must be spent, and an
unsuccessful vote will lead to a revocation script that must be spent.
If we allowed stake change scripts to have a valid pubkey, that too
would require another op code, but we disallow those for output.
2020-09-26 09:30:56 +00:00
|
|
|
)
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
serialized_tx.hex()
|
2022-01-24 20:23:58 +00:00
|
|
|
== "01000000031064cbf0f0889b919ce083c82065612710b1a6adcdb3f15d7ffc5e6de2cd8a4d0100000000ffffffffd8616d4a0b0d19a48ec34c0278e2b9befa90bdecc5d11906152e8ca7e6fd41f30100000000ffffffff68b514dc271bddcedd7cc0df89856822f1ccc13974968e7820ba3e62297d3a5f0000000000ffffffff025803cd1d0000000000001976a9143eb656115197956125365348c542e37b6d3d259988ac00e1f5050000000000001976a9143ee6f9d662e7be18373d80e5eb44627014c2bf6688ac00000000000000000300c2eb0b0000000000000000ffffffff6a47304402205eec688bd8d52908dae5fa29d121637b6d5c7df0246235a0dbab8170e3d0309e0220774560da627134cb1942a8cafd3926e67317af70287f0c8422468821ea4f78560121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd000c2eb0b0000000000000000ffffffff6a4730440220171d7840fee536f2c41e80bdcd9d2248eadfe32f51e0404582aa9ce8d7c31f5f022075c6fbb39394dd34a6271ada25a9e68dc26ddb46fa84962c40a11fafadf9e2fd0121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd000c2eb0b0000000000000000ffffffff6a47304402207121e3da42ec635e3ba9d5c4e7f4921c6acab87c60d58956f60d89eab69defa60220649c2d9a987407e259088e5ebebae289e4b8a82bc77850004978021561299fcc01210294e3e5e77e22eea0e4c0d30d89beb4db7f69b4bf1ae709e411d6a06618b8f852"
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|
multi: Add decred staking.
Add two new input and four output script types.
Decred ticket purchases consist of a stake submission, op returns, and
change addresses. Although change addresses are allowed by consensus,
they are no longer used in practice and so have been given the
restrictions of a null pubkey and no value. Stake scripts are almost
identical to p2pkh or p2sh except for an extra opcode in front. Inputs
are currently only used in the form of one input three outputs with the
first output, or stake submission, paying to a public key hash, or with
two inputs and five outputs with the stake submission paying to a
multisig script hash. The op returns are directed to the user in the
case of one and the voting service provider and user in the case of two.
One of the sstx commitment for a ticket must pay back to the trezor
wallet. This is checked and an error is thrown if we don't find the
expected public key hash.
Because this adds the ability to create new types of outputs once the
ticket votes, two new input script types are also needed. A successful
vote will lead to a stake generation script that must be spent, and an
unsuccessful vote will lead to a revocation script that must be spent.
If we allowed stake change scripts to have a valid pubkey, that too
would require another op code, but we disallow those for output.
2020-09-26 09:30:56 +00:00
|
|
|
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
@pytest.mark.multisig
|
2024-11-15 16:31:22 +00:00
|
|
|
def test_decred_multisig_change(session: Session):
|
2022-01-24 20:23:58 +00:00
|
|
|
# NOTE: fake input tx used
|
|
|
|
|
|
|
|
paths = [parse_path(f"m/48h/1h/{index}'/0'") for index in range(3)]
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes = [
|
2024-11-15 16:31:22 +00:00
|
|
|
btc.get_public_node(session, address_n, coin_name="Decred Testnet").node
|
2021-11-10 21:19:53 +00:00
|
|
|
for address_n in paths
|
|
|
|
]
|
multi: Add decred staking.
Add two new input and four output script types.
Decred ticket purchases consist of a stake submission, op returns, and
change addresses. Although change addresses are allowed by consensus,
they are no longer used in practice and so have been given the
restrictions of a null pubkey and no value. Stake scripts are almost
identical to p2pkh or p2sh except for an extra opcode in front. Inputs
are currently only used in the form of one input three outputs with the
first output, or stake submission, paying to a public key hash, or with
two inputs and five outputs with the stake submission paying to a
multisig script hash. The op returns are directed to the user in the
case of one and the voting service provider and user in the case of two.
One of the sstx commitment for a ticket must pay back to the trezor
wallet. This is checked and an error is thrown if we don't find the
expected public key hash.
Because this adds the ability to create new types of outputs once the
ticket votes, two new input script types are also needed. A successful
vote will lead to a stake generation script that must be spent, and an
unsuccessful vote will lead to a revocation script that must be spent.
If we allowed stake change scripts to have a valid pubkey, that too
would require another op code, but we disallow those for output.
2020-09-26 09:30:56 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
signatures = [[b"", b"", b""], [b"", b"", b""]]
|
multi: Add decred staking.
Add two new input and four output script types.
Decred ticket purchases consist of a stake submission, op returns, and
change addresses. Although change addresses are allowed by consensus,
they are no longer used in practice and so have been given the
restrictions of a null pubkey and no value. Stake scripts are almost
identical to p2pkh or p2sh except for an extra opcode in front. Inputs
are currently only used in the form of one input three outputs with the
first output, or stake submission, paying to a public key hash, or with
two inputs and five outputs with the stake submission paying to a
multisig script hash. The op returns are directed to the user in the
case of one and the voting service provider and user in the case of two.
One of the sstx commitment for a ticket must pay back to the trezor
wallet. This is checked and an error is thrown if we don't find the
expected public key hash.
Because this adds the ability to create new types of outputs once the
ticket votes, two new input script types are also needed. A successful
vote will lead to a stake generation script that must be spent, and an
unsuccessful vote will lead to a revocation script that must be spent.
If we allowed stake change scripts to have a valid pubkey, that too
would require another op code, but we disallow those for output.
2020-09-26 09:30:56 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
def create_multisig(index, address, signatures=None):
|
|
|
|
address_n = parse_path(address)
|
2021-11-10 21:28:11 +00:00
|
|
|
multisig = messages.MultisigRedeemScriptType(
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes=nodes, address_n=address_n, signatures=signatures, m=2
|
2017-12-19 15:19:55 +00:00
|
|
|
)
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
return (paths[index] + address_n), multisig
|
|
|
|
|
|
|
|
def test_multisig(index):
|
|
|
|
address_n, multisig = create_multisig(index, "m/0/0", signatures[0])
|
2021-11-10 21:28:11 +00:00
|
|
|
inp1 = messages.TxInputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=address_n,
|
|
|
|
# TchpthUkRys1VQWgnQyLJNaA4MLBjVmRL2c
|
|
|
|
multisig=multisig,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=200_000_000,
|
2022-01-24 20:23:58 +00:00
|
|
|
prev_hash=FAKE_TXHASH_9ac7d2,
|
2017-12-19 15:19:55 +00:00
|
|
|
prev_index=1,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDMULTISIG,
|
2017-12-19 15:19:55 +00:00
|
|
|
decred_tree=0,
|
|
|
|
)
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n, multisig = create_multisig(index, "m/0/1", signatures[1])
|
2021-11-10 21:28:11 +00:00
|
|
|
inp2 = messages.TxInputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=address_n,
|
|
|
|
# TcnfDEfMhkM3oLWqiq9v9GmYgLK7qfjitKG
|
|
|
|
multisig=multisig,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=200_000_000,
|
2022-01-24 20:23:58 +00:00
|
|
|
prev_hash=FAKE_TXHASH_48f5b8,
|
2017-12-19 15:19:55 +00:00
|
|
|
prev_index=0,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.InputScriptType.SPENDMULTISIG,
|
2017-12-19 15:19:55 +00:00
|
|
|
decred_tree=0,
|
|
|
|
)
|
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n, multisig = create_multisig(index, "m/1/0")
|
2021-11-10 21:28:11 +00:00
|
|
|
out1 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address_n=address_n,
|
|
|
|
# TcrrURA3Bzj4isGU48PdSP9SDoU5oCpjEcb
|
|
|
|
multisig=multisig,
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=99_900_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOMULTISIG,
|
2017-12-19 15:19:55 +00:00
|
|
|
)
|
|
|
|
|
2021-11-10 21:28:11 +00:00
|
|
|
out2 = messages.TxOutputType(
|
2021-11-10 21:19:53 +00:00
|
|
|
address="TsWjioPrP8E1TuTMmTrVMM2BA4iPrjQXBpR",
|
2022-01-31 12:25:30 +00:00
|
|
|
amount=300_000_000,
|
2021-11-10 21:28:11 +00:00
|
|
|
script_type=messages.OutputScriptType.PAYTOADDRESS,
|
2017-12-19 15:19:55 +00:00
|
|
|
)
|
|
|
|
|
2024-11-15 16:31:22 +00:00
|
|
|
with session:
|
|
|
|
session.set_expected_responses(
|
2018-08-13 16:21:24 +00:00
|
|
|
[
|
2020-07-14 18:43:53 +00:00
|
|
|
request_input(0),
|
|
|
|
request_input(1),
|
|
|
|
request_output(0),
|
|
|
|
request_output(1),
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.ButtonRequest(code=B.ConfirmOutput),
|
2024-11-15 16:31:22 +00:00
|
|
|
(is_core(session), messages.ButtonRequest(code=B.ConfirmOutput)),
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.ButtonRequest(code=B.SignTx),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(0),
|
2022-01-24 20:23:58 +00:00
|
|
|
request_meta(FAKE_TXHASH_9ac7d2),
|
|
|
|
request_input(0, FAKE_TXHASH_9ac7d2),
|
|
|
|
request_output(0, FAKE_TXHASH_9ac7d2),
|
|
|
|
request_output(1, FAKE_TXHASH_9ac7d2),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(1),
|
2022-01-24 20:23:58 +00:00
|
|
|
request_meta(FAKE_TXHASH_48f5b8),
|
|
|
|
request_input(0, FAKE_TXHASH_48f5b8),
|
|
|
|
request_output(0, FAKE_TXHASH_48f5b8),
|
|
|
|
request_output(1, FAKE_TXHASH_48f5b8),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(0),
|
|
|
|
request_input(1),
|
|
|
|
request_finished(),
|
2018-08-13 16:21:24 +00:00
|
|
|
]
|
|
|
|
)
|
2021-11-10 21:19:53 +00:00
|
|
|
signature, serialized_tx = btc.sign_tx(
|
2024-11-15 16:31:22 +00:00
|
|
|
session,
|
2018-11-02 15:25:51 +00:00
|
|
|
"Decred Testnet",
|
2021-11-10 21:19:53 +00:00
|
|
|
[inp1, inp2],
|
2018-11-02 15:25:51 +00:00
|
|
|
[out1, out2],
|
|
|
|
prev_txes=TX_API,
|
2018-08-13 16:21:24 +00:00
|
|
|
)
|
2017-12-19 15:19:55 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
signatures[0][index] = signature[0]
|
|
|
|
signatures[1][index] = signature[1]
|
|
|
|
return serialized_tx
|
2017-12-20 20:39:16 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
test_multisig(2)
|
|
|
|
serialized_tx = test_multisig(0)
|
2017-12-20 20:39:16 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
assert (
|
|
|
|
serialized_tx.hex()
|
2022-01-24 20:23:58 +00:00
|
|
|
== "0100000002d18f50c5e465b727fee4af645350093a8baf7e04ee8ef34ecf0c46f422d2c79a0100000000fffffffff32d5470c1a96b2d9d5215066bd2e254f191d4ce8873d0d096f71c8b5fb8f5480000000000ffffffff02605af40500000000000017a914d4ea4e064d969064ca56a4cede56f7bf6cf62f118700a3e1110000000000001976a9143eb656115197956125365348c542e37b6d3d259988ac00000000000000000200c2eb0b0000000000000000fffffffffc483045022100e7056e4cbc0941a1255e85ab95634fd9ae497be9a8ab0e793d6049f7dd97fa07022031c17d6279211843ea1e0815a1831748aa44c3a3083669293805f8e9e803d78d01473044022039b74918f67afd24f20c0bf4d0ea40637d85005bbb942e7c79e17694e4729e0902202563fa43376220261bb177fc87d637d39809e0ffa4991a1477dbc60a1c2e3997014c69522103defea6f243b97354449bb348446a97e38df2fbed33afc3a7185bfdd26757cfdb2103725d6c5253f2040a9a73af24bcc196bf302d6cc94374dd7197b138e10912670121038924e94fff15302a3fb45ad4fc0ed17178800f0f1c2bdacb1017f4db951aa9f153ae00c2eb0b0000000000000000fffffffffb473044022047afb55f956ef7ac7d4a32e97fe35b3981cd827866ccd76e66b7f186a5338f9302201415cdd987876e8c6c13037e53d055aac467acece41d9357657e4fd8290d914101473044022005cb0efd5889d697e040b2db5d56ef7e1d29fcd20b74a8cc44d670092b6cfaee02202150837c1f5108af8b6cc022bd2d40e54170869ad39b2d1d61c67a47ad21e019014c695221021ef4b5d81f21593071b993bd4d8c564c569a6f84de0d4511135cbc66d8bf7bcd2103f1e53b6e0ff99adf7e8fa826a94bdac83163d8abbc1d19a8d6b88a4af91b9a67210390c8ea70e1f2f60e0052be65183c43bb01b2f02dfa4e448f74e359997f74e6ad53ae"
|
2021-11-10 21:19:53 +00:00
|
|
|
)
|