From 8a4e8013f10faabc7792c93303f969a468222eb8 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Thu, 31 Jan 2019 21:17:00 +0100 Subject: [PATCH] firmware: process tx.branch_id (zcash) --- firmware/protob/Makefile | 2 +- firmware/signing.c | 14 ++++++++++---- vendor/trezor-common | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/firmware/protob/Makefile b/firmware/protob/Makefile index 0cf8453c18..dbdf0485db 100644 --- a/firmware/protob/Makefile +++ b/firmware/protob/Makefile @@ -26,7 +26,7 @@ messages_%_pb2.py: messages-%.proto $(Q)protoc -I/usr/include -I. $< --python_out=. messages_map.h: messages_map.py messages_pb2.py - $(Q)$(PYTHON) $< | grep -v -e MessageType_Cardano -e MessageType_Tezos -e MessageType_Ripple -e MessageType_Monero -e MessageType_DebugMonero -e MessageType_Ontology -e MessageType_Tron > $@ + $(Q)$(PYTHON) $< | grep -v -e MessageType_Cardano -e MessageType_Tezos -e MessageType_Ripple -e MessageType_Monero -e MessageType_DebugMonero -e MessageType_Ontology -e MessageType_Tron -e MessageType_Eos > $@ clean: rm -f *.pb *.o *.d *.pb.c *.pb.h *_pb2.py messages_map.h diff --git a/firmware/signing.c b/firmware/signing.c index 74c16d6e05..428fbd4d96 100644 --- a/firmware/signing.c +++ b/firmware/signing.c @@ -68,6 +68,7 @@ static uint32_t lock_time = 0; static uint32_t expiry = 0; static bool overwintered = false; static uint32_t version_group_id = 0; +static uint32_t branch_id = 0; static uint32_t next_nonsegwit_input; static uint32_t progress, progress_step, progress_meta_step; static bool multisig_fp_set, multisig_fp_mismatch; @@ -485,6 +486,7 @@ void signing_init(const SignTx *msg, const CoinInfo *_coin, const HDNode *_root) expiry = msg->expiry; overwintered = msg->has_overwintered && msg->overwintered; version_group_id = msg->version_group_id; + branch_id = msg->branch_id; uint32_t size = TXSIZE_HEADER + TXSIZE_FOOTER + ser_length_size(inputs_count) + ser_length_size(outputs_count); if (coin->decred) { @@ -768,9 +770,11 @@ static void signing_hash_bip143(const TxInputType *txinput, uint8_t *hash) { static void signing_hash_zip143(const TxInputType *txinput, uint8_t *hash) { uint32_t hash_type = signing_hash_type(); + uint8_t personal[16]; + memcpy(personal, "ZcashSigHash", 12); + memcpy(personal + 12, &branch_id, 4); Hasher hasher_preimage; - // BRANCH_ID = 0x5ba81b19 / Overwinter - hasher_InitParam(&hasher_preimage, HASHER_BLAKE2B_PERSONAL, "ZcashSigHash\x19\x1b\xa8\x5b", 16); + hasher_InitParam(&hasher_preimage, HASHER_BLAKE2B_PERSONAL, personal, sizeof(personal)); uint32_t ver = version | TX_OVERWINTERED; // 1. nVersion | fOverwintered hasher_Update(&hasher_preimage, (const uint8_t *)&ver, 4); hasher_Update(&hasher_preimage, (const uint8_t *)&version_group_id, 4); // 2. nVersionGroupId @@ -793,9 +797,11 @@ static void signing_hash_zip143(const TxInputType *txinput, uint8_t *hash) { static void signing_hash_zip243(const TxInputType *txinput, uint8_t *hash) { uint32_t hash_type = signing_hash_type(); + uint8_t personal[16]; + memcpy(personal, "ZcashSigHash", 12); + memcpy(personal + 12, &branch_id, 4); Hasher hasher_preimage; - // BRANCH_ID = 0x76b809bb / Sapling - hasher_InitParam(&hasher_preimage, HASHER_BLAKE2B_PERSONAL, "ZcashSigHash\xbb\x09\xb8\x76", 16); + hasher_InitParam(&hasher_preimage, HASHER_BLAKE2B_PERSONAL, personal, sizeof(personal)); uint32_t ver = version | TX_OVERWINTERED; // 1. nVersion | fOverwintered hasher_Update(&hasher_preimage, (const uint8_t *)&ver, 4); hasher_Update(&hasher_preimage, (const uint8_t *)&version_group_id, 4); // 2. nVersionGroupId diff --git a/vendor/trezor-common b/vendor/trezor-common index 495b35e212..4b41d2e638 160000 --- a/vendor/trezor-common +++ b/vendor/trezor-common @@ -1 +1 @@ -Subproject commit 495b35e212f48ea2ac9e356febd5a49c3ee5254b +Subproject commit 4b41d2e63841517bf701618434c018acf4f1bca2