Skip to content

Commit

Permalink
Merge pull request #171 from Zondax/swap_feature
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosala authored Feb 28, 2023
2 parents b58fcbd + 43080fd commit abc0f74
Show file tree
Hide file tree
Showing 14 changed files with 453 additions and 11 deletions.
4 changes: 3 additions & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.installer_script

include $(BOLOS_SDK)/Makefile.defines

DEFINES += HAVE_SWAP

DEFINES += APP_SECRET_MODE_ENABLED

$(info ************ TARGET_NAME = [$(TARGET_NAME)])
Expand Down Expand Up @@ -77,7 +79,7 @@ endif

APP_LOAD_PARAMS = --curve ed25519 $(COMMON_LOAD_PARAMS) --path $(APPPATH)

NANOS_STACK_SIZE := 3216
NANOS_STACK_SIZE := 3160

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

Expand Down
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=20
# This is the `spec_version` field of `Runtime`
APPVERSION_N=9370
# This is the patch version of this release
APPVERSION_P=0
APPVERSION_P=1
27 changes: 20 additions & 7 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include "zxmacros.h"
#include "secret.h"
#include "app_mode.h"
#include "swap.h"
#include "view_internal.h"

static bool tx_initialized = false;

Expand Down Expand Up @@ -144,7 +146,7 @@ __Z_INLINE void handleGetAddr(volatile uint32_t *flags, volatile uint32_t *tx, u
}
if (requireConfirmation) {
view_review_init(addr_getItem, addr_getNumItems, app_reply_address);
view_review_show(0x03);
view_review_show(REVIEW_ADDRESS);
*flags |= IO_ASYNCH_REPLY;
return;
}
Expand Down Expand Up @@ -172,9 +174,15 @@ __Z_INLINE void handleSignSr25519(volatile uint32_t *flags, volatile uint32_t *t
THROW(APDU_CODE_DATA_INVALID);
}

view_review_init(tx_getItem, tx_getNumItems, app_return_sr25519);
view_review_show(0x03);
*flags |= IO_ASYNCH_REPLY;
if (G_swap_state.called_from_swap) {
G_swap_state.should_exit = 1;
app_sign_sr25519();
app_return_sr25519();
} else {
view_review_init(tx_getItem, tx_getNumItems, app_return_sr25519);
view_review_show(REVIEW_TXN);
*flags |= IO_ASYNCH_REPLY;
}
}
#endif

Expand All @@ -188,9 +196,14 @@ __Z_INLINE void handleSignEd25519(volatile uint32_t *flags, volatile uint32_t *t
THROW(APDU_CODE_DATA_INVALID);
}

view_review_init(tx_getItem, tx_getNumItems, app_sign_ed25519);
view_review_show(0x03);
*flags |= IO_ASYNCH_REPLY;
if (G_swap_state.called_from_swap) {
G_swap_state.should_exit = 1;
app_sign_ed25519();
} else {
view_review_init(tx_getItem, tx_getNumItems, app_sign_ed25519);
view_review_show(REVIEW_TXN);
*flags |= IO_ASYNCH_REPLY;
}
}

__Z_INLINE void handleSign(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
Expand Down
27 changes: 26 additions & 1 deletion app/src/common/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,42 @@
********************************************************************************/
#include "app_main.h"
#include "view.h"
#include "swap.h"

#include <os_io_seproxyhal.h>

static void app_exit(void) {
BEGIN_TRY_L(exit) {
TRY_L(exit) {
os_sched_exit(-1);
}
FINALLY_L(exit) {
}
}
END_TRY_L(exit);
}

__attribute__((section(".boot"))) int
main(void) {
main(int arg0) {
// exit critical section
__asm volatile("cpsie i");

view_init();
os_boot();

if (arg0) {
libargs_s *args = (libargs_s *) arg0;
if (args->id != 0x100) {
app_exit();
return 0;
}

swap_handle_command(args);
if (!G_swap_state.called_from_swap) {
os_lib_end();
}
}

BEGIN_TRY
{
TRY
Expand Down
10 changes: 10 additions & 0 deletions app/src/common/tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "parser.h"
#include <string.h>
#include "zxmacros.h"
#include "swap.h"

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2)
#define RAM_BUFFER_SIZE 8192
Expand Down Expand Up @@ -89,6 +90,15 @@ const char *tx_parse() {
return parser_getErrorDescription(err);
}

// If in swap mode, compare swap tx parameters with stored info.
if (G_swap_state.called_from_swap) {
err = check_swap_conditions(&ctx_parsed_tx);
CHECK_APP_CANARY()
if (err != parser_ok) {
return parser_getErrorDescription(err);
}
}

return NULL;
}

Expand Down
Loading

0 comments on commit abc0f74

Please sign in to comment.