diff --git a/firmware/fsm.c b/firmware/fsm.c index 527f7756c4..1c4b86df83 100644 --- a/firmware/fsm.c +++ b/firmware/fsm.c @@ -580,21 +580,12 @@ void fsm_msgGetAddress(GetAddress *msg) HDNode *node = fsm_getDerivedNode(SECP256K1_NAME, msg->address_n, msg->address_n_count); if (!node) return; hdnode_fill_public_key(node); - bool is_segwit = 0; - if (!compute_address(coin, msg->script_type, node, msg->has_multisig, &msg->multisig, resp->address, &is_segwit)) { + if (!compute_address(coin, msg->script_type, node, msg->has_multisig, &msg->multisig, resp->address)) { fsm_sendFailure(FailureType_Failure_ActionCancelled, "Can't encode address"); } if (msg->has_show_display && msg->show_display) { - if (is_segwit) { - layoutSegwitWarning(); - if (!protectButton(ButtonRequestType_ButtonRequest_Address, false)) { - fsm_sendFailure(FailureType_Failure_ActionCancelled, "Show address cancelled"); - layoutHome(); - return; - } - } char desc[16]; if (msg->has_multisig) { strlcpy(desc, "Msig __ of __:", sizeof(desc)); diff --git a/firmware/layout2.c b/firmware/layout2.c index bb6516a9ec..0a8e665231 100644 --- a/firmware/layout2.c +++ b/firmware/layout2.c @@ -426,18 +426,3 @@ void layoutU2FDialog(const char *verb, const char *appname, const BITMAP *appico } layoutDialog(appicon, NULL, verb, NULL, verb, "U2F security key?", NULL, appname, NULL, NULL); } - -void layoutSegwitWarning() -{ - layoutDialogSwipe(&bmp_icon_info, - "Cancel", - "Understood", - NULL, - "The following address", - "is for SegWit soft fork.", - NULL, - "It is unsafe to use", - "until segwit activates.", - NULL - ); -} diff --git a/firmware/layout2.h b/firmware/layout2.h index 95633fa722..458fa55fda 100644 --- a/firmware/layout2.h +++ b/firmware/layout2.h @@ -45,6 +45,5 @@ void layoutPublicKey(const uint8_t *pubkey); void layoutSignIdentity(const IdentityType *identity, const char *challenge); void layoutDecryptIdentity(const IdentityType *identity); void layoutU2FDialog(const char *verb, const char *appname, const BITMAP *appicon); -void layoutSegwitWarning(void); #endif diff --git a/firmware/signing.c b/firmware/signing.c index 500595da91..4e5c197574 100644 --- a/firmware/signing.c +++ b/firmware/signing.c @@ -113,9 +113,9 @@ Phase2: sign inputs, check that nothing changed foreach I (idx1): // input to sign if (idx1 is segwit) Request I STAGE_REQUEST_SEGWIT_INPUT - Return serialized input chunk + Return serialized input chunk - else + else foreach I (idx2): Request I STAGE_REQUEST_4_INPUT If idx1 == idx2 @@ -771,6 +771,11 @@ void signing_txack(TransactionType *tx) send_req_2_prev_meta(); } else if (tx->inputs[0].script_type == InputScriptType_SPENDWITNESS || tx->inputs[0].script_type == InputScriptType_SPENDP2SHWITNESS) { + if (!coin->has_segwit || !coin->segwit) { + fsm_sendFailure(FailureType_Failure_Other, "Segwit not enabled on this coin"); + signing_abort(); + return; + } if (!tx->inputs[0].has_amount) { fsm_sendFailure(FailureType_Failure_Other, "Segwit input without amount"); signing_abort(); diff --git a/firmware/transaction.c b/firmware/transaction.c index 691f1ca056..5956f12c07 100644 --- a/firmware/transaction.c +++ b/firmware/transaction.c @@ -62,8 +62,7 @@ bool compute_address(const CoinType *coin, InputScriptType script_type, const HDNode *node, bool has_multisig, const MultisigRedeemScriptType *multisig, - char address[MAX_ADDR_SIZE], - bool *is_segwit) { + char address[MAX_ADDR_SIZE]) { uint8_t raw[32]; uint8_t digest[MAX_ADDR_RAW_SIZE]; @@ -78,7 +77,9 @@ bool compute_address(const CoinType *coin, } if (script_type == InputScriptType_SPENDWITNESS) { // segwit p2wsh: script hash is single sha256 - *is_segwit = 1; + if (!coin->has_segwit || !coin->segwit) { + return 0; + } if (!coin->has_address_type_p2wsh) { return 0; } @@ -92,7 +93,9 @@ bool compute_address(const CoinType *coin, } } else if (script_type == InputScriptType_SPENDP2SHWITNESS) { // segwit p2wsh encapsuled in p2sh address - *is_segwit = 1; + if (!coin->has_segwit || !coin->segwit) { + return 0; + } if (!coin->has_address_type_p2sh) { return 0; } @@ -108,7 +111,6 @@ bool compute_address(const CoinType *coin, } } else { // non-segwit p2sh multisig - *is_segwit = 0; prelen = address_prefix_bytes_len(coin->address_type_p2sh); address_write_prefix_bytes(coin->address_type_p2sh, raw); ripemd160(digest, 32, raw + prelen); @@ -118,7 +120,9 @@ bool compute_address(const CoinType *coin, } } else if (script_type == InputScriptType_SPENDWITNESS) { // segwit p2wpkh: pubkey hash is ripemd160 of sha256 - *is_segwit = 1; + if (!coin->has_segwit || !coin->segwit) { + return 0; + } if (!coin->has_address_type_p2wpkh) { return 0; } @@ -132,7 +136,9 @@ bool compute_address(const CoinType *coin, } } else if (script_type == InputScriptType_SPENDP2SHWITNESS) { // segwit p2wpkh embedded in p2sh - *is_segwit = 1; + if (!coin->has_segwit || !coin->segwit) { + return 0; + } if (!coin->has_address_type_p2sh) { return 0; } @@ -147,7 +153,6 @@ bool compute_address(const CoinType *coin, return 0; } } else { - *is_segwit = 0; ecdsa_get_address(node->public_key, coin->address_type, address, MAX_ADDR_SIZE); } return 1; @@ -159,7 +164,6 @@ int compile_output(const CoinType *coin, const HDNode *root, TxOutputType *in, T out->amount = in->amount; uint8_t addr_raw[MAX_ADDR_RAW_SIZE]; size_t addr_raw_len; - bool is_segwit; if (in->script_type == OutputScriptType_PAYTOOPRETURN) { // only 0 satoshi allowed for OP_RETURN @@ -201,7 +205,7 @@ int compile_output(const CoinType *coin, const HDNode *root, TxOutputType *in, T hdnode_fill_public_key(&node); if (!compute_address(coin, input_script_type, &node, in->has_multisig, &in->multisig, - in->address, &is_segwit)) { + in->address)) { return 0; // failed to compile output } } else if (!in->has_address) { diff --git a/firmware/transaction.h b/firmware/transaction.h index 808ccbca2e..06d07f765e 100644 --- a/firmware/transaction.h +++ b/firmware/transaction.h @@ -45,7 +45,7 @@ typedef struct { SHA256_CTX ctx; } TxStruct; -bool compute_address(const CoinType *coin, InputScriptType script_type, const HDNode *node, bool has_multisig, const MultisigRedeemScriptType *multisig, char address[MAX_ADDR_SIZE], bool *is_segwit); +bool compute_address(const CoinType *coin, InputScriptType script_type, const HDNode *node, bool has_multisig, const MultisigRedeemScriptType *multisig, char address[MAX_ADDR_SIZE]); uint32_t compile_script_sig(uint32_t address_type, const uint8_t *pubkeyhash, uint8_t *out); uint32_t compile_script_multisig(const MultisigRedeemScriptType *multisig, uint8_t *out); uint32_t compile_script_multisig_hash(const MultisigRedeemScriptType *multisig, uint8_t *hash);