Skip to content

Commit

Permalink
Merge pull request #177 from Zondax/dev
Browse files Browse the repository at this point in the history
New Release
  • Loading branch information
chcmedeiros authored Feb 3, 2025
2 parents 82cc269 + fa50ae5 commit 7053fd1
Show file tree
Hide file tree
Showing 792 changed files with 1,643 additions and 10,947 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ file(GLOB_RECURSE LIB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser_impl.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser_impl_eth.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser_data_cap.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser_client_deal.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/fil_utils.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser_raw_bytes.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/eth_utils.c
Expand Down
1 change: 1 addition & 0 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ endif

# Add the PRODUCTION_BUILD definition to the compiler flags
DEFINES += PRODUCTION_BUILD=$(PRODUCTION_BUILD)
DEFINES += APP_BLINDSIGN_MODE_ENABLED

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.app_testing

Expand Down
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This is the major version of this release
APPVERSION_M=1
APPVERSION_M=2
# This is the minor version of this release
APPVERSION_N=0
# This is the patch version of this release
Expand Down
54 changes: 18 additions & 36 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,33 +365,14 @@ handleSign(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx)
THROW(APDU_CODE_OK);
}

const uint8_t instruction = G_io_apdu_buffer[OFFSET_INS];
switch (instruction) {
case INS_SIGN_SECP256K1:
ZEMU_LOGF(50, "HandleSignFil\n")
tx_context_fil();
break;

case INS_SIGN_DATACAP:
ZEMU_LOGF(50, "HandleSignDatacap\n")
tx_context_datacap();
break;

case INS_CLIENT_DEAL:
ZEMU_LOGF(50, "HandleSignClientDeal\n")
tx_context_client_deal();
break;

default:
THROW(APDU_CODE_COMMAND_NOT_ALLOWED);
break;
}
CHECK_APP_CANARY()
ZEMU_LOGF(50, "HandleSignFil\n")
tx_context_fil();

const char *error_msg = tx_parse();
CHECK_APP_CANARY()


uint8_t error_code;
const char *error_msg = tx_parse(&error_code);
CHECK_APP_CANARY()

if (error_msg != NULL) {
const int error_msg_length = strnlen(error_msg, sizeof(G_io_apdu_buffer));
Expand Down Expand Up @@ -437,13 +418,18 @@ handleSignRawBytes(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx)

CHECK_APP_CANARY()

const char *error_msg = tx_parse();
uint8_t error_code;
const char *error_msg = tx_parse(&error_code);
CHECK_APP_CANARY()

if (error_msg != NULL) {
const int error_msg_length = strnlen(error_msg, sizeof(G_io_apdu_buffer));
MEMCPY(G_io_apdu_buffer, error_msg, error_msg_length);
*tx += (error_msg_length);
if (error_code == parser_blindsign_required) {
*flags |= IO_ASYNCH_REPLY;
view_blindsign_error_show();
}
THROW(APDU_CODE_DATA_INVALID);
}

Expand All @@ -465,13 +451,18 @@ handleSignEth(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx)

CHECK_APP_CANARY()

const char *error_msg = tx_parse();
uint8_t error_code;
const char *error_msg = tx_parse(&error_code);
CHECK_APP_CANARY()

if (error_msg != NULL) {
const int error_msg_length = strnlen(error_msg, sizeof(G_io_apdu_buffer));
MEMCPY(G_io_apdu_buffer, error_msg, error_msg_length);
*tx += (error_msg_length);
if (error_code == parser_blindsign_required) {
*flags |= IO_ASYNCH_REPLY;
view_blindsign_error_show();
}
THROW(APDU_CODE_DATA_INVALID);
}

Expand Down Expand Up @@ -542,16 +533,7 @@ handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx)
handleSign(flags, tx, rx);
break;
}
case INS_SIGN_DATACAP: {
CHECK_PIN_VALIDATED()
handleSign(flags, tx, rx);
break;
}
case INS_CLIENT_DEAL: {
CHECK_PIN_VALIDATED()
handleSign(flags, tx, rx);
break;
}

