Skip to content

Commit

Permalink
Fix swap implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeutin-ledger committed Oct 10, 2024
1 parent f4705ed commit b76202b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 15 additions & 3 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,21 @@ __Z_INLINE void handleSign(volatile uint32_t *flags, volatile uint32_t *tx, uint
THROW(APDU_CODE_DATA_INVALID);
}

view_review_init(tx_getItem, tx_getNumItems, app_sign_ed25519);
view_review_show(REVIEW_TXN);
*flags |= IO_ASYNCH_REPLY;
#ifdef HAVE_SWAP
if (G_swap_state.called_from_swap && G_swap_state.should_exit && error_msg == NULL) {
// Call app_sign_ed25519 without going through UI display, the UI validation was done in
// Exchange app already
app_sign_ed25519();
// Go back to Exchange and report our success to display the modal
finalize_exchange_sign_transaction(true);
} else {
#endif
view_review_init(tx_getItem, tx_getNumItems, app_sign_ed25519);
view_review_show(REVIEW_TXN);
*flags |= IO_ASYNCH_REPLY;
#ifdef HAVE_SWAP
}
#endif
}

__Z_INLINE void handleSignRaw(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
Expand Down
6 changes: 4 additions & 2 deletions app/src/swap/handle_sign_transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ bool copy_transaction_parameters(create_transaction_parameters_t *sign_transacti
return true;
}

// Ensure the received transaction matches what was validated in the Exchange app UI
parser_error_t check_swap_conditions(parser_tx_t *txObj) {
parser_error_t err = parser_unexpected_error;
if (txObj == NULL) {
Expand Down Expand Up @@ -103,6 +104,7 @@ parser_error_t check_swap_conditions(parser_tx_t *txObj) {
CHECK_ERROR(parser_getItem(txObj, &uiFields));
if (strncmp(valid_network, tmpValue, strlen(valid_network)) != 0) {
ZEMU_LOGF(200, "Swap not enable on %s network.\n", tmpValue);
return parser_swap_tx_wrong_method;
}

// Check method.
Expand Down Expand Up @@ -150,12 +152,12 @@ parser_error_t check_swap_conditions(parser_tx_t *txObj) {
const size_t strLen = strlen(tmpValue);
const size_t amountLen = strlen(tmpAmount);
if (zxerr != zxerr_ok || strLen != amountLen || strncmp(tmpValue, tmpAmount, strLen) != 0) {
ZEMU_LOGF(200, "Wrong swap tx amount (%s, should be : %s).\n", tmp_str, tmpAmount);
ZEMU_LOGF(200, "Wrong swap tx amount (%s, should be : %s).\n", tmpValue, tmpAmount);
return parser_swap_tx_wrong_amount;
}

ZEMU_LOGF(50, "Swap parameters verified by current tx\n");
return err;
return parser_ok;
}

void __attribute__((noreturn)) finalize_exchange_sign_transaction(bool is_success) {
Expand Down

0 comments on commit b76202b

Please sign in to comment.