From ce307c948426750abca11687829c8b6a0087d1da Mon Sep 17 00:00:00 2001 From: matejcik Date: Thu, 20 Oct 2022 15:51:16 +0200 Subject: [PATCH] feat(common): mark CoSi fields as required [no changelog] --- common/protob/messages-crypto.proto | 10 +++++----- core/src/trezor/messages.py | 20 ++++++++++---------- legacy/firmware/fsm_msg_crypto.h | 8 ++------ python/src/trezorlib/messages.py | 20 ++++++++++---------- 4 files changed, 27 insertions(+), 31 deletions(-) diff --git a/common/protob/messages-crypto.proto b/common/protob/messages-crypto.proto index 4953e6159..f33f9609e 100644 --- a/common/protob/messages-crypto.proto +++ b/common/protob/messages-crypto.proto @@ -106,8 +106,8 @@ message CosiCommit { * @end */ message CosiCommitment { - optional bytes commitment = 1; // Commitment - optional bytes pubkey = 2; // Public key + required bytes commitment = 1; // Commitment + required bytes pubkey = 2; // Public key } /** @@ -118,9 +118,9 @@ message CosiCommitment { */ message CosiSign { repeated uint32 address_n = 1; // BIP-32 path to derive the key from master node - optional bytes data = 2; // Data to be signed - optional bytes global_commitment = 3; // Aggregated commitment - optional bytes global_pubkey = 4; // Aggregated public key + required bytes data = 2; // Data to be signed + required bytes global_commitment = 3; // Aggregated commitment + required bytes global_pubkey = 4; // Aggregated public key } /** diff --git a/core/src/trezor/messages.py b/core/src/trezor/messages.py index e676378dd..8963ea4cb 100644 --- a/core/src/trezor/messages.py +++ b/core/src/trezor/messages.py @@ -1992,14 +1992,14 @@ if TYPE_CHECKING: return isinstance(msg, cls) class CosiCommitment(protobuf.MessageType): - commitment: "bytes | None" - pubkey: "bytes | None" + commitment: "bytes" + pubkey: "bytes" def __init__( self, *, - commitment: "bytes | None" = None, - pubkey: "bytes | None" = None, + commitment: "bytes", + pubkey: "bytes", ) -> None: pass @@ -2009,17 +2009,17 @@ if TYPE_CHECKING: class CosiSign(protobuf.MessageType): address_n: "list[int]" - data: "bytes | None" - global_commitment: "bytes | None" - global_pubkey: "bytes | None" + data: "bytes" + global_commitment: "bytes" + global_pubkey: "bytes" def __init__( self, *, + data: "bytes", + global_commitment: "bytes", + global_pubkey: "bytes", address_n: "list[int] | None" = None, - data: "bytes | None" = None, - global_commitment: "bytes | None" = None, - global_pubkey: "bytes | None" = None, ) -> None: pass diff --git a/legacy/firmware/fsm_msg_crypto.h b/legacy/firmware/fsm_msg_crypto.h index 72f2cdb28..3aa52dd95 100644 --- a/legacy/firmware/fsm_msg_crypto.h +++ b/legacy/firmware/fsm_msg_crypto.h @@ -276,8 +276,6 @@ void fsm_msgCosiCommit(const CosiCommit *msg) { cosi_nonce_is_set = true; } - resp->has_commitment = true; - resp->has_pubkey = true; resp->commitment.size = 32; resp->pubkey.size = 32; @@ -293,11 +291,9 @@ void fsm_msgCosiSign(const CosiSign *msg) { CHECK_INITIALIZED - CHECK_PARAM(msg->has_data, _("No data provided")); - CHECK_PARAM(msg->has_global_commitment && msg->global_commitment.size == 32, + CHECK_PARAM(msg->global_commitment.size == 32, _("Invalid global commitment")); - CHECK_PARAM(msg->has_global_pubkey && msg->global_pubkey.size == 32, - _("Invalid global pubkey")); + CHECK_PARAM(msg->global_pubkey.size == 32, _("Invalid global pubkey")); if (!cosi_nonce_is_set) { fsm_sendFailure(FailureType_Failure_ProcessError, _("CoSi nonce not set")); diff --git a/python/src/trezorlib/messages.py b/python/src/trezorlib/messages.py index 7d2d43b2b..a060c6c30 100644 --- a/python/src/trezorlib/messages.py +++ b/python/src/trezorlib/messages.py @@ -3020,15 +3020,15 @@ class CosiCommit(protobuf.MessageType): class CosiCommitment(protobuf.MessageType): MESSAGE_WIRE_TYPE = 72 FIELDS = { - 1: protobuf.Field("commitment", "bytes", repeated=False, required=False, default=None), - 2: protobuf.Field("pubkey", "bytes", repeated=False, required=False, default=None), + 1: protobuf.Field("commitment", "bytes", repeated=False, required=True), + 2: protobuf.Field("pubkey", "bytes", repeated=False, required=True), } def __init__( self, *, - commitment: Optional["bytes"] = None, - pubkey: Optional["bytes"] = None, + commitment: "bytes", + pubkey: "bytes", ) -> None: self.commitment = commitment self.pubkey = pubkey @@ -3038,18 +3038,18 @@ class CosiSign(protobuf.MessageType): MESSAGE_WIRE_TYPE = 73 FIELDS = { 1: protobuf.Field("address_n", "uint32", repeated=True, required=False, default=None), - 2: protobuf.Field("data", "bytes", repeated=False, required=False, default=None), - 3: protobuf.Field("global_commitment", "bytes", repeated=False, required=False, default=None), - 4: protobuf.Field("global_pubkey", "bytes", repeated=False, required=False, default=None), + 2: protobuf.Field("data", "bytes", repeated=False, required=True), + 3: protobuf.Field("global_commitment", "bytes", repeated=False, required=True), + 4: protobuf.Field("global_pubkey", "bytes", repeated=False, required=True), } def __init__( self, *, + data: "bytes", + global_commitment: "bytes", + global_pubkey: "bytes", address_n: Optional[Sequence["int"]] = None, - data: Optional["bytes"] = None, - global_commitment: Optional["bytes"] = None, - global_pubkey: Optional["bytes"] = None, ) -> None: self.address_n: Sequence["int"] = address_n if address_n is not None else [] self.data = data