case INS_SIGN_RAW_BYTES: {
CHECK_PIN_VALIDATED()
handleSignRawBytes(flags, tx, rx);
Expand Down
2 changes: 0 additions & 2 deletions app/src/coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ typedef enum {
#define INS_GET_ADDR_SECP256K1 0x01
#define INS_SIGN_SECP256K1 0x02
#define INS_SIGN_ETH 0x04
#define INS_SIGN_DATACAP 0x05
#define INS_CLIENT_DEAL 0x06
#define INS_SIGN_RAW_BYTES 0x07
#define INS_GET_ADDR_ETH 0x02

Expand Down
5 changes: 1 addition & 4 deletions app/src/common/parser_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ typedef enum {
parser_invalid_rlp_data,
parser_invalid_chain_id,
parser_invalid_rs_values,
parser_invalid_datacap_tx,
parser_invalid_cid,
parser_invalid_deal_duration,
parser_invalid_prefix,
parser_invalid_datacap_prefix,
// Customs
parser_expert_mode_required,
parser_blindsign_required,
} parser_error_t;

// Define the three types
Expand All @@ -82,8 +81,6 @@ typedef enum {
typedef enum {
fil_tx = 0,
eth_tx,
datacap_tx,
clientdeal_tx,
raw_bytes,
} tx_type_t;

Expand Down
11 changes: 2 additions & 9 deletions app/src/common/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ void tx_context_eth() {
ctx_parsed_tx.tx_type = eth_tx;
}

void tx_context_datacap() {
ctx_parsed_tx.tx_type = datacap_tx;
}

void tx_context_client_deal() {
ctx_parsed_tx.tx_type = clientdeal_tx;
}

void tx_context_raw_bytes() {
ctx_parsed_tx.tx_type = raw_bytes;
}
Expand Down Expand Up @@ -100,7 +92,7 @@ uint8_t *tx_get_buffer() {
return buffering_get_buffer()->data;
}

const char *tx_parse() {
const char *tx_parse(uint8_t *error_code) {
uint8_t err = parser_parse(
&ctx_parsed_tx,
tx_get_buffer(),
Expand All @@ -110,6 +102,7 @@ const char *tx_parse() {
return parser_getErrorDescription(err);

err = parser_validate(&ctx_parsed_tx);
*error_code = err;
CHECK_APP_CANARY()

if (err != parser_ok)
Expand Down
4 changes: 1 addition & 3 deletions app/src/common/tx.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
// transaction initializer for the buffer and transaction type.
void tx_context_fil();
void tx_context_eth();
void tx_context_datacap();
void tx_context_client_deal();
void tx_context_raw_bytes();

// Signing is differently depending tx is rawBytes type
Expand Down Expand Up @@ -55,7 +53,7 @@ uint8_t *tx_get_buffer();
/// Parse message stored in transaction buffer
/// This function should be called as soon as full buffer data is loaded.
/// \return It returns NULL if data is valid or error message otherwise.
const char *tx_parse();
const char *tx_parse(uint8_t *error_code);

/// Return the number of items in the transaction
zxerr_t tx_getNumItems(uint8_t *num_items);
Expand Down
39 changes: 3 additions & 36 deletions app/src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include "coin.h"
#include "common/parser_common.h"
#include "fil_utils.h"
#include "parser_client_deal.h"
#include "parser_data_cap.h"
#include "parser_impl.h"
#include "parser_impl_eth.h"
#include "parser_raw_bytes.h"
Expand Down Expand Up @@ -79,24 +77,17 @@ parser_error_t parser_parse(parser_context_t *ctx, const uint8_t *data,
switch (ctx->tx_type) {
case fil_tx: {
CHECK_PARSER_ERR(parser_init(ctx, data, dataLen))
app_mode_skip_blindsign_ui();
return _read(ctx, &(parser_tx_obj.base_tx));
}
case eth_tx: {
CHECK_PARSER_ERR(parser_init(ctx, data, dataLen))
return _readEth(ctx, &eth_tx_obj);
}
case datacap_tx: {
CHECK_PARSER_ERR(parser_init(ctx, data, dataLen))
return _readDataCap(ctx, &parser_tx_obj.rem_datacap_tx);
}
case clientdeal_tx: {
CHECK_PARSER_ERR(parser_init(ctx, data, dataLen))
return _readClientDeal(ctx, &parser_tx_obj.client_deal_tx);
}
case raw_bytes: {
// Processing raw-bytes is valid only in expert mode
if (!app_mode_expert())
return parser_unsupported_tx;
if (!app_mode_blindsign())
return parser_blindsign_required;

return _readRawBytes(ctx, &parser_tx_obj.raw_bytes_tx);
}
Expand All @@ -118,14 +109,6 @@ parser_error_t parser_validate(const parser_context_t *ctx) {
CHECK_PARSER_ERR(_validateTxEth())
break;
}
case datacap_tx: {
CHECK_PARSER_ERR(_validateDataCap(ctx))
break;
}
case clientdeal_tx: {
CHECK_PARSER_ERR(_validateClientDeal(ctx))
break;
}
case raw_bytes: {
CHECK_PARSER_ERR(_validateRawBytes(ctx))
break;
Expand Down Expand Up @@ -161,14 +144,6 @@ parser_error_t parser_getNumItems(const parser_context_t *ctx,
CHECK_PARSER_ERR(_getNumItemsEth(num_items));
break;
}
case datacap_tx: {
*num_items = _getNumItemsDataCap(ctx);
break;
}
case clientdeal_tx: {
*num_items = _getNumItemsClientDeal(ctx);
break;
}
case raw_bytes: {
*num_items = _getNumItemsRawBytes(ctx);
break;
Expand Down Expand Up @@ -375,14 +350,6 @@ parser_error_t parser_getItem(const parser_context_t *ctx, uint8_t displayIdx,
return _getItemEth(ctx, displayIdx, outKey, outKeyLen, outVal, outValLen,
pageIdx, pageCount);
}
case datacap_tx: {
return _getItemDataCap(ctx, displayIdx, outKey, outKeyLen, outVal,
outValLen, pageIdx, pageCount);
}
case clientdeal_tx: {
return _getItemClientDeal(ctx, displayIdx, outKey, outKeyLen, outVal,
outValLen, pageIdx, pageCount);
}
case raw_bytes: {
// for now just display the hash
return _getItemRawBytes(ctx, displayIdx, outKey, outKeyLen, outVal,
Expand Down
Loading

0 comments on commit 7053fd1

Please sign in to comment.