Skip to content

Commit

Permalink
Backward compatibility (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
abenso committed Sep 16, 2024
1 parent 44b9aa1 commit 69ee512
Show file tree
Hide file tree
Showing 987 changed files with 1,518 additions and 93 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ jobs:
wget https://github.com/Kitware/CMake/releases/download/v3.28.0/cmake-3.28.0-linux-x86_64.sh
sudo mkdir /opt/cmake
sudo sh cmake-3.28.0-linux-x86_64.sh --skip-license --prefix=/opt/cmake
sudo ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake
sudo ln -s /opt/cmake/bin/ctest /usr/local/bin/ctest
sudo ln -sf /opt/cmake/bin/cmake /usr/local/bin/cmake
sudo ln -sf /opt/cmake/bin/ctest /usr/local/bin/ctest
- name: Verify CMake version
run: cmake --version
- name: Install deps
Expand Down Expand Up @@ -112,7 +112,11 @@ jobs:
npm install -g yarn
- name: Build and run zemu tests
run: |
make test_all
for i in {1..3}; do
make zemu_install && break || sleep 10
done
make
make zemu_test
- name: Upload Snapshots (only failure)
if: ${{ failure() }}
uses: actions/upload-artifact@v3
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=0
# This is the minor version
APPVERSION_N=0
# This is the patch version
APPVERSION_P=2
APPVERSION_P=3
44 changes: 41 additions & 3 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "actions.h"
#include "addr.h"
#include "apdu_handler_legacy.h"
#include "app_main.h"
#include "coin.h"
#include "crypto.h"
Expand All @@ -31,14 +32,15 @@
#include "view_internal.h"
#include "zxmacros.h"

// This is for backward compatibility with the legacy app, we need to redefine some instructions
#undef INS_GET_VERSION
#define INS_GET_VERSION 0x20
#undef INS_GET_ADDR
#define INS_GET_ADDR 0x21
#undef INS_SIGN
#define INS_SIGN 0x22
#define INS_SIGN_HASH 0x23
#define INS_SIGN_TRANSACTION 0x24
#define INS_SIGN_TRANSFER 0x24

static bool tx_initialized = false;

Expand Down Expand Up @@ -124,7 +126,7 @@ __Z_INLINE void handleSign(volatile uint32_t *flags, volatile uint32_t *tx, uint
THROW(APDU_CODE_OK);
}

const char *error_msg = tx_parse(get_tx_type());
const char *error_msg = tx_parse(tx_get_buffer_length(), get_tx_type());
CHECK_APP_CANARY()
if (error_msg != NULL) {
const int error_msg_length = strnlen(error_msg, sizeof(G_io_apdu_buffer));
Expand Down Expand Up @@ -208,13 +210,49 @@ void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
break;
}

case INS_SIGN_TRANSACTION: {
case INS_SIGN_TRANSFER: {
CHECK_PIN_VALIDATED()
set_tx_type(tx_type_transfer);
handleSign(flags, tx, rx);
break;
}

case BCOMP_GET_VERSION: {
CHECK_PIN_VALIDATED()
legacy_handleGetVersion(tx);
break;
}

case BCOMP_VERIFY_ADDRESS: {
CHECK_PIN_VALIDATED()
legacy_handleGetAddr(flags, tx, rx, LEGACY_SHOW_ADDRESS);
break;
}

case BCOMP_GET_PUBKEY: {
CHECK_PIN_VALIDATED()
legacy_handleGetAddr(flags, tx, rx, LEGACY_NOT_SHOW_ADDRESS);
break;
}

case BCOMP_SIGN_JSON_TX: {
CHECK_PIN_VALIDATED()
legacy_handleSignTransaction(flags, tx, rx);
break;
}

case BCOMP_SIGN_TX_HASH: {
CHECK_PIN_VALIDATED()
legacy_handleSignHash(flags, tx, rx);
break;
}

case BCOMP_MAKE_TRANSFER_TX: {
CHECK_PIN_VALIDATED()
legacy_handleSignTransferTx(flags, tx, rx);
break;
}

#if defined(APP_TESTING)
case INS_TEST: {
handleTest(flags, tx, rx);
Expand Down
Loading

0 comments on commit 69ee512

Please sign in to comment.