From 0adc3f0073a915b652e90bd672b6568d66a5ea2b Mon Sep 17 00:00:00 2001 From: Z4karia <92750334+Z4karia@users.noreply.github.com> Date: Fri, 12 Apr 2024 16:46:59 +0000 Subject: [PATCH] Remove textual mode --- app/src/coin.h | 1 - app/src/common/parser.h | 5 +- app/src/common/tx.c | 7 +- app/src/common/tx.h | 1 - app/src/parser.c | 226 ++----------------------------------- app/src/parser_impl.c | 54 +-------- app/src/parser_impl.h | 1 - app/src/parser_txdef.h | 7 -- docs/APDUSPEC.md | 1 - docs/TXSPEC.md | 72 +----------- fuzz/parser_parse.cpp | 4 +- tests/common.cpp | 8 +- tests/common.h | 2 +- tests/testcases.cpp | 44 -------- tests/testcases.h | 3 +- tests/ui_tests.cpp | 3 +- tests_zemu/tests/common.ts | 1 - 17 files changed, 24 insertions(+), 416 deletions(-) diff --git a/app/src/coin.h b/app/src/coin.h index d07e6c54..6a51b7eb 100644 --- a/app/src/coin.h +++ b/app/src/coin.h @@ -37,7 +37,6 @@ typedef enum { typedef enum { tx_json = 0, - tx_textual } tx_type_e; typedef enum { diff --git a/app/src/common/parser.h b/app/src/common/parser.h index 212734e0..2f74cc63 100644 --- a/app/src/common/parser.h +++ b/app/src/common/parser.h @@ -50,11 +50,10 @@ parser_error_t parser_parse(parser_context_t *ctx, parser_error_t parser_validate(const parser_context_t *ctx); //// returns the number of items in the current parsing context -parser_error_t parser_getNumItems(const parser_context_t *ctx, uint8_t *num_items); +parser_error_t parser_getNumItems(uint8_t *num_items); // retrieves a readable output for each field / page -parser_error_t parser_getItem(const parser_context_t *ctx, - uint8_t displayIdx, +parser_error_t parser_getItem(uint8_t displayIdx, char *outKey, uint16_t outKeyLen, char *outVal, uint16_t outValLen, uint8_t pageIdx, uint8_t *pageCount); diff --git a/app/src/common/tx.c b/app/src/common/tx.c index 9a7c8a4e..fa766ce7 100644 --- a/app/src/common/tx.c +++ b/app/src/common/tx.c @@ -78,7 +78,7 @@ static parser_tx_t tx_obj; const char *tx_parse(tx_type_e type) { - if (type != tx_json && type != tx_textual) { + if (type != tx_json) { return parser_getErrorDescription(parser_value_out_of_range); } @@ -114,7 +114,7 @@ void tx_parse_reset() zxerr_t tx_getNumItems(uint8_t *num_items) { - parser_error_t err = parser_getNumItems(&ctx_parsed_tx, num_items); + parser_error_t err = parser_getNumItems(num_items); if (err != parser_ok) { @@ -138,8 +138,7 @@ zxerr_t tx_getItem(int8_t displayIdx, return zxerr_no_data; } - parser_error_t err = parser_getItem(&ctx_parsed_tx, - displayIdx, + parser_error_t err = parser_getItem(displayIdx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount); diff --git a/app/src/common/tx.h b/app/src/common/tx.h index 54b22b37..98e58549 100644 --- a/app/src/common/tx.h +++ b/app/src/common/tx.h @@ -46,7 +46,6 @@ const char *tx_parse(tx_type_e type); /// Return the number of items in the transaction zxerr_t tx_getNumItems(uint8_t *num_items); -zxerr_t tx_getTextualNumItems(uint8_t *num_items); /// Gets an specific item from the transaction (including paging) zxerr_t tx_getItem(int8_t displayIdx, diff --git a/app/src/parser.c b/app/src/parser.c index a350f0a4..4108e356 100644 --- a/app/src/parser.c +++ b/app/src/parser.c @@ -52,11 +52,7 @@ parser_error_t parser_parse(parser_context_t *ctx, CHECK_PARSER_ERR(parser_init_context(ctx, data, dataLen)) ctx->tx_obj = tx_obj; - if (tx_obj->tx_type == tx_textual) { - CHECK_PARSER_ERR(_read_text_tx(ctx, tx_obj)) - } else { - CHECK_PARSER_ERR(_read_json_tx(ctx, tx_obj)) - } + CHECK_PARSER_ERR(_read_json_tx(ctx, tx_obj)) extraDepthLevel = false; return parser_ok; @@ -69,51 +65,23 @@ parser_error_t parser_validate(const parser_context_t *ctx) { // Iterate through all items to check that all can be shown and are valid uint8_t numItems = 0; - CHECK_PARSER_ERR(parser_getNumItems(ctx, &numItems)) + CHECK_PARSER_ERR(parser_getNumItems(&numItems)) char tmpKey[40]; char tmpVal[40]; uint8_t pageCount = 0; for (uint8_t idx = 0; idx < numItems; idx++) { - CHECK_PARSER_ERR(parser_getItem(ctx, idx, tmpKey, sizeof(tmpKey), tmpVal, sizeof(tmpVal), 0, &pageCount)) + CHECK_PARSER_ERR(parser_getItem(idx, tmpKey, sizeof(tmpKey), tmpVal, sizeof(tmpVal), 0, &pageCount)) } return parser_ok; } -parser_error_t parser_getNumItems(const parser_context_t *ctx, uint8_t *num_items) { +parser_error_t parser_getNumItems(uint8_t *num_items) { *num_items = 0; - if (ctx->tx_obj->tx_type == tx_textual) { - *num_items = app_mode_expert() ? (uint8_t) ctx->tx_obj->tx_text.n_containers : (uint8_t) (ctx->tx_obj->tx_text.n_containers - ctx->tx_obj->tx_text.n_expert); - return parser_ok; - } return tx_display_numItems(num_items); } -__Z_INLINE bool parser_areEqual(uint16_t tokenIdx, const char *expected) { - if (parser_tx_obj.tx_json.json.tokens[tokenIdx].type != JSMN_STRING) { - 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 false; - } - - if (strlen(expected) != (size_t) len) { - 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 false; - } - } - - return true; -} - __Z_INLINE bool parser_isAmount(char *key) { if (strcmp(key, "msgs/value/coins") == 0){ return true; @@ -291,176 +259,7 @@ __Z_INLINE parser_error_t parser_formatAmount(uint16_t amountToken, return parser_formatAmountItem(showItemTokenIdx, outVal, outValLen, showPageIdx, &dummy); } -__Z_INLINE parser_error_t parser_screenPrint(const parser_context_t *ctx, - Cbor_container *container, - char *outKey, uint16_t outKeyLen, - char *outVal, uint16_t outValLen, - uint8_t pageIdx, uint8_t *pageCount) { - - //verification assures that content + title < size(tmp), to be used in string manipulation - if (container->screen.titleLen > MAX_TITLE_SIZE || container->screen.contentLen > MAX_CONTENT_SIZE) { - return parser_unexpected_value; - } - MEMZERO(ctx->tx_obj->tx_text.tmpBuffer, sizeof(ctx->tx_obj->tx_text.tmpBuffer)); - char *tmp = (char*) ctx->tx_obj->tx_text.tmpBuffer; - size_t tmp_len = sizeof(ctx->tx_obj->tx_text.tmpBuffer); - char out[OUTPUT_HANDLER_SIZE] = {0}; - - // No Tittle screen - if (container->screen.titleLen == 0) { - MEMCPY(tmp, container->screen.contentPtr, container->screen.contentLen); - CHECK_PARSER_ERR(tx_display_translation(out, sizeof(out),tmp, container->screen.contentLen)) - - for (uint8_t i = 0; i < container->screen.indent; i++) { - z_str3join(out, sizeof(out), SCREEN_INDENT, ""); - } - - snprintf(outKey, outKeyLen, " "); - pageString(outVal, outValLen, out, pageIdx, pageCount); - return parser_ok; - } - - //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)) - - uint8_t titleLen = container->screen.titleLen + container->screen.indent; - //Title needs to be truncated, so we concat title witn content - if ((titleLen > PRINTABLE_TITLE_SIZE ) || (outValLen > 0 && ((strlen(out)/outValLen) >= 1 - && titleLen > PRINTABLE_PAGINATED_TITLE_SIZE))) { - - char key[MAX_TITLE_SIZE + 2] = {0}; - MEMCPY(key, TITLE_TRUNCATE_REPLACE, strlen(TITLE_TRUNCATE_REPLACE)); - for (uint8_t i = 0; i < container->screen.indent; i++) { - z_str3join(key, sizeof(key), SCREEN_INDENT, ""); - } - - 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); - snprintf(outKey, outKeyLen, "%s", key); - pageString(outVal, outValLen, tmp, pageIdx, pageCount); - return parser_ok; - } - - //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, ""); - } - snprintf(outKey, outKeyLen, "%s", key); - pageString(outVal, outValLen, out, pageIdx, pageCount); - - return parser_ok; -} - -__Z_INLINE parser_error_t parser_getScreenInfo(const parser_context_t *ctx, - Cbor_container *container, - uint8_t index) { - CborValue it; - CborValue containerArray_ptr; - CborValue mapStruct_ptr; - INIT_CBOR_PARSER(ctx, mapStruct_ptr) - - PARSER_ASSERT_OR_ERROR(!cbor_value_at_end(&mapStruct_ptr), parser_unexpected_buffer_end) - PARSER_ASSERT_OR_ERROR(cbor_value_is_map(&mapStruct_ptr), parser_unexpected_type) - CHECK_CBOR_MAP_ERR(cbor_value_enter_container(&mapStruct_ptr, &it)) - CHECK_CBOR_MAP_ERR(cbor_value_advance(&it)) - CHECK_CBOR_MAP_ERR(cbor_value_enter_container(&it, &containerArray_ptr)) - - for (int i = 0; i < index ; i ++) { - CHECK_CBOR_MAP_ERR(cbor_value_advance(&containerArray_ptr)) - } - - CborValue data; - CHECK_CBOR_MAP_ERR(cbor_value_get_map_length(&containerArray_ptr, &container->n_field)) - CHECK_CBOR_MAP_ERR(cbor_value_enter_container(&containerArray_ptr, &data)) - CHECK_PARSER_ERR(cbor_get_containerInfo(&data, container)) - - return parser_ok; -} - -__Z_INLINE parser_error_t parser_getNextNonExpert(const parser_context_t *ctx, - Cbor_container *container, - uint8_t displayIdx) { - - PARSER_ASSERT_OR_ERROR(displayIdx < ctx->tx_obj->tx_text.n_containers, parser_unexpected_value); - - uint8_t non_expert = 0; - for (size_t containerIdx = 0; containerIdx < ctx->tx_obj->tx_text.n_containers; containerIdx++) { - parser_getScreenInfo(ctx, container, containerIdx); - if (!container->screen.expert) { - non_expert++; - } else { - continue; - } - if (non_expert == displayIdx + 1) { - break; - } - PARSER_ASSERT_OR_ERROR(non_expert <= displayIdx, parser_unexpected_value); - } - return parser_ok; -} - -__Z_INLINE parser_error_t parser_getTextualItem(const parser_context_t *ctx, - uint8_t displayIdx, - char *outKey, uint16_t outKeyLen, - char *outVal, uint16_t outValLen, - uint8_t pageIdx, uint8_t *pageCount) { - *pageCount = 0; - - MEMZERO(outKey, outKeyLen); - MEMZERO(outVal, outValLen); - - uint8_t numItems; - CHECK_PARSER_ERR(parser_getNumItems(ctx, &numItems)) - PARSER_ASSERT_OR_ERROR((numItems != 0), parser_unexpected_number_items) - PARSER_ASSERT_OR_ERROR((displayIdx < numItems), parser_display_idx_out_of_range) - - CHECK_APP_CANARY() - - Cbor_container container; - container.screen.titlePtr = NULL; - container.screen.titleLen = 0; - container.screen.contentPtr = NULL; - container.screen.contentLen = 0; - container.screen.indent = 0; - 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)) - } - - CHECK_PARSER_ERR(parser_screenPrint(ctx, &container, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount)) - - return parser_ok; -} - -__Z_INLINE parser_error_t parser_getJsonItem(const parser_context_t *ctx, - uint8_t displayIdx, +__Z_INLINE parser_error_t parser_getJsonItem(uint8_t displayIdx, char *outKey, uint16_t outKeyLen, char *outVal, uint16_t outValLen, uint8_t pageIdx, uint8_t *pageCount) { @@ -472,7 +271,7 @@ __Z_INLINE parser_error_t parser_getJsonItem(const parser_context_t *ctx, MEMZERO(outVal, outValLen); uint8_t numItems; - CHECK_PARSER_ERR(parser_getNumItems(ctx, &numItems)) + CHECK_PARSER_ERR(parser_getNumItems(&numItems)) CHECK_APP_CANARY() if (numItems == 0) { @@ -508,24 +307,15 @@ __Z_INLINE parser_error_t parser_getJsonItem(const parser_context_t *ctx, return parser_ok; } -parser_error_t parser_getItem(const parser_context_t *ctx, - uint8_t displayIdx, +parser_error_t parser_getItem(uint8_t displayIdx, char *outKey, uint16_t outKeyLen, char *outVal, uint16_t outValLen, uint8_t pageIdx, uint8_t *pageCount) { - if (ctx->tx_obj->tx_type == tx_textual) { - CHECK_PARSER_ERR(parser_getTextualItem(ctx,displayIdx, + CHECK_PARSER_ERR(parser_getJsonItem(displayIdx, outKey, outKeyLen, outVal, outValLen, pageIdx, pageCount)); - } else { - CHECK_PARSER_ERR(parser_getJsonItem(ctx,displayIdx, - outKey, outKeyLen, - outVal, outValLen, - pageIdx, pageCount)); - } - return parser_ok; } diff --git a/app/src/parser_impl.c b/app/src/parser_impl.c index 0a3149d5..b12e81a3 100644 --- a/app/src/parser_impl.c +++ b/app/src/parser_impl.c @@ -114,56 +114,4 @@ parser_error_t _read_json_tx(parser_context_t *c, __Z_UNUSED parser_tx_t *v) { parser_tx_obj.tx_json.filter_msg_from_count = 0; return parser_ok; -} - -parser_error_t _read_text_tx(parser_context_t *c, parser_tx_t *v) { - CborValue it; - CborValue mapStruct_ptr; - CHECK_APP_CANARY() - INIT_CBOR_PARSER(c, mapStruct_ptr) - CHECK_APP_CANARY() - - //Make sure we have a map/struct - PARSER_ASSERT_OR_ERROR(cbor_value_is_map(&mapStruct_ptr), parser_unexpected_type) - CHECK_CBOR_MAP_ERR(cbor_value_enter_container(&mapStruct_ptr, &it)) - - //Make sure we have screen_key set to 1 - int screen_key = 0; - PARSER_ASSERT_OR_ERROR(cbor_value_is_integer(&it), parser_unexpected_type) - CHECK_CBOR_MAP_ERR(cbor_value_get_int(&it, &screen_key)) - PARSER_ASSERT_OR_ERROR(screen_key == 1, parser_unexpected_type) - CHECK_CBOR_MAP_ERR(cbor_value_advance(&it)) - - //Make sure we have an array of containers and check size - PARSER_ASSERT_OR_ERROR(cbor_value_is_array(&it), parser_unexpected_type) - - CHECK_CBOR_MAP_ERR(cbor_value_get_array_length(&it, &v->tx_text.n_containers)) - // Limit max fields to 255 - PARSER_ASSERT_OR_ERROR((v->tx_text.n_containers > 0 && v->tx_text.n_containers <= UINT8_MAX), parser_unexpected_number_items) - - CborValue containerArray_ptr; - CborValue data; - Cbor_container container; - - // Enter array of containers - CHECK_CBOR_MAP_ERR(cbor_value_enter_container(&it, &containerArray_ptr)) - - for (size_t i = 0; i < v->tx_text.n_containers; i++) { - MEMZERO(&container, sizeof(container)); - - CHECK_CBOR_MAP_ERR(cbor_value_get_map_length(&containerArray_ptr, &container.n_field)) - PARSER_ASSERT_OR_ERROR((container.n_field > 0 && container.n_field < 5), parser_unexpected_value) - - CHECK_CBOR_MAP_ERR(cbor_value_enter_container(&containerArray_ptr, &data)) - CHECK_PARSER_ERR(cbor_check_expert(&data, &container)) - - v->tx_text.n_expert += container.screen.expert ? 1 : 0; - CHECK_CBOR_MAP_ERR(cbor_value_advance(&containerArray_ptr)) - } - CHECK_CBOR_MAP_ERR(cbor_value_leave_container(&it, &containerArray_ptr)) - - // End of buffer does not match end of parsed data - PARSER_ASSERT_OR_ERROR(it.source.ptr == c->buffer + c->bufferLen, parser_cbor_unexpected_EOF) - - return parser_ok; -} +} \ No newline at end of file diff --git a/app/src/parser_impl.h b/app/src/parser_impl.h index 1af7a28f..862e7c4b 100644 --- a/app/src/parser_impl.h +++ b/app/src/parser_impl.h @@ -45,7 +45,6 @@ typedef struct { extern parser_tx_t parser_tx_obj; parser_error_t _read_json_tx(parser_context_t *c, parser_tx_t *v); -parser_error_t _read_text_tx(parser_context_t *c, parser_tx_t *v); #ifdef __cplusplus } diff --git a/app/src/parser_txdef.h b/app/src/parser_txdef.h index c3c75146..41d08e60 100644 --- a/app/src/parser_txdef.h +++ b/app/src/parser_txdef.h @@ -40,12 +40,6 @@ typedef struct screen_arg_t { bool expert; } screen_arg_t; -typedef struct tx_textual_t{ - size_t n_containers; - uint8_t n_expert; - uint8_t tmpBuffer[625]; -} tx_textual_t; - typedef struct { // These are internal values used for tracking the state of the query/search uint16_t _item_index_current; @@ -103,7 +97,6 @@ typedef struct { union { tx_json_t tx_json; - tx_textual_t tx_text; }; } parser_tx_t; diff --git a/docs/APDUSPEC.md b/docs/APDUSPEC.md index b125614e..64e4cac3 100644 --- a/docs/APDUSPEC.md +++ b/docs/APDUSPEC.md @@ -106,7 +106,6 @@ First three items in the derivation path will be hardened automatically hardened | | | | 1 = add | | | | | 2 = last | | P2 | byte (1) | Transaction Format | 0 = json | -| | | | 1 = textual | | L | byte (1) | Bytes in payload | (depends) | The first packet/chunk includes only the derivation path and HRP. diff --git a/docs/TXSPEC.md b/docs/TXSPEC.md index 037e1915..2343d236 100644 --- a/docs/TXSPEC.md +++ b/docs/TXSPEC.md @@ -1,6 +1,6 @@ Transaction Specification ------------------------- -Two types of transaction formats are supported by the Cosmos App, Json format and Textual format. +The THORChain App supports the JSON Format transaction type. ### JSON Format @@ -93,72 +93,4 @@ assert ledger_validate('{"a ":2,"b":3}') assert not ledger_validate('{"a":2,\n"b":3}') assert not ledger_validate('{"b":2,"a":3}') assert not ledger_validate('{"a" : 2 }') -``` - -### Textual Format - -In Textual Format, a transaction is rendered into a textual representation, which is then sent to Ledger device, where transmitted data can be simply decoded into legible text. - -The textual representation is a sequence of screens. Each screen is meant to be displayed in its entirety. This textual representation must be encoded using CBOR deterministic encoding (RFC 8949). - -A screen consists of a text string, an indentation, and the expert flag,represented as an integer-keyed map. All entries are optional and MUST be omitted from the encoding if empty, zero, or false. Text defaults to the empty string, indent defaults to zero, and expert defaults to false. -```json -screen = { - text_key: tstr, - indent_key: uint, - expert_key: bool, -} -```` -To keep the enconding small on the CBOR the entry keys are represented by small integers. -``` -text_key = 1 -indent_key = 2 -expert_key = 3 -``` - -#### Examples -Textual Representation -``` -Chain id: my-chain -Account number: 1 -Sequence: 2 -Public key: cosmos.crypto.secp256k1.PubKey -> PubKey object ->> Key: Auvdf+T963bciiBe9l15DNMOijdaXCUo6zqSOvH7TXlN -Transaction: 1 Messages -> Message (1/1): cosmos.bank.v1beta1.MsgSend -> From address: cosmos1ulav3hsenupswqfkw2y3sup5kgtqwnvqa8eyhs -> To address: cosmos1ejrf4cur2wy6kfurg9f2jppp2h3afe5h6pkh5t -> Amount: 10 ATOM -End of Messages -Fees: 0.002 uatom -Gas limit: 100'000 -Hash of raw bytes: e237dc2e3f8f0b1d0310e1cd0b0ab5fc4a59e4bc3454d67eb65c3fdb0fa599c9 -```` - -CBOR Envelope -``` -[ - {1: "Chain id: my-chain"}, - {1: "Account number: 1"}, - {1: "Sequence: 2"}, - {1: "Public key: cosmos.crypto.secp256k1.PubKey", 3: true}, - {1: "PubKey object", 2: 1, 3: true}, - {1: "Key: Auvdf+T963bciiBe9l15DNMOijdaXCUo6zqSOvH7TXlN", 2: 2, 3: true}, - {1: "Transaction: 1 Messages"}, - {1: "Message (1/1): cosmos.bank.v1beta1.MsgSend", 2: 1}, - {1: "From address: cosmos1ulav3hsenupswqfkw2y3sup5kgtqwnvqa8eyhs", 2: 1}, - {1: "To address: cosmos1ejrf4cur2wy6kfurg9f2jppp2h3afe5h6pkh5t", 2: 1}, - {1: "Amount: 10 ATOM", 2: 1}, - {1: "End of Messages"}, - {1: "Fees: 0.002 uatom"}, - {1: "Gas limit: 100'000", 3: true}, - { 1: "Hash of raw bytes: e237dc2e3f8f0b1d0310e1cd0b0ab5fc4a59e4bc3454d67eb65c3fdb0fa599c9", 3: true,}, -] -``` -CBOR Encoded -``` -8fa10172436861696e2069643a206d792d636861696ea101714163636f756e74206e756d6265723a2031a1016b53657175656e63653a2032a201782a5075626c6963206b65793a20636f736d6f732e63727970746f2e736563703235366b312e5075624b657903f5a3016d5075624b6579206f626a656374020103f5a30178314b65793a2041757664662b54393633626369694265396c3135444e4d4f696a64615843556f367a71534f76483754586c4e020203f5a101775472616e73616374696f6e3a2031204d65737361676573a201782a4d6573736167652028312f31293a20636f736d6f732e62616e6b2e763162657461312e4d736753656e640201a201783b46726f6d20616464726573733a20636f736d6f7331756c6176336873656e7570737771666b77327933737570356b677471776e76716138657968730201a2017839546f20616464726573733a20636f736d6f7331656a726634637572327779366b667572673966326a707070326833616665356836706b6835740201a2016f416d6f756e743a2031302041544f4d0201a1016f456e64206f66204d65737361676573a10171466565733a20302e303032207561746f6da20172476173206c696d69743a203130302730303003f5a201785348617368206f66207261772062797465733a206532333764633265336638663062316430333130653163643062306162356663346135396534626333343534643637656236356333666462306661353939633903f5 -``` - -The CBOR envelope is decoded using Intel TinyCbor library. Each CBOR container size is verified and the text string is slip into title and content to later be displayed in the Ledger Screen. \ No newline at end of file +``` \ No newline at end of file diff --git a/fuzz/parser_parse.cpp b/fuzz/parser_parse.cpp index 1cc4fd9e..55a2f469 100644 --- a/fuzz/parser_parse.cpp +++ b/fuzz/parser_parse.cpp @@ -43,7 +43,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) } uint8_t num_items; - rc = parser_getNumItems(&ctx, &num_items); + rc = parser_getNumItems(&num_items); if (rc != parser_ok) { (void)fprintf(stderr, "error in parser_getNumItems: %s\n", @@ -55,7 +55,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) uint8_t page_idx = 0; uint8_t page_count = 1; while (page_idx < page_count) { - rc = parser_getItem(&ctx, i, + rc = parser_getItem(i, PARSER_KEY, sizeof(PARSER_KEY), PARSER_VALUE, sizeof(PARSER_VALUE), page_idx, &page_count); diff --git a/tests/common.cpp b/tests/common.cpp index f8e49866..56482969 100644 --- a/tests/common.cpp +++ b/tests/common.cpp @@ -25,13 +25,12 @@ #include "gmock/gmock.h" #include "coin.h" -std::vector dumpUI(parser_context_t *ctx, - uint16_t maxKeyLen, +std::vector dumpUI(uint16_t maxKeyLen, uint16_t maxValueLen) { auto answer = std::vector(); uint8_t numItems; - parser_error_t err = parser_getNumItems(ctx, &numItems); + parser_error_t err = parser_getNumItems(&numItems); if (err != parser_ok) { return answer; } @@ -45,8 +44,7 @@ std::vector dumpUI(parser_context_t *ctx, while (pageIdx < pageCount) { std::stringstream ss; - err = parser_getItem(ctx, - idx, + err = parser_getItem(idx, keyBuffer, maxKeyLen, valueBuffer, maxValueLen, pageIdx, &pageCount); diff --git a/tests/common.h b/tests/common.h index beb78755..600e873f 100644 --- a/tests/common.h +++ b/tests/common.h @@ -27,6 +27,6 @@ else FAIL() << "One of the strings is null"; } parser_error_t parse_tx(parsed_json_t *parsed_json, const char *tx); -std::vector dumpUI(parser_context_t *ctx, uint16_t maxKeyLen, uint16_t maxValueLen); +std::vector dumpUI(uint16_t maxKeyLen, uint16_t maxValueLen); #define JSON_PARSE(parsed_json, buffer) json_parse(parsed_json, buffer, strlen(buffer)) diff --git a/tests/testcases.cpp b/tests/testcases.cpp index 8fc64886..634e2ce7 100644 --- a/tests/testcases.cpp +++ b/tests/testcases.cpp @@ -69,47 +69,3 @@ std::vector GetJsonTestCases(const std::string &jsonFile) { return answer; } - -std::vector GetJsonTextualTestCases(const std::string &jsonFile) { - auto answer = std::vector(); - - const Json::CharReaderBuilder builder; - Json::Value obj; - - const std::string fullPathJsonFile = std::string(TESTVECTORS_DIR) + jsonFile; - - std::ifstream inFile(fullPathJsonFile); - if (!inFile.is_open()) { - return answer; - } - - // Retrieve all test cases - JSONCPP_STRING errs; - Json::parseFromStream(builder, inFile, &obj, &errs); - std::cout << "Number of testcases: " << obj.size() << std::endl; - - for (int i = 0; i < obj.size(); i++) { - - auto outputs = std::vector(); - for (auto s : obj[i]["output"]) { - outputs.push_back(s.asString()); - } - - auto outputs_expert = std::vector(); - for (auto s : obj[i]["output_expert"]) { - outputs_expert.push_back(s.asString()); - } - - answer.push_back(testcase_t{ - obj[i]["index"].asUInt64(), - obj[i]["name"].asString(), - obj[i]["blob"].asString(), - "", - "", - outputs, - outputs_expert, - false - }); - } - return answer; -} diff --git a/tests/testcases.h b/tests/testcases.h index ed9fcd47..c7bc3744 100644 --- a/tests/testcases.h +++ b/tests/testcases.h @@ -28,5 +28,4 @@ typedef struct { bool expert; } testcase_t; -std::vector GetJsonTestCases(const std::string& filename); -std::vector GetJsonTextualTestCases(const std::string &jsonFile); +std::vector GetJsonTestCases(const std::string& filename); \ No newline at end of file diff --git a/tests/ui_tests.cpp b/tests/ui_tests.cpp index e7ebbda9..1041fb04 100644 --- a/tests/ui_tests.cpp +++ b/tests/ui_tests.cpp @@ -27,7 +27,6 @@ using ::testing::TestWithParam; -using ::testing::Values; void validate_testcase(const testcase_t &tc) { parser_context_t ctx; @@ -67,7 +66,7 @@ void check_testcase(const testcase_t &tc) { if (err != parser_ok) return; - auto output = dumpUI(&ctx, 40, 40); + auto output = dumpUI(40, 40); for (const auto &i : output) { std::cout << i << std::endl; diff --git a/tests_zemu/tests/common.ts b/tests_zemu/tests/common.ts index 3f8381ef..6dad1e83 100644 --- a/tests_zemu/tests/common.ts +++ b/tests_zemu/tests/common.ts @@ -18,7 +18,6 @@ import { DEFAULT_START_OPTIONS, IDeviceModel } from '@zondax/zemu' const Resolve = require('path').resolve export const AMINO_JSON_TX = 0x0 -export const TEXTUAL_TX = 0x1 export const APP_SEED = 'equip will roof matter pink blind book anxiety banner elbow sun young' const APP_PATH_S = Resolve('../app/output/app_s.elf')