From 13cbb59082b8c38d8f311c39c5458d9907339e38 Mon Sep 17 00:00:00 2001 From: Andrew Kozlik Date: Mon, 18 Oct 2021 15:21:21 +0200 Subject: [PATCH] feat(common): Add script_pubkey field to TxInput message. --- common/protob/messages-bitcoin.proto | 4 +++- core/.changelog.d/1857.added | 1 + core/src/trezor/messages.py | 2 ++ docs/common/communication/bitcoin-signing.md | 2 +- legacy/firmware/.changelog.d/1857.added | 1 + legacy/firmware/messages.h | 2 +- legacy/firmware/protob/messages-bitcoin.options | 2 ++ python/.changelog.d/1857.added | 1 + python/src/trezorlib/messages.py | 6 ++++++ 9 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 core/.changelog.d/1857.added create mode 100644 legacy/firmware/.changelog.d/1857.added create mode 100644 python/.changelog.d/1857.added diff --git a/common/protob/messages-bitcoin.proto b/common/protob/messages-bitcoin.proto index fad571e2a..9d5352af4 100644 --- a/common/protob/messages-bitcoin.proto +++ b/common/protob/messages-bitcoin.proto @@ -300,6 +300,7 @@ message TxAck { optional bytes orig_hash = 16; // tx_hash of the original transaction where this input was spent (used when creating a replacement transaction) optional uint32 orig_index = 17; // index of the input in the original transaction (used when creating a replacement transaction) optional DecredStakingSpendType decred_staking_spend = 18; // if not None this holds the type of stake spend: revocation or stake generation + optional bytes script_pubkey = 19; // scriptPubKey of the previous output spent by this input, only set of EXTERNAL inputs } /** * Structure representing compiled transaction output @@ -351,6 +352,7 @@ message TxInput { optional bytes orig_hash = 16; // tx_hash of the original transaction where this input was spent (used when creating a replacement transaction) optional uint32 orig_index = 17; // index of the input in the original transaction (used when creating a replacement transaction) optional DecredStakingSpendType decred_staking_spend = 18; // if not None this holds the type of stake spend: revocation or stake generation + optional bytes script_pubkey = 19; // scriptPubKey of the previous output spent by this input, only set of EXTERNAL inputs } /** Data type for transaction output to be signed. @@ -399,7 +401,7 @@ message PrevInput { optional uint32 decred_tree = 9; // only for Decred // fields that are in use, or have been in the past, in TxInputType - reserved 1, 6, 7, 8, 10, 11, 12, 13, 14, 15; + reserved 1, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19; } /** Data type for outputs of previous transactions. diff --git a/core/.changelog.d/1857.added b/core/.changelog.d/1857.added new file mode 100644 index 000000000..4b3f9803b --- /dev/null +++ b/core/.changelog.d/1857.added @@ -0,0 +1 @@ +Add script_pubkey field to TxInput message. diff --git a/core/src/trezor/messages.py b/core/src/trezor/messages.py index 951368bde..34affc501 100644 --- a/core/src/trezor/messages.py +++ b/core/src/trezor/messages.py @@ -643,6 +643,7 @@ if TYPE_CHECKING: orig_hash: "bytes | None" orig_index: "int | None" decred_staking_spend: "DecredStakingSpendType | None" + script_pubkey: "bytes | None" def __init__( self, @@ -662,6 +663,7 @@ if TYPE_CHECKING: orig_hash: "bytes | None" = None, orig_index: "int | None" = None, decred_staking_spend: "DecredStakingSpendType | None" = None, + script_pubkey: "bytes | None" = None, ) -> None: pass diff --git a/docs/common/communication/bitcoin-signing.md b/docs/common/communication/bitcoin-signing.md index 2e761fb10..af45594c4 100644 --- a/docs/common/communication/bitcoin-signing.md +++ b/docs/common/communication/bitcoin-signing.md @@ -154,7 +154,7 @@ signing party hasn't signed their input yet (i.e., with two Trezors, one must si so that the other can include a pre-signed input), they can instead provide a [SLIP-19](https://github.com/satoshilabs/slips/blob/master/slip-0019.md) ownership proof in the `ownership_proof` field, with optional commitment data in -`commitment_data`. +`commitment_data`. The `script_pubkey` field is required for all external inputs. ### Transaction output diff --git a/legacy/firmware/.changelog.d/1857.added b/legacy/firmware/.changelog.d/1857.added new file mode 100644 index 000000000..4b3f9803b --- /dev/null +++ b/legacy/firmware/.changelog.d/1857.added @@ -0,0 +1 @@ +Add script_pubkey field to TxInput message. diff --git a/legacy/firmware/messages.h b/legacy/firmware/messages.h index ad362922c..2e1e68db5 100644 --- a/legacy/firmware/messages.h +++ b/legacy/firmware/messages.h @@ -32,7 +32,7 @@ #define MSG_IN_ENCODED_SIZE (16 * 1024) // Maximum size of a C struct containing a decoded incoming message. -#define MSG_IN_DECODED_SIZE (15 * 1024) +#define MSG_IN_DECODED_SIZE (16 * 1024) // Buffer size for outgoing USB packets with headers. #define MSG_OUT_BUFFER_SIZE (3 * 1024) diff --git a/legacy/firmware/protob/messages-bitcoin.options b/legacy/firmware/protob/messages-bitcoin.options index 1b3a2d6bc..9cfc470a0 100644 --- a/legacy/firmware/protob/messages-bitcoin.options +++ b/legacy/firmware/protob/messages-bitcoin.options @@ -35,6 +35,7 @@ TxInputType.witness max_size:109 TxInputType.ownership_proof max_size:171 TxInputType.commitment_data max_size:32 TxInputType.orig_hash max_size:32 +TxInputType.script_pubkey max_size:520 TxOutputType.address max_size:130 TxOutputType.address_n max_count:8 @@ -62,6 +63,7 @@ TxInput.witness max_size:109 TxInput.ownership_proof max_size:171 TxInput.commitment_data max_size:32 TxInput.orig_hash max_size:32 +TxInput.script_pubkey max_size:520 TxOutput.address max_size:130 TxOutput.address_n max_count:8 diff --git a/python/.changelog.d/1857.added b/python/.changelog.d/1857.added new file mode 100644 index 000000000..4b3f9803b --- /dev/null +++ b/python/.changelog.d/1857.added @@ -0,0 +1 @@ +Add script_pubkey field to TxInput message. diff --git a/python/src/trezorlib/messages.py b/python/src/trezorlib/messages.py index cce9cb888..ea147dace 100644 --- a/python/src/trezorlib/messages.py +++ b/python/src/trezorlib/messages.py @@ -1197,6 +1197,7 @@ class TxInput(protobuf.MessageType): 16: protobuf.Field("orig_hash", "bytes", repeated=False, required=False), 17: protobuf.Field("orig_index", "uint32", repeated=False, required=False), 18: protobuf.Field("decred_staking_spend", "DecredStakingSpendType", repeated=False, required=False), + 19: protobuf.Field("script_pubkey", "bytes", repeated=False, required=False), } def __init__( @@ -1217,6 +1218,7 @@ class TxInput(protobuf.MessageType): orig_hash: Optional["bytes"] = None, orig_index: Optional["int"] = None, decred_staking_spend: Optional["DecredStakingSpendType"] = None, + script_pubkey: Optional["bytes"] = None, ) -> None: self.address_n = address_n if address_n is not None else [] self.prev_hash = prev_hash @@ -1233,6 +1235,7 @@ class TxInput(protobuf.MessageType): self.orig_hash = orig_hash self.orig_index = orig_index self.decred_staking_spend = decred_staking_spend + self.script_pubkey = script_pubkey class TxOutput(protobuf.MessageType): @@ -1650,6 +1653,7 @@ class TxInputType(protobuf.MessageType): 16: protobuf.Field("orig_hash", "bytes", repeated=False, required=False), 17: protobuf.Field("orig_index", "uint32", repeated=False, required=False), 18: protobuf.Field("decred_staking_spend", "DecredStakingSpendType", repeated=False, required=False), + 19: protobuf.Field("script_pubkey", "bytes", repeated=False, required=False), } def __init__( @@ -1670,6 +1674,7 @@ class TxInputType(protobuf.MessageType): orig_hash: Optional["bytes"] = None, orig_index: Optional["int"] = None, decred_staking_spend: Optional["DecredStakingSpendType"] = None, + script_pubkey: Optional["bytes"] = None, ) -> None: self.address_n = address_n if address_n is not None else [] self.prev_hash = prev_hash @@ -1686,6 +1691,7 @@ class TxInputType(protobuf.MessageType): self.orig_hash = orig_hash self.orig_index = orig_index self.decred_staking_spend = decred_staking_spend + self.script_pubkey = script_pubkey class TxOutputBinType(protobuf.MessageType):