diff --git a/include/btchip_helpers.h b/include/btchip_helpers.h index a99504b7..d29d08c2 100644 --- a/include/btchip_helpers.h +++ b/include/btchip_helpers.h @@ -39,6 +39,7 @@ unsigned char btchip_output_script_is_op_create(unsigned char *buffer, size_t size); unsigned char btchip_output_script_is_op_call(unsigned char *buffer, size_t size); +unsigned char btchip_output_script_is_empty(unsigned char *buffer); void btchip_sleep16(unsigned short delay); void btchip_sleep32(unsigned long int delayEach, unsigned long int delayRepeat); diff --git a/src/btchip_apdu_hash_input_finalize_full.c b/src/btchip_apdu_hash_input_finalize_full.c index dfb1cd9c..0a9b3ea5 100644 --- a/src/btchip_apdu_hash_input_finalize_full.c +++ b/src/btchip_apdu_hash_input_finalize_full.c @@ -45,6 +45,7 @@ static bool check_output_displayable() { unsigned char amount[8], isOpReturn, isP2sh, isNativeSegwit, j, nullAmount = 1; unsigned char isOpCreate, isOpCall; + bool isRecognizedOutputScript = false; for (j = 0; j < 8; j++) { if (btchip_context_D.currentOutput[j] != 0) { @@ -68,12 +69,17 @@ static bool check_output_displayable() { isOpCall = btchip_output_script_is_op_call(btchip_context_D.currentOutput + 8, sizeof(btchip_context_D.currentOutput) - 8); - if (((G_coin_config->kind == COIN_KIND_QTUM || G_coin_config->kind == COIN_KIND_HYDRA) && - !btchip_output_script_is_regular(btchip_context_D.currentOutput + 8) && - !isP2sh && !(nullAmount && isOpReturn) && !isOpCreate && !isOpCall) || - (!(G_coin_config->kind == COIN_KIND_QTUM || G_coin_config->kind == COIN_KIND_HYDRA) && - !btchip_output_script_is_regular(btchip_context_D.currentOutput + 8) && - !isP2sh && !(nullAmount && isOpReturn))) { + if (btchip_output_script_is_regular(btchip_context_D.currentOutput + 8) || + isP2sh || (nullAmount && isOpReturn)) { + isRecognizedOutputScript = true; + } else if (G_coin_config->kind == COIN_KIND_QTUM || G_coin_config->kind == COIN_KIND_HYDRA) { + if (isOpCreate || isOpCall) + isRecognizedOutputScript = true; + } else if (G_coin_config->kind == COIN_KIND_PEERCOIN) { + if (nullAmount) + isRecognizedOutputScript = true; + } + if (!isRecognizedOutputScript) { PRINTF("Error : Unrecognized output script"); THROW(EXCEPTION); } diff --git a/src/btchip_helpers.c b/src/btchip_helpers.c index a7131b0c..76f2351b 100644 --- a/src/btchip_helpers.c +++ b/src/btchip_helpers.c @@ -149,6 +149,10 @@ unsigned char btchip_output_script_is_op_call(unsigned char *buffer, return output_script_is_op_create_or_call(buffer, size, 0xC2); } +unsigned char btchip_output_script_is_empty(unsigned char *buffer) { + return buffer[0] == 0; +} + unsigned char btchip_rng_u8_modulo(unsigned char modulo) { unsigned int rng_max = 256 % modulo; unsigned int rng_limit = 256 - rng_max; diff --git a/src/main.c b/src/main.c index b4069954..9854cfc4 100644 --- a/src/main.c +++ b/src/main.c @@ -812,7 +812,7 @@ uint8_t prepare_fees() { borrow = transaction_amount_sub_be( fees, btchip_context_D.transactionContext.transactionAmount, btchip_context_D.totalOutputAmount); - if (borrow && G_coin_config->kind == COIN_KIND_KOMODO) { + if (borrow && (G_coin_config->kind == COIN_KIND_KOMODO || G_coin_config->kind == COIN_KIND_PEERCOIN)) { os_memmove(vars.tmp.feesAmount, "REWARD", 6); vars.tmp.feesAmount[6] = '\0'; } @@ -846,6 +846,10 @@ void get_address_from_output_script(unsigned char* script, int script_size, char strcpy(out, "OP_RETURN"); return; } + if (G_coin_config->kind == COIN_KIND_PEERCOIN && btchip_output_script_is_empty(script)) { + strcpy(out, "COINSTAKE"); + return; + } if ((G_coin_config->kind == COIN_KIND_QTUM || G_coin_config->kind == COIN_KIND_HYDRA) && btchip_output_script_is_op_create(script, script_size)) { strcpy(out, "OP_CREATE");