From 9dfc08ca618ad6026eddb00f26b86893f266ff10 Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Tue, 19 May 2020 12:54:58 +0000 Subject: [PATCH] core/bitcoin: drop decred_script_version --- common/protob/messages-bitcoin.proto | 4 ++-- core/src/apps/bitcoin/sign_tx/decred.py | 8 ++++--- core/src/apps/bitcoin/sign_tx/helpers.py | 21 +------------------ core/src/trezor/messages/TxInputType.py | 3 --- core/src/trezor/messages/TxOutputType.py | 3 --- legacy/firmware/signing.c | 14 ------------- legacy/firmware/transaction.c | 4 +++- python/src/trezorlib/messages/TxInputType.py | 3 --- python/src/trezorlib/messages/TxOutputType.py | 3 --- tests/device_tests/test_msg_signtx_decred.py | 5 ----- 10 files changed, 11 insertions(+), 57 deletions(-) diff --git a/common/protob/messages-bitcoin.proto b/common/protob/messages-bitcoin.proto index a5effcaf84..880a16765c 100644 --- a/common/protob/messages-bitcoin.proto +++ b/common/protob/messages-bitcoin.proto @@ -213,7 +213,7 @@ message TxAck { optional MultisigRedeemScriptType multisig = 7; // Filled if input is going to spend multisig tx optional uint64 amount = 8; // amount of previous transaction output (for segwit only) optional uint32 decred_tree = 9; // only for Decred - optional uint32 decred_script_version = 10; // only for Decred + // optional uint32 decred_script_version = 10; // only for Decred // deprecated -> only 0 is supported // optional bytes prev_block_hash_bip115 = 11; // BIP-115 support dropped // optional uint32 prev_block_height_bip115 = 12; // BIP-115 support dropped } @@ -235,7 +235,7 @@ message TxAck { required OutputScriptType script_type = 4; // output script type optional MultisigRedeemScriptType multisig = 5; // defines multisig address; script_type must be PAYTOMULTISIG optional bytes op_return_data = 6; // defines op_return data; script_type must be PAYTOOPRETURN, amount must be 0 - optional uint32 decred_script_version = 7; // only for Decred + // optional uint32 decred_script_version = 7; // only for Decred // deprecated -> only 0 is supported // optional bytes block_hash_bip115 = 8; // BIP-115 support dropped // optional uint32 block_height_bip115 = 9; // BIP-115 support dropped enum OutputScriptType { diff --git a/core/src/apps/bitcoin/sign_tx/decred.py b/core/src/apps/bitcoin/sign_tx/decred.py index 275338f7ce..af2f02f209 100644 --- a/core/src/apps/bitcoin/sign_tx/decred.py +++ b/core/src/apps/bitcoin/sign_tx/decred.py @@ -22,6 +22,7 @@ from .bitcoin import Bitcoin DECRED_SERIALIZE_FULL = const(0 << 16) DECRED_SERIALIZE_NO_WITNESS = const(1 << 16) DECRED_SERIALIZE_WITNESS_SIGNING = const(3 << 16) +DECRED_SCRIPT_VERSION = const(0) DECRED_SIGHASH_ALL = const(1) @@ -63,8 +64,6 @@ class Decred(Bitcoin): self.write_tx_input(self.serialized_tx, txi, bytes()) async def confirm_output(self, txo: TxOutputType, script_pubkey: bytes) -> None: - if txo.decred_script_version != 0: - raise wire.ActionCancelled("Cannot send to output with script version != 0") await super().confirm_output(txo, script_pubkey) self.write_tx_output(self.serialized_tx, txo, script_pubkey) @@ -160,7 +159,10 @@ class Decred(Bitcoin): script_pubkey: bytes, ) -> None: writers.write_uint64(w, txo.amount) - writers.write_uint16(w, txo.decred_script_version) + if isinstance(txo, TxOutputBinType): + writers.write_uint16(w, txo.decred_script_version) + else: + writers.write_uint16(w, DECRED_SCRIPT_VERSION) writers.write_bytes_prefixed(w, script_pubkey) def write_tx_header( diff --git a/core/src/apps/bitcoin/sign_tx/helpers.py b/core/src/apps/bitcoin/sign_tx/helpers.py index d1e035fd29..57981711ac 100644 --- a/core/src/apps/bitcoin/sign_tx/helpers.py +++ b/core/src/apps/bitcoin/sign_tx/helpers.py @@ -21,7 +21,7 @@ from apps.common.coininfo import CoinInfo from ..writers import TX_HASH_SIZE if False: - from typing import Any, Awaitable, Dict, Union + from typing import Any, Awaitable, Dict from trezor.messages.TxInputType import EnumTypeInputScriptType from trezor.messages.TxOutputType import EnumTypeOutputScriptType @@ -241,8 +241,6 @@ def sanitize_tx_input(tx: TransactionType, coin: CoinInfo) -> TxInputType: raise wire.DataError("Segwit not enabled on this coin") if txi.amount is None: raise wire.DataError("Segwit input without amount") - - _sanitize_decred(txi, coin) return txi @@ -267,26 +265,9 @@ def sanitize_tx_output(tx: TransactionType, coin: CoinInfo) -> TxOutputType: raise wire.DataError("Both address and address_n provided.") if not txo.address_n and not txo.address: raise wire.DataError("Missing address") - - _sanitize_decred(txo, coin) - return txo def sanitize_tx_binoutput(tx: TransactionType, coin: CoinInfo) -> TxOutputBinType: txo_bin = tx.bin_outputs[0] - _sanitize_decred(txo_bin, coin) return txo_bin - - -def _sanitize_decred( - tx: Union[TxInputType, TxOutputType, TxOutputBinType], coin: CoinInfo -) -> None: - if coin.decred: - if tx.decred_script_version is None: - tx.decred_script_version = 0 - else: - if tx.decred_script_version is not None: - raise wire.DataError( - "Decred details provided but Decred coin not specified." - ) diff --git a/core/src/trezor/messages/TxInputType.py b/core/src/trezor/messages/TxInputType.py index bd7d4c6f2c..1c4997f16c 100644 --- a/core/src/trezor/messages/TxInputType.py +++ b/core/src/trezor/messages/TxInputType.py @@ -26,7 +26,6 @@ class TxInputType(p.MessageType): multisig: MultisigRedeemScriptType = None, amount: int = None, decred_tree: int = None, - decred_script_version: int = None, ) -> None: self.address_n = address_n if address_n is not None else [] self.prev_hash = prev_hash @@ -37,7 +36,6 @@ class TxInputType(p.MessageType): self.multisig = multisig self.amount = amount self.decred_tree = decred_tree - self.decred_script_version = decred_script_version @classmethod def get_fields(cls) -> Dict: @@ -51,5 +49,4 @@ class TxInputType(p.MessageType): 7: ('multisig', MultisigRedeemScriptType, 0), 8: ('amount', p.UVarintType, 0), 9: ('decred_tree', p.UVarintType, 0), - 10: ('decred_script_version', p.UVarintType, 0), } diff --git a/core/src/trezor/messages/TxOutputType.py b/core/src/trezor/messages/TxOutputType.py index 20edacf612..8862b30933 100644 --- a/core/src/trezor/messages/TxOutputType.py +++ b/core/src/trezor/messages/TxOutputType.py @@ -23,7 +23,6 @@ class TxOutputType(p.MessageType): script_type: EnumTypeOutputScriptType = None, multisig: MultisigRedeemScriptType = None, op_return_data: bytes = None, - decred_script_version: int = None, ) -> None: self.address = address self.address_n = address_n if address_n is not None else [] @@ -31,7 +30,6 @@ class TxOutputType(p.MessageType): self.script_type = script_type self.multisig = multisig self.op_return_data = op_return_data - self.decred_script_version = decred_script_version @classmethod def get_fields(cls) -> Dict: @@ -42,5 +40,4 @@ class TxOutputType(p.MessageType): 4: ('script_type', p.EnumType("OutputScriptType", (0, 1, 2, 3, 4, 5)), 0), # required 5: ('multisig', MultisigRedeemScriptType, 0), 6: ('op_return_data', p.BytesType, 0), - 7: ('decred_script_version', p.UVarintType, 0), } diff --git a/legacy/firmware/signing.c b/legacy/firmware/signing.c index e18f7c51d0..6e09739c8a 100644 --- a/legacy/firmware/signing.c +++ b/legacy/firmware/signing.c @@ -652,13 +652,6 @@ static bool signing_validate_input(const TxInputType *txinput) { signing_abort(); return false; } - if (!coin->decred && txinput->has_decred_script_version) { - fsm_sendFailure( - FailureType_Failure_DataError, - _("Decred details provided but Decred coin not specified.")); - signing_abort(); - return false; - } #if !BITCOIN_ONLY if (coin->force_bip143 || coin->overwintered) { @@ -783,13 +776,6 @@ static bool signing_check_input(const TxInputType *txinput) { tx_sequence_hash(&hasher_sequence, txinput); #if !BITCOIN_ONLY if (coin->decred) { - if (txinput->decred_script_version > 0) { - fsm_sendFailure(FailureType_Failure_DataError, - _("Decred v1+ scripts are not supported")); - signing_abort(); - return false; - } - // serialize Decred prefix in Phase 1 resp.has_serialized = true; resp.serialized.has_serialized_tx = true; diff --git a/legacy/firmware/transaction.c b/legacy/firmware/transaction.c index 450a165d11..28866603fc 100644 --- a/legacy/firmware/transaction.c +++ b/legacy/firmware/transaction.c @@ -61,6 +61,8 @@ /* size of a Decred witness (without script): 8 amount, 4 block height, 4 block * index */ #define TXSIZE_DECRED_WITNESS 16 +/* support version of Decred script_version */ +#define DECRED_SCRIPT_VERSION 0 static const uint8_t segwit_header[2] = {0, 1}; @@ -193,7 +195,7 @@ int compile_output(const CoinInfo *coin, const HDNode *root, TxOutputType *in, TxOutputBinType *out, bool needs_confirm) { memzero(out, sizeof(TxOutputBinType)); out->amount = in->amount; - out->decred_script_version = in->decred_script_version; + out->decred_script_version = DECRED_SCRIPT_VERSION; uint8_t addr_raw[MAX_ADDR_RAW_SIZE] = {0}; size_t addr_raw_len = 0; diff --git a/python/src/trezorlib/messages/TxInputType.py b/python/src/trezorlib/messages/TxInputType.py index baf95b5729..68f0df089b 100644 --- a/python/src/trezorlib/messages/TxInputType.py +++ b/python/src/trezorlib/messages/TxInputType.py @@ -26,7 +26,6 @@ class TxInputType(p.MessageType): multisig: MultisigRedeemScriptType = None, amount: int = None, decred_tree: int = None, - decred_script_version: int = None, ) -> None: self.address_n = address_n if address_n is not None else [] self.prev_hash = prev_hash @@ -37,7 +36,6 @@ class TxInputType(p.MessageType): self.multisig = multisig self.amount = amount self.decred_tree = decred_tree - self.decred_script_version = decred_script_version @classmethod def get_fields(cls) -> Dict: @@ -51,5 +49,4 @@ class TxInputType(p.MessageType): 7: ('multisig', MultisigRedeemScriptType, 0), 8: ('amount', p.UVarintType, 0), 9: ('decred_tree', p.UVarintType, 0), - 10: ('decred_script_version', p.UVarintType, 0), } diff --git a/python/src/trezorlib/messages/TxOutputType.py b/python/src/trezorlib/messages/TxOutputType.py index e6bf62d577..b3f5537478 100644 --- a/python/src/trezorlib/messages/TxOutputType.py +++ b/python/src/trezorlib/messages/TxOutputType.py @@ -23,7 +23,6 @@ class TxOutputType(p.MessageType): script_type: EnumTypeOutputScriptType = None, multisig: MultisigRedeemScriptType = None, op_return_data: bytes = None, - decred_script_version: int = None, ) -> None: self.address = address self.address_n = address_n if address_n is not None else [] @@ -31,7 +30,6 @@ class TxOutputType(p.MessageType): self.script_type = script_type self.multisig = multisig self.op_return_data = op_return_data - self.decred_script_version = decred_script_version @classmethod def get_fields(cls) -> Dict: @@ -42,5 +40,4 @@ class TxOutputType(p.MessageType): 4: ('script_type', p.EnumType("OutputScriptType", (0, 1, 2, 3, 4, 5)), 0), # required 5: ('multisig', MultisigRedeemScriptType, 0), 6: ('op_return_data', p.BytesType, 0), - 7: ('decred_script_version', p.UVarintType, 0), } diff --git a/tests/device_tests/test_msg_signtx_decred.py b/tests/device_tests/test_msg_signtx_decred.py index 18ddbbe57c..a0e663a706 100644 --- a/tests/device_tests/test_msg_signtx_decred.py +++ b/tests/device_tests/test_msg_signtx_decred.py @@ -63,7 +63,6 @@ class TestMsgSigntxDecred: address="TscqTv1he8MZrV321SfRghw7LFBCJDKB3oz", amount=190000000, script_type=proto.OutputScriptType.PAYTOADDRESS, - decred_script_version=0, ) with client: @@ -123,7 +122,6 @@ class TestMsgSigntxDecred: address="TsWjioPrP8E1TuTMmTrVMM2BA4iPrjQXBpR", amount=489975000, script_type=proto.OutputScriptType.PAYTOADDRESS, - decred_script_version=0, ) out2 = proto.TxOutputType( @@ -131,7 +129,6 @@ class TestMsgSigntxDecred: address_n=parse_path("m/44'/1'/0'/1/0"), amount=100000000, script_type=proto.OutputScriptType.PAYTOADDRESS, - decred_script_version=0, ) with client: @@ -222,14 +219,12 @@ class TestMsgSigntxDecred: multisig=multisig, amount=99900000, script_type=proto.OutputScriptType.PAYTOMULTISIG, - decred_script_version=0, ) out2 = proto.TxOutputType( address="TsWjioPrP8E1TuTMmTrVMM2BA4iPrjQXBpR", amount=300000000, script_type=proto.OutputScriptType.PAYTOADDRESS, - decred_script_version=0, ) with client: