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
|
2022-01-31 12:25:30 +00:00
|
|
|
from trezorlib.debuglink import TrezorClientDebugLink as Client
|
2018-04-18 13:53:40 +00:00
|
|
|
from trezorlib.tools import parse_path
|
2017-12-18 10:55:41 +00:00
|
|
|
|
2021-11-29 11:00:01 +00:00
|
|
|
from ...tx_cache import TxCache
|
|
|
|
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
|
|
|
|
|
|
|
|
2018-09-12 18:34:26 +00:00
|
|
|
TXHASH_e16248 = bytes.fromhex(
|
2018-08-13 16:21:24 +00:00
|
|
|
"e16248f0b39a0a0c0e53d6f2f84c2a944f0d50e017a82701e8e02e46e979d5ed"
|
|
|
|
)
|
2018-09-12 18:34:26 +00:00
|
|
|
TXHASH_5e6e35 = bytes.fromhex(
|
2018-08-13 16:21:24 +00:00
|
|
|
"5e6e3500a333c53c02f523db5f1a9b17538a8850b4c2c24ecb9b7ba48059b970"
|
|
|
|
)
|
2018-09-12 18:34:26 +00:00
|
|
|
TXHASH_ccf95b = bytes.fromhex(
|
2018-08-13 16:21:24 +00:00
|
|
|
"ccf95b0fd220ef59ae2e5b17005a81e222758122682d522eff8ae1fcbc93bc74"
|
|
|
|
)
|
2018-09-12 18:34:26 +00:00
|
|
|
TXHASH_f395ef = bytes.fromhex(
|
2018-08-13 16:21:24 +00:00
|
|
|
"f395ef3e72a831a766db15e7a38bc28025d4ee02234d68bdea2d8353b47a3113"
|
|
|
|
)
|
2018-09-12 18:34:26 +00:00
|
|
|
TXHASH_3f7c39 = bytes.fromhex(
|
2018-08-13 16:21:24 +00:00
|
|
|
"3f7c395521d38387e7617565fe17628723ef6635a08537ad9c46cfb1619e4c3f"
|
|
|
|
)
|
2018-09-12 18:34:26 +00:00
|
|
|
TXHASH_16da18 = bytes.fromhex(
|
2018-08-13 16:21:24 +00:00
|
|
|
"16da185052740d85a630e79c140558215b64e26c500212b90e16b55d13ca06a8"
|
|
|
|
)
|
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
|
|
|
TXHASH_8b6890 = bytes.fromhex(
|
|
|
|
"8b6890c10a3764fe6f378bc5b7e438148df176e9be1dde704ce866361149e254"
|
|
|
|
)
|
|
|
|
TXHASH_1f00fc = bytes.fromhex(
|
|
|
|
"1f00fc54530d7c4877f5032e91b6c507f6a1531861dede2ab134e5c0b5dfe8c8"
|
|
|
|
)
|
2017-12-18 10:55:41 +00:00
|
|
|
|
2021-11-10 21:19:53 +00:00
|
|
|
pytestmark = [pytest.mark.altcoin, pytest.mark.decred]
|
|
|
|
|
|
|
|
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_send_decred(client: Client):
|
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"),
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_hash=TXHASH_e16248,
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
|
|
|
[
|
|
|
|
request_input(0),
|
|
|
|
request_output(0),
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.ButtonRequest(code=B.ConfirmOutput),
|
|
|
|
messages.ButtonRequest(code=B.FeeOverThreshold),
|
|
|
|
messages.ButtonRequest(code=B.SignTx),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_input(0),
|
|
|
|
request_meta(TXHASH_e16248),
|
|
|
|
request_input(0, TXHASH_e16248),
|
|
|
|
request_output(0, TXHASH_e16248),
|
|
|
|
request_output(1, TXHASH_e16248),
|
|
|
|
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(
|
|
|
|
client, "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()
|
|
|
|
== "0100000001edd579e9462ee0e80127a817e0500d4f942a4cf8f2d6530e0c0a9ab3f04862e10100000000ffffffff01802b530b0000000000001976a914819d291a2f7fbf770e784bfd78b5ce92c58e95ea88ac00000000000000000100c2eb0b0000000000000000ffffffff6a473044022009e394c7dec76ab6988270b467839b1462ad781556bce37383b76e026418ce6302204f7f6ef535d2986b095d7c96232a0990a0b9ce3004894b39c167bb18e5833ac30121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_t1
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_purchase_ticket_decred(client: Client):
|
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"),
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_hash=TXHASH_e16248,
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
|
|
|
[
|
|
|
|
request_input(0),
|
|
|
|
request_output(0),
|
2021-11-10 21:28:11 +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),
|
|
|
|
request_meta(TXHASH_e16248),
|
|
|
|
request_input(0, TXHASH_e16248),
|
|
|
|
request_output(0, TXHASH_e16248),
|
|
|
|
request_output(1, TXHASH_e16248),
|
|
|
|
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(
|
|
|
|
client,
|
|
|
|
"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()
|
|
|
|
== "0100000001edd579e9462ee0e80127a817e0500d4f942a4cf8f2d6530e0c0a9ab3f04862e10100000000ffffffff03603bea0b0000000000001aba76a914819d291a2f7fbf770e784bfd78b5ce92c58e95ea88ac00000000000000000000206a1edc1a98d791735eb9a8715a2a219c23680edcedad00c2eb0b000000000058000000000000000000001abd76a914000000000000000000000000000000000000000088ac00000000000000000100c2eb0b0000000000000000ffffffff6b4830450221008ced5411a6d92b761bdd8b9f7fbc5bfae3c31f9369050c218977f4540ab1ec9602206e89c821878ebfd959d1c4a63100eec5b1154c8d9508c039bb78e333498a73b40121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.skip_t1
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_spend_from_stake_generation_and_revocation_decred(client: Client):
|
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"),
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_hash=TXHASH_8b6890,
|
|
|
|
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"),
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_hash=TXHASH_1f00fc,
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
|
|
|
[
|
|
|
|
request_input(0),
|
|
|
|
request_input(1),
|
|
|
|
request_output(0),
|
2021-11-10 21:28:11 +00:00
|
|
|
messages.ButtonRequest(code=B.ConfirmOutput),
|
|
|
|
messages.ButtonRequest(code=B.SignTx),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_input(0),
|
|
|
|
request_meta(TXHASH_8b6890),
|
|
|
|
request_input(0, TXHASH_8b6890),
|
|
|
|
request_input(1, TXHASH_8b6890),
|
|
|
|
request_output(0, TXHASH_8b6890),
|
|
|
|
request_output(1, TXHASH_8b6890),
|
|
|
|
request_output(2, TXHASH_8b6890),
|
|
|
|
request_input(1),
|
|
|
|
request_meta(TXHASH_1f00fc),
|
|
|
|
request_input(0, TXHASH_1f00fc),
|
|
|
|
request_output(0, TXHASH_1f00fc),
|
|
|
|
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(
|
|
|
|
client, "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()
|
|
|
|
== "010000000254e249113666e84c70de1dbee976f18d1438e4b7c58b376ffe64370ac190688b0200000001ffffffffc8e8dfb5c0e534b12adede611853a1f607c5b6912e03f577487c0d5354fc001f0000000001ffffffff0160fdd5170000000000001976a914819d291a2f7fbf770e784bfd78b5ce92c58e95ea88ac00000000000000000200c2eb0b0000000000000000ffffffff6b483045022100bdcb877c97d72db74eca06fefa21a7f7b00afcd5d916fce2155ed7df1ca5546102201e1f9efd7d652b449474c2c70171bfc4535544927bed62021f7334447d1ea4740121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd000c2eb0b0000000000000000ffffffff6a473044022030c5743c442bd696d19dcf73d54e95526e726de965c2e2b4b9fd70248eaae21d02201305a3bcc2bb0e33122277763990e3b48f317d61264a68d190fb8acfc004cc640121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd0"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_send_decred_change(client: Client):
|
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"),
|
|
|
|
amount=190_000_000,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_hash=TXHASH_5e6e35,
|
|
|
|
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
|
|
|
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,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_hash=TXHASH_ccf95b,
|
|
|
|
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,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_hash=TXHASH_f395ef,
|
|
|
|
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-31 12:25:30 +00:00
|
|
|
amount=489_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
|
|
|
)
|
|
|
|
|
|
|
|
with client:
|
|
|
|
client.set_expected_responses(
|
|
|
|
[
|
|
|
|
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),
|
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),
|
|
|
|
request_meta(TXHASH_5e6e35),
|
|
|
|
request_input(0, TXHASH_5e6e35),
|
|
|
|
request_output(0, TXHASH_5e6e35),
|
|
|
|
request_input(1),
|
|
|
|
request_meta(TXHASH_ccf95b),
|
|
|
|
request_input(0, TXHASH_ccf95b),
|
|
|
|
request_output(0, TXHASH_ccf95b),
|
|
|
|
request_output(1, TXHASH_ccf95b),
|
|
|
|
request_input(2),
|
|
|
|
request_meta(TXHASH_f395ef),
|
|
|
|
request_input(0, TXHASH_f395ef),
|
|
|
|
request_output(0, TXHASH_f395ef),
|
|
|
|
request_output(1, TXHASH_f395ef),
|
|
|
|
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(
|
|
|
|
client,
|
|
|
|
"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()
|
|
|
|
== "010000000370b95980a47b9bcb4ec2c2b450888a53179b1a5fdb23f5023cc533a300356e5e0000000000ffffffff74bc93bcfce18aff2e522d6822817522e2815a00175b2eae59ef20d20f5bf9cc0100000000ffffffff13317ab453832deabd684d2302eed42580c28ba3e715db66a731a8723eef95f30000000000ffffffff02d86c341d0000000000001976a9143eb656115197956125365348c542e37b6d3d259988ac00e1f5050000000000001976a9143ee6f9d662e7be18373d80e5eb44627014c2bf6688ac000000000000000003802b530b0000000000000000ffffffff6a47304402200e50a6d43c462045917792e7d03b4354900c3baccb7abef66f556a32b12f2ca6022031ae94fdf2a41dd6ed2e081faf0f8f1c64411a1b46eb26f7f35d94402b2bde110121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd000c2eb0b0000000000000000ffffffff6a47304402204894c2f8e76c4645d2df600cdd01443aeb48807b72150c4bc10eebd126529532022054cd37462a3f0ddb85c75b4e874ab0c2aad7eebcff3e6c1ac20e1c16babe36720121030e669acac1f280d1ddf441cd2ba5e97417bf2689e4bbec86df4f831bf9f7ffd000c2eb0b0000000000000000ffffffff6b4830450221009f1ba584023da8aafd57374e83be68f1a097b906967ec9e50736f31bfc7989f102204a190fc2885e394572b5c2ced046657b1dd07abdb19144e21e78987968c7f17601210294e3e5e77e22eea0e4c0d30d89beb4db7f69b4bf1ae709e411d6a06618b8f852"
|
|
|
|
)
|
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
|
2022-01-31 12:25:30 +00:00
|
|
|
def test_decred_multisig_change(client: Client):
|
|
|
|
paths = [parse_path(f"m/48h/1h/{index}h/0h") for index in range(3)]
|
2021-11-10 21:19:53 +00:00
|
|
|
nodes = [
|
|
|
|
btc.get_public_node(client, address_n, coin_name="Decred Testnet").node
|
|
|
|
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,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_hash=TXHASH_3f7c39,
|
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,
|
2021-11-10 21:19:53 +00:00
|
|
|
prev_hash=TXHASH_16da18,
|
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
|
|
|
)
|
|
|
|
|
2019-08-27 14:58:59 +00:00
|
|
|
with client:
|
|
|
|
client.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),
|
|
|
|
messages.ButtonRequest(code=B.SignTx),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(0),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_meta(TXHASH_3f7c39),
|
|
|
|
request_input(0, TXHASH_3f7c39),
|
|
|
|
request_output(0, TXHASH_3f7c39),
|
|
|
|
request_output(1, TXHASH_3f7c39),
|
2020-03-26 14:58:44 +00:00
|
|
|
request_input(1),
|
2021-11-10 21:19:53 +00:00
|
|
|
request_meta(TXHASH_16da18),
|
|
|
|
request_input(0, TXHASH_16da18),
|
|
|
|
request_output(0, TXHASH_16da18),
|
|
|
|
request_output(1, TXHASH_16da18),
|
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(
|
2019-08-27 14:58:59 +00:00
|
|
|
client,
|
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()
|
|
|
|
== "01000000023f4c9e61b1cf469cad3785a03566ef23876217fe657561e78783d32155397c3f0100000000ffffffffa806ca135db5160eb91202506ce2645b215805149ce730a6850d74525018da160000000000ffffffff02605af40500000000000017a914d4ea4e064d969064ca56a4cede56f7bf6cf62f118700a3e1110000000000001976a9143eb656115197956125365348c542e37b6d3d259988ac00000000000000000200c2eb0b0000000000000000fffffffffc483045022100a35fd1ed579362ac65b583ba910a3d814c5e9b87da835993bf4166a6b3a8482b02204b3e167fad7d37dd62aa585c68d3c8e00c3c43bf7a25d74f6407870a4a7499e9014730440220720fd7b6dfd337056c5e6dad76e307b3758e702ccfd39471bf90e0db3a5f5eba02205bd062c78fcdd56057723a0e39d661a790f325e59e643b54c47b7218a5781684014c69522103defea6f243b97354449bb348446a97e38df2fbed33afc3a7185bfdd26757cfdb2103725d6c5253f2040a9a73af24bcc196bf302d6cc94374dd7197b138e10912670121038924e94fff15302a3fb45ad4fc0ed17178800f0f1c2bdacb1017f4db951aa9f153ae00c2eb0b0000000000000000fffffffffc4730440220625357288f0880be21d6a44275033fd84cf04bc23227eef810455ad711507e4402207d303548bb0476f98c52f223fe4430f82a78a73f757b186453948b0908f5af3101483045022100e140f586e370824b13576c77cf9f2855294fd415316f2a130126d8412a7cf08c0220308d1f5c83847458b271c93bfca5eba7fc1691b9c5d6e57955985affd1110e24014c695221021ef4b5d81f21593071b993bd4d8c564c569a6f84de0d4511135cbc66d8bf7bcd2103f1e53b6e0ff99adf7e8fa826a94bdac83163d8abbc1d19a8d6b88a4af91b9a67210390c8ea70e1f2f60e0052be65183c43bb01b2f02dfa4e448f74e359997f74e6ad53ae"
|
|
|
|
)
|