Skip to content

Commit

Permalink
restriction of chain-id values
Browse files Browse the repository at this point in the history
  • Loading branch information
chcmedeiros committed Sep 12, 2023
1 parent 87bad44 commit 2ab31ca
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,17 @@ __Z_INLINE parser_error_t parser_getTextualItem(const parser_context_t *ctx,
container.screen.expert = false;
CHECK_PARSER_ERR(parser_getScreenInfo(ctx, &container, displayIdx))

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))
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/tx_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (strcmp(outVal, "0") == 0 || strcmp(outVal, "1") == 0) {
zemu_log_stack("Not Allowed chain");
return parser_unexpected_chain;
} else {
zemu_log_stack("Chain is NOT DEFAULT");
}
Expand Down
15 changes: 14 additions & 1 deletion tests/tx_parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -140,6 +140,19 @@ 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"})";

Expand Down

0 comments on commit 2ab31ca

Please sign in to comment.