diff --git a/app/Makefile.version b/app/Makefile.version index ca6bd018..02cf60bc 100644 --- a/app/Makefile.version +++ b/app/Makefile.version @@ -3,4 +3,4 @@ APPVERSION_M=2 # This is the `spec_version` field of `Runtime` APPVERSION_N=35 # This is the patch version of this release -APPVERSION_P=11 +APPVERSION_P=12 diff --git a/app/src/apdu_handler.c b/app/src/apdu_handler.c index 3222c96f..a7ed6dc5 100644 --- a/app/src/apdu_handler.c +++ b/app/src/apdu_handler.c @@ -63,6 +63,7 @@ __Z_INLINE void handle_getversion(__Z_UNUSED volatile uint32_t *flags, volatile } __Z_INLINE uint8_t extractHRP(uint32_t rx, uint32_t offset) { + uint8_t hrp_len = 0; if (rx < offset + 1) { THROW(APDU_CODE_DATA_INVALID); } @@ -77,10 +78,15 @@ __Z_INLINE uint8_t extractHRP(uint32_t rx, uint32_t offset) { memcpy(bech32_hrp, G_io_apdu_buffer + offset + 1, bech32_hrp_len); bech32_hrp[bech32_hrp_len] = 0; // zero terminate - return bech32_hrp_len; + hrp_len = bech32_hrp_len; + return hrp_len; } __Z_INLINE void extractHDPath(uint32_t rx, uint32_t offset) { + if (rx < offset + 1) { + THROW(APDU_CODE_DATA_INVALID); + } + if ((rx - offset) < sizeof(uint32_t) * HDPATH_LEN_DEFAULT) { THROW(APDU_CODE_WRONG_LENGTH); } @@ -110,8 +116,8 @@ static void extractHDPath_HRP(uint32_t rx, uint32_t offset) { // Check if HRP was sent if ((rx - offset) > sizeof(uint32_t) * HDPATH_LEN_DEFAULT) { - extractHRP(rx, offset + sizeof(uint32_t) * HDPATH_LEN_DEFAULT); - encoding = checkChainConfig(hdPath[1], bech32_hrp, bech32_hrp_len); + uint8_t hrp_bech32_len = extractHRP(rx, offset + sizeof(uint32_t) * HDPATH_LEN_DEFAULT); + encoding = checkChainConfig(hdPath[1], bech32_hrp, hrp_bech32_len); if (encoding == UNSUPPORTED) { ZEMU_LOGF(50, "Chain config not supported for: %s\n", bech32_hrp) THROW(APDU_CODE_COMMAND_NOT_ALLOWED); diff --git a/app/src/cbor/cbor_parser_helper.c b/app/src/cbor/cbor_parser_helper.c index a6d02b4a..59af1ee3 100644 --- a/app/src/cbor/cbor_parser_helper.c +++ b/app/src/cbor/cbor_parser_helper.c @@ -35,6 +35,9 @@ parser_error_t parser_mapCborError(CborError err) { } static parser_error_t cbor_check_optFields(CborValue *data, Cbor_container *container) { + if (data == NULL || container == NULL) { + return parser_unexpected_value; + } int key; for (size_t i = 0; i < container->n_field; i++) { @@ -67,6 +70,10 @@ static parser_error_t cbor_check_optFields(CborValue *data, Cbor_container *cont } static parser_error_t cbor_check_screen(CborValue *data, Cbor_container *container) { + if (data == NULL || container == NULL) { + return parser_unexpected_value; + } + int screen_key; //check title Key PARSER_ASSERT_OR_ERROR(cbor_value_is_integer(data), parser_unexpected_type) diff --git a/app/src/crypto.c b/app/src/crypto.c index f2972e4e..eb3c280e 100644 --- a/app/src/crypto.c +++ b/app/src/crypto.c @@ -29,7 +29,7 @@ uint32_t hdPath[HDPATH_LEN_DEFAULT]; uint8_t bech32_hrp_len; char bech32_hrp[MAX_BECH32_HRP_LEN + 1]; -address_encoding_e encoding; +address_encoding_e encoding = BECH32_COSMOS; #include "cx.h" @@ -73,15 +73,7 @@ static zxerr_t crypto_extractUncompressedPublicKey(uint8_t *pubKey, uint16_t pub __Z_INLINE zxerr_t compressPubkey(const uint8_t *pubkey, uint16_t pubkeyLen, uint8_t *output, uint16_t outputLen) { if (pubkey == NULL || output == NULL || pubkeyLen != PK_LEN_SECP256K1_UNCOMPRESSED || outputLen < PK_LEN_SECP256K1) { - return zxerr_unknown; - } - - // Format pubkey - for (int i = 0; i < 32; i++) { - output[i] = pubkey[64 - i]; - } - if ((pubkey[32] & 1) != 0) { - output[31] |= 0x80; + return zxerr_invalid_crypto_settings; } MEMCPY(output, pubkey, PK_LEN_SECP256K1); @@ -194,7 +186,7 @@ zxerr_t crypto_fillAddress(uint8_t *buffer, uint16_t buffer_len, uint16_t *addrR case BECH32_COSMOS: { // Hash it cx_hash_sha256(buffer, PK_LEN_SECP256K1, hashed1_pk, CX_SHA256_SIZE); - uint8_t hashed2_pk[CX_RIPEMD160_SIZE]; + uint8_t hashed2_pk[CX_RIPEMD160_SIZE] = {0}; ripemd160_32(hashed2_pk, hashed1_pk); CHECK_ZXERR(bech32EncodeFromBytes(addr, buffer_len - PK_LEN_SECP256K1, bech32_hrp, hashed2_pk, CX_RIPEMD160_SIZE, 1, BECH32_ENCODING_BECH32)) break; diff --git a/app/src/crypto.h b/app/src/crypto.h index 12a0ea6e..7b216290 100644 --- a/app/src/crypto.h +++ b/app/src/crypto.h @@ -33,8 +33,6 @@ extern char bech32_hrp[MAX_BECH32_HRP_LEN + 1]; extern uint8_t bech32_hrp_len; extern address_encoding_e encoding; -void crypto_set_hrp(char *p); - zxerr_t crypto_fillAddress(uint8_t *buffer, uint16_t bufferLen, uint16_t *addrResponseLen); zxerr_t crypto_sign(uint8_t *signature, uint16_t signatureMaxlen, uint16_t *signatureLen); diff --git a/app/src/parser.c b/app/src/parser.c index 0292e760..c590eeb7 100644 --- a/app/src/parser.c +++ b/app/src/parser.c @@ -90,75 +90,85 @@ parser_error_t parser_getNumItems(const parser_context_t *ctx, uint8_t *num_item return tx_display_numItems(num_items); } -__Z_INLINE bool_t parser_areEqual(uint16_t tokenIdx, const char *expected) { +__Z_INLINE bool parser_areEqual(uint16_t tokenIdx, const char *expected) { if (parser_tx_obj.tx_json.json.tokens[tokenIdx].type != JSMN_STRING) { - return bool_false; + return false; } int32_t len = parser_tx_obj.tx_json.json.tokens[tokenIdx].end - parser_tx_obj.tx_json.json.tokens[tokenIdx].start; if (len < 0) { - return bool_false; + return false; } if (strlen(expected) != (size_t) len) { - return bool_false; + return false; } const char *p = parser_tx_obj.tx_json.tx + parser_tx_obj.tx_json.json.tokens[tokenIdx].start; for (int32_t i = 0; i < len; i++) { if (expected[i] != *(p + i)) { - return bool_false; + return false; } } - return bool_true; + return true; } -__Z_INLINE bool_t parser_isAmount(char *key) { +__Z_INLINE bool parser_isAmount(char *key) { if (strcmp(key, "fee/amount") == 0) { - return bool_true; + return true; } if (strcmp(key, "msgs/inputs/coins") == 0) { - return bool_true; + return true; } if (strcmp(key, "msgs/outputs/coins") == 0) { - return bool_true; + return true; } if (strcmp(key, "msgs/value/inputs/coins") == 0) { - return bool_true; + return true; } if (strcmp(key, "msgs/value/outputs/coins") == 0) { - return bool_true; + return true; } if (strcmp(key, "msgs/value/amount") == 0) { - return bool_true; + return true; } if (strcmp(key, "tip/amount") == 0) { - return bool_true; + return true; } - return bool_false; + return false; } -__Z_INLINE bool_t is_default_denom_base(const char *denom, uint8_t denom_len) { - if (tx_is_expert_mode()) { - return false; +__Z_INLINE parser_error_t is_default_denom_base(const char *denom, uint8_t denom_len, bool *is_default) { + if (is_default == NULL) { + return parser_unexpected_value; + } + + bool is_expert_or_default = false; + CHECK_PARSER_ERR(tx_is_expert_mode_or_not_default_chainid(&is_expert_or_default)) + if (is_expert_or_default) { + *is_default = false; + return parser_ok; } if (strlen(COIN_DEFAULT_DENOM_BASE) != denom_len) { - return bool_false; + *is_default = false; + return parser_ok; } - if (memcmp(denom, COIN_DEFAULT_DENOM_BASE, denom_len) == 0) - return bool_true; + if (memcmp(denom, COIN_DEFAULT_DENOM_BASE, denom_len) == 0) { + *is_default = true; + return parser_ok; + } - return bool_false; + return parser_ok; } __Z_INLINE parser_error_t parser_formatAmountItem(uint16_t amountToken, @@ -199,10 +209,11 @@ __Z_INLINE parser_error_t parser_formatAmountItem(uint16_t amountToken, MEMZERO(outVal, outValLen); MEMZERO(bufferUI, sizeof(bufferUI)); - const char *amountPtr = parser_tx_obj.tx_json.tx + parser_tx_obj.tx_json.json.tokens[amountToken + 2].start; - if (parser_tx_obj.tx_json.json.tokens[amountToken + 2].start < 0) { + if (parser_tx_obj.tx_json.json.tokens[amountToken + 2].start < 0 || + parser_tx_obj.tx_json.json.tokens[amountToken + 4].start < 0) { return parser_unexpected_buffer_end; } + const char *amountPtr = parser_tx_obj.tx_json.tx + parser_tx_obj.tx_json.json.tokens[amountToken + 2].start; const int32_t amountLen = parser_tx_obj.tx_json.json.tokens[amountToken + 2].end - parser_tx_obj.tx_json.json.tokens[amountToken + 2].start; @@ -228,7 +239,9 @@ __Z_INLINE parser_error_t parser_formatAmountItem(uint16_t amountToken, snprintf(bufferUI, sizeof(bufferUI), "%s ", tmpAmount); // If denomination has been recognized format and replace - if (is_default_denom_base(denomPtr, denomLen)) { + bool is_default =false; + CHECK_PARSER_ERR(is_default_denom_base(denomPtr, denomLen, &is_default)) + if (is_default) { if (fpstr_to_str(bufferUI, sizeof(bufferUI), tmpAmount, COIN_DEFAULT_DENOM_FACTOR) != 0) { return parser_unexpected_error; } @@ -253,7 +266,7 @@ __Z_INLINE parser_error_t parser_formatAmount(uint16_t amountToken, } uint8_t totalPages = 0; - bool_t showItemSet = false; + uint8_t showItemSet = 0; uint8_t showPageIdx = pageIdx; uint16_t showItemTokenIdx = 0; @@ -274,7 +287,7 @@ __Z_INLINE parser_error_t parser_formatAmount(uint16_t amountToken, if (!showItemSet) { if (showPageIdx < subpagesCount) { - showItemSet = true; + showItemSet = 1; showItemTokenIdx = itemTokenIdx; ZEMU_LOGF(200, "[formatAmount] [%d] [SET] TokenIdx %d - PageIdx: %d", i, showItemTokenIdx, showPageIdx) @@ -329,6 +342,9 @@ __Z_INLINE parser_error_t parser_screenPrint(const parser_context_t *ctx, //Translate output, cpy to tmp to assure it ends in \0 MEMZERO(tmp, tmp_len); + if(container->screen.contentPtr == NULL) { + return parser_unexpected_value; + } MEMCPY(tmp, container->screen.contentPtr, container->screen.contentLen); CHECK_PARSER_ERR(tx_display_translation(out, sizeof(out), tmp,container->screen.contentLen)) @@ -344,6 +360,9 @@ __Z_INLINE parser_error_t parser_screenPrint(const parser_context_t *ctx, } MEMZERO(ctx->tx_obj->tx_text.tmpBuffer, sizeof(ctx->tx_obj->tx_text.tmpBuffer)); + if(container->screen.titlePtr == NULL) { + return parser_unexpected_value; + } MEMCPY(tmp, container->screen.titlePtr, container->screen.titleLen); MEMCPY(tmp + container->screen.titleLen,": ",2); MEMCPY(tmp + container->screen.titleLen + 2, out, sizeof(out) - container->screen.titleLen -2); @@ -354,6 +373,9 @@ __Z_INLINE parser_error_t parser_screenPrint(const parser_context_t *ctx, //Normal print case - Prepare title char key[MAX_TITLE_SIZE + 2] = {0}; + if(container->screen.titlePtr == NULL) { + return parser_unexpected_value; + } MEMCPY(key, container->screen.titlePtr, container->screen.titleLen); for (uint8_t i = 0; i < container->screen.indent; i++) { z_str3join(key, sizeof(key), SCREEN_INDENT, ""); @@ -438,6 +460,16 @@ __Z_INLINE parser_error_t parser_getTextualItem(const parser_context_t *ctx, container.screen.expert = false; CHECK_PARSER_ERR(parser_getScreenInfo(ctx, &container, displayIdx)) + // title and content can be Null depending on the screen for chain id they cant be null + if (container.screen.titlePtr != NULL && container.screen.contentPtr != NULL) { + if (!strncmp(container.screen.titlePtr, "Chain id", container.screen.titleLen)){ + if(!strncmp(container.screen.contentPtr, "0", container.screen.contentLen) || + !strncmp(container.screen.contentPtr, "1", container.screen.contentLen)) { + return parser_unexpected_chain; + } + } + } + if (!app_mode_expert()) { CHECK_PARSER_ERR(parser_getNextNonExpert(ctx, &container, displayIdx)) } @@ -467,7 +499,7 @@ __Z_INLINE parser_error_t parser_getJsonItem(const parser_context_t *ctx, return parser_unexpected_number_items; } - if (displayIdx < 0 || displayIdx >= numItems) { + if (displayIdx >= numItems) { return parser_display_idx_out_of_range; } diff --git a/app/src/tx_display.c b/app/src/tx_display.c index 787e745e..208d436d 100644 --- a/app/src/tx_display.c +++ b/app/src/tx_display.c @@ -131,6 +131,9 @@ __Z_INLINE parser_error_t calculate_is_default_chainid() { // If we don't match the default chainid, switch to expert mode display_cache.is_default_chain = true; zemu_log_stack("DEFAULT Chain "); + } else if ((outVal[0] == 0x30 || outVal[0] == 0x31) && strlen(outVal) == 1) { + zemu_log_stack("Not Allowed chain"); + return parser_unexpected_chain; } else { zemu_log_stack("Chain is NOT DEFAULT"); } @@ -301,7 +304,9 @@ parser_error_t tx_indexRootFields() { CHECK_PARSER_ERR(calculate_is_default_chainid()) // turn off grouping if we are not in expert mode - if (tx_is_expert_mode()) { + bool is_expert_or_default = false; + CHECK_PARSER_ERR(tx_is_expert_mode_or_not_default_chainid(&is_expert_or_default)) + if (is_expert_or_default) { parser_tx_obj.tx_json.flags.msg_from_grouping = 0; } @@ -314,27 +319,49 @@ parser_error_t tx_indexRootFields() { return parser_ok; } -__Z_INLINE bool is_default_chainid() { +__Z_INLINE parser_error_t is_default_chainid(bool *is_default) { + if (is_default == NULL) { + return parser_unexpected_value; + } + CHECK_PARSER_ERR(tx_indexRootFields()) - return display_cache.is_default_chain; + *is_default = display_cache.is_default_chain; + + return parser_ok; } -bool tx_is_expert_mode() { - return app_mode_expert() || !is_default_chainid(); +parser_error_t tx_is_expert_mode_or_not_default_chainid(bool *expert_or_default) { + if (expert_or_default == NULL) { + return parser_unexpected_value; + } + + bool is_default = false; + CHECK_PARSER_ERR(is_default_chainid(&is_default)) + *expert_or_default = app_mode_expert() || !is_default; + + return parser_ok; } -__Z_INLINE uint8_t get_subitem_count(root_item_e root_item) { +__Z_INLINE parser_error_t get_subitem_count(root_item_e root_item, uint8_t *num_items) { + if (num_items == NULL) { + return parser_unexpected_value; + } + CHECK_PARSER_ERR(tx_indexRootFields()) - if (display_cache.total_item_count == 0) - return 0; + if (display_cache.total_item_count == 0) { + *num_items = 0; + return parser_ok; + } int32_t tmp_num_items = display_cache.root_item_number_subitems[root_item]; - + bool is_expert_or_default = false; + switch (root_item) { case root_item_chain_id: case root_item_sequence: case root_item_account_number: - if (!tx_is_expert_mode()) { + CHECK_PARSER_ERR(tx_is_expert_mode_or_not_default_chainid(&is_expert_or_default)) + if (!is_expert_or_default) { tmp_num_items = 0; } break; @@ -355,7 +382,8 @@ __Z_INLINE uint8_t get_subitem_count(root_item_e root_item) { case root_item_memo: break; case root_item_fee: - if (!tx_is_expert_mode()) { + CHECK_PARSER_ERR(tx_is_expert_mode_or_not_default_chainid(&is_expert_or_default)) + if (!is_expert_or_default) { tmp_num_items = 1; // Only Amount } break; @@ -365,8 +393,9 @@ __Z_INLINE uint8_t get_subitem_count(root_item_e root_item) { default: break; } + *num_items = tmp_num_items; - return tmp_num_items; + return parser_ok; } __Z_INLINE parser_error_t retrieve_tree_indexes(uint8_t display_index, root_item_e *root_item, uint8_t *subitem_index) { @@ -374,19 +403,28 @@ __Z_INLINE parser_error_t retrieve_tree_indexes(uint8_t display_index, root_item // consume indexed subpages until we get the item index in the subpage *root_item = 0; *subitem_index = 0; - while (get_subitem_count(*root_item) == 0) { + uint8_t num_items; + + CHECK_PARSER_ERR(get_subitem_count(*root_item, &num_items)); + while (num_items == 0) { (*root_item)++; + CHECK_PARSER_ERR(get_subitem_count(*root_item, &num_items)); } for (uint16_t i = 0; i < display_index; i++) { (*subitem_index)++; - const uint8_t subitem_count = get_subitem_count(*root_item); + uint8_t subitem_count = 0; + CHECK_PARSER_ERR(get_subitem_count(*root_item, &subitem_count)); if (*subitem_index >= subitem_count) { // Advance root index and skip empty items *subitem_index = 0; (*root_item)++; - while (get_subitem_count(*root_item) == 0) { + + uint8_t num_items_2 = 0; + CHECK_PARSER_ERR(get_subitem_count(*root_item, &num_items_2)); + while (num_items_2 == 0) { (*root_item)++; + CHECK_PARSER_ERR(get_subitem_count(*root_item, &num_items_2)); } } } @@ -403,8 +441,10 @@ parser_error_t tx_display_numItems(uint8_t *num_items) { CHECK_PARSER_ERR(tx_indexRootFields()) *num_items = 0; + uint8_t n_items = 0; for (root_item_e root_item = 0; root_item < NUM_REQUIRED_ROOT_PAGES; root_item++) { - *num_items += get_subitem_count(root_item); + CHECK_PARSER_ERR( get_subitem_count(root_item, &n_items)) + *num_items += n_items; } return parser_ok; @@ -419,7 +459,7 @@ parser_error_t tx_display_query(uint16_t displayIdx, uint8_t num_items; CHECK_PARSER_ERR(tx_display_numItems(&num_items)) - if (displayIdx < 0 || displayIdx >= num_items) { + if (displayIdx >= num_items) { return parser_display_idx_out_of_range; } diff --git a/app/src/tx_display.h b/app/src/tx_display.h index 73b167f5..5130a482 100644 --- a/app/src/tx_display.h +++ b/app/src/tx_display.h @@ -36,7 +36,7 @@ typedef enum { root_item_tip, } root_item_e; -bool tx_is_expert_mode(); +parser_error_t tx_is_expert_mode_or_not_default_chainid(bool *expert_or_default); const char *get_required_root_item(root_item_e i); diff --git a/fuzzing/parser_parse.cpp b/fuzz/parser_parse.cpp similarity index 80% rename from fuzzing/parser_parse.cpp rename to fuzz/parser_parse.cpp index 69d6ba61..1cc4fd9e 100644 --- a/fuzzing/parser_parse.cpp +++ b/fuzz/parser_parse.cpp @@ -3,6 +3,7 @@ #include #include "parser.h" +#include "zxformat.h" #ifdef NDEBUG @@ -11,22 +12,27 @@ using std::size_t; +namespace { + char PARSER_KEY[16384]; + char PARSER_VALUE[16384]; +} -static char PARSER_KEY[16384]; -static char PARSER_VALUE[16384]; extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { parser_context_t ctx; parser_error_t rc; + parser_tx_t tx_obj; + MEMZERO(&tx_obj, sizeof(tx_obj)); char buffer[1000]; array_to_hexstr(buffer, sizeof(buffer), data, size); - fprintf(stderr, "%s\n", buffer); + + (void)fprintf(stderr, "%s\n", buffer); - fprintf(stderr, "----------------------------------------------\n"); + (void)fprintf(stderr, "----------------------------------------------\n"); - rc = parser_parse(&ctx, data, size); + rc = parser_parse(&ctx, data, size, &tx_obj); if (rc != parser_ok) { return 0; } @@ -39,7 +45,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) uint8_t num_items; rc = parser_getNumItems(&ctx, &num_items); if (rc != parser_ok) { - fprintf(stderr, + (void)fprintf(stderr, "error in parser_getNumItems: %s\n", parser_getErrorDescription(rc)); assert(false); @@ -57,7 +63,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) // fprintf(stderr, "%s = %s\n", PARSER_KEY, PARSER_VALUE); if (rc != parser_ok) { - fprintf(stderr, + (void)fprintf(stderr, "error getting item %u at page index %u: %s\n", (unsigned)i, (unsigned)page_idx, diff --git a/fuzzing/run-fuzz-crashes.py b/fuzz/run-fuzz-crashes.py similarity index 100% rename from fuzzing/run-fuzz-crashes.py rename to fuzz/run-fuzz-crashes.py diff --git a/fuzzing/run-fuzzers.py b/fuzz/run-fuzzers.py similarity index 100% rename from fuzzing/run-fuzzers.py rename to fuzz/run-fuzzers.py diff --git a/tests/common.cpp b/tests/common.cpp index 276d9c19..f8e49866 100644 --- a/tests/common.cpp +++ b/tests/common.cpp @@ -99,6 +99,7 @@ TEST(Address, EVMAddressEvmos) { const char bech32_hrp[] = "evmos"; char address[100] = {0}; const zxerr_t err = bech32EncodeFromBytes(address, sizeof(address), bech32_hrp, eth_address, 20, 0, BECH32_ENCODING_BECH32); + EXPECT_EQ(err, zxerr_ok); const std::string evm_address(address, address + strnlen(address, sizeof(address))); EXPECT_EQ(evm_address, "evmos1dj7dw0xcazjzs3rx9u9quakh77d0myeamrkupf"); @@ -125,7 +126,8 @@ TEST(Address, EVMAddressCosmos) { const char bech32_hrp[] = "cosmos"; char address[100] = {0}; const zxerr_t err = bech32EncodeFromBytes(address, sizeof(address), bech32_hrp, eth_address, 20, 0, BECH32_ENCODING_BECH32); - + EXPECT_EQ(err, zxerr_ok); + const std::string evm_address(address, address + strnlen(address, sizeof(address))); EXPECT_EQ(evm_address, "cosmos15n2h0lzvfgc8x4fm6fdya89n78x6ee2fm7fxr3"); } diff --git a/tests/testcases.cpp b/tests/testcases.cpp index cb497cbc..8fc64886 100644 --- a/tests/testcases.cpp +++ b/tests/testcases.cpp @@ -21,11 +21,11 @@ std::vector GetJsonTestCases(const std::string &jsonFile) { auto answer = std::vector(); - Json::CharReaderBuilder builder; - std::shared_ptr obj(new Json::Value()); + const Json::CharReaderBuilder builder; + const std::shared_ptr obj(new Json::Value()); - std::string fullPathJsonFile = std::string(TESTVECTORS_DIR) + jsonFile; + const std::string fullPathJsonFile = std::string(TESTVECTORS_DIR) + jsonFile; std::ifstream inFile(fullPathJsonFile); if (!inFile.is_open()) { @@ -44,7 +44,7 @@ std::vector GetJsonTestCases(const std::string &jsonFile) { Json::StreamWriterBuilder wbuilder; wbuilder["commentStyle"] = "None"; wbuilder["indentation"] = ""; - std::string txStr = Json::writeString(wbuilder, v["tx"]); + const std::string txStr = Json::writeString(wbuilder, v["tx"]); auto expected = std::vector(); for (const auto j : v["expected"]) { @@ -73,10 +73,10 @@ std::vector GetJsonTestCases(const std::string &jsonFile) { std::vector GetJsonTextualTestCases(const std::string &jsonFile) { auto answer = std::vector(); - Json::CharReaderBuilder builder; + const Json::CharReaderBuilder builder; Json::Value obj; - std::string fullPathJsonFile = std::string(TESTVECTORS_DIR) + jsonFile; + const std::string fullPathJsonFile = std::string(TESTVECTORS_DIR) + jsonFile; std::ifstream inFile(fullPathJsonFile); if (!inFile.is_open()) { diff --git a/tests/tx_parse.cpp b/tests/tx_parse.cpp index 78976c91..f4c7b2aa 100644 --- a/tests/tx_parse.cpp +++ b/tests/tx_parse.cpp @@ -26,7 +26,7 @@ namespace { #pragma ide diagnostic ignored "ConstantParameter" parser_error_t tx_traverse(int16_t root_token_index, uint8_t *numChunks) { uint16_t ret_value_token_index = 0; - parser_error_t err = tx_traverse_find(root_token_index, &ret_value_token_index); + const parser_error_t err = tx_traverse_find(root_token_index, &ret_value_token_index); if (err != parser_ok){ return err; @@ -127,7 +127,7 @@ namespace { } TEST(TxParse, Count_Minimal) { - auto transaction = R"({"account_number":"0"})"; + auto transaction = R"({"account_number":"3"})"; parser_tx_obj.tx_json.tx = transaction; parser_tx_obj.tx_json.flags.cache_valid = false; @@ -140,12 +140,25 @@ namespace { EXPECT_EQ(1, numItems) << "Wrong number of items"; } + TEST(TxParse, Tx_Chain_not_Allowed) { + auto transaction = R"({"account_number":"0","chain_id":"0","fee":{"amount":[{"amount":"5","denom":"photon"}],"gas":"10000"},"memo":"testmemo","msgs":[{"inputs":[{"address":"cosmosaccaddr1d9h8qat5e4ehc5","coins":[{"amount":"10","denom":"atom"}]}],"outputs":[{"address":"cosmosaccaddr1da6hgur4wse3jx32","coins":[{"amount":"10","denom":"atom"}]}]}],"sequence":"1"})"; + + parser_tx_obj.tx_json.tx = transaction; + parser_tx_obj.tx_json.flags.cache_valid = false; + parser_error_t err = JSON_PARSE(&parser_tx_obj.tx_json.json, parser_tx_obj.tx_json.tx); + EXPECT_EQ(err, parser_ok); + + uint8_t numItems; + parser_error_t err2 = tx_display_numItems(&numItems); + EXPECT_EQ(err2, parser_unexpected_chain); + } + TEST(TxParse, Tx_Page_Count) { auto transaction = R"({"account_number":"0","chain_id":"test-chain-1","fee":{"amount":[{"amount":"5","denom":"photon"}],"gas":"10000"},"memo":"testmemo","msgs":[{"inputs":[{"address":"cosmosaccaddr1d9h8qat5e4ehc5","coins":[{"amount":"10","denom":"atom"}]}],"outputs":[{"address":"cosmosaccaddr1da6hgur4wse3jx32","coins":[{"amount":"10","denom":"atom"}]}]}],"sequence":"1"})"; parser_tx_obj.tx_json.tx = transaction; parser_tx_obj.tx_json.flags.cache_valid = false; - parser_error_t err = JSON_PARSE(&parser_tx_obj.tx_json.json, parser_tx_obj.tx_json.tx); + const parser_error_t err = JSON_PARSE(&parser_tx_obj.tx_json.json, parser_tx_obj.tx_json.tx); EXPECT_EQ(err, parser_ok); uint8_t numItems; diff --git a/tests_zemu/snapshots/s-mainmenu/00004.png b/tests_zemu/snapshots/s-mainmenu/00004.png index 8b61000f..ba1bdc35 100644 Binary files a/tests_zemu/snapshots/s-mainmenu/00004.png and b/tests_zemu/snapshots/s-mainmenu/00004.png differ diff --git a/tests_zemu/snapshots/s-mainmenu/00010.png b/tests_zemu/snapshots/s-mainmenu/00010.png index 8b61000f..ba1bdc35 100644 Binary files a/tests_zemu/snapshots/s-mainmenu/00010.png and b/tests_zemu/snapshots/s-mainmenu/00010.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00004.png b/tests_zemu/snapshots/sp-mainmenu/00004.png index b639e800..33c0445e 100644 Binary files a/tests_zemu/snapshots/sp-mainmenu/00004.png and b/tests_zemu/snapshots/sp-mainmenu/00004.png differ diff --git a/tests_zemu/snapshots/sp-mainmenu/00010.png b/tests_zemu/snapshots/sp-mainmenu/00010.png index b639e800..33c0445e 100644 Binary files a/tests_zemu/snapshots/sp-mainmenu/00010.png and b/tests_zemu/snapshots/sp-mainmenu/00010.png differ diff --git a/tests_zemu/snapshots/st-mainmenu/00001.png b/tests_zemu/snapshots/st-mainmenu/00001.png index e971ae89..63b62b71 100644 Binary files a/tests_zemu/snapshots/st-mainmenu/00001.png and b/tests_zemu/snapshots/st-mainmenu/00001.png differ diff --git a/tests_zemu/snapshots/x-mainmenu/00004.png b/tests_zemu/snapshots/x-mainmenu/00004.png index b639e800..33c0445e 100644 Binary files a/tests_zemu/snapshots/x-mainmenu/00004.png and b/tests_zemu/snapshots/x-mainmenu/00004.png differ diff --git a/tests_zemu/snapshots/x-mainmenu/00010.png b/tests_zemu/snapshots/x-mainmenu/00010.png index b639e800..33c0445e 100644 Binary files a/tests_zemu/snapshots/x-mainmenu/00010.png and b/tests_zemu/snapshots/x-mainmenu/00010.png differ diff --git a/tests_zemu/tests/standard.test.ts b/tests_zemu/tests/standard.test.ts index 65e15f46..9ec51ca4 100644 --- a/tests_zemu/tests/standard.test.ts +++ b/tests_zemu/tests/standard.test.ts @@ -87,6 +87,7 @@ describe('Standard', function () { expect(resp.bech32_address).toEqual('cosmos1wkd9tfm5pqvhhaxq77wv9tvjcsazuaykwsld65') expect(resp.compressed_pk.length).toEqual(33) + expect(resp.compressed_pk.toString("hex")).toEqual('035c986b9ae5fbfb8e1e9c12c817f5ef8fdb821cdecaa407f1420ec4f8f1d766bf') } finally { await sim.close() } @@ -121,6 +122,7 @@ describe('Standard', function () { expect(resp.bech32_address).toEqual('cosmos1wkd9tfm5pqvhhaxq77wv9tvjcsazuaykwsld65') expect(resp.compressed_pk.length).toEqual(33) + expect(resp.compressed_pk.toString("hex")).toEqual('035c986b9ae5fbfb8e1e9c12c817f5ef8fdb821cdecaa407f1420ec4f8f1d766bf') } finally { await sim.close() }