Skip to content

Commit

Permalink
Merge pull request #4 from Zondax/dev
Browse files Browse the repository at this point in the history
M2 features
  • Loading branch information
abenso authored Sep 16, 2024
2 parents 86514e5 + 69ee512 commit 7710fe6
Show file tree
Hide file tree
Showing 1,366 changed files with 2,680 additions and 326 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
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ file(GLOB_RECURSE LIB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/hexutils.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/zxmacros.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/zxformat.c
${CMAKE_CURRENT_SOURCE_DIR}/deps/ledger-zxlib/src/buffering.c
####
${CMAKE_CURRENT_SOURCE_DIR}/app/src/buffering_json.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/tx.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/parser.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/items.c
${CMAKE_CURRENT_SOURCE_DIR}/app/src/items_format.c
Expand Down Expand Up @@ -172,7 +175,9 @@ target_link_libraries(app_lib PUBLIC)
# Fuzz Targets
if(ENABLE_FUZZING)
set(FUZZ_TARGETS
parser_parse
parser_parse_json
parser_parse_hash
parser_parse_transfer
)

foreach(target ${FUZZ_TARGETS})
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
67 changes: 65 additions & 2 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,26 @@

#include "actions.h"
#include "addr.h"
#include "apdu_handler_legacy.h"
#include "app_main.h"
#include "coin.h"
#include "crypto.h"
#include "parser_txdef.h"
#include "tx.h"
#include "view.h"
#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_TRANSFER 0x24

static bool tx_initialized = false;

void extractHDPath(uint32_t rx, uint32_t offset) {
Expand Down Expand Up @@ -109,12 +121,12 @@ __Z_INLINE void handleGetAddr(volatile uint32_t *flags, volatile uint32_t *tx, u
}

__Z_INLINE void handleSign(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
zemu_log("handleSign\n");
zemu_log("handleSignJson\n");
if (!process_chunk(tx, rx)) {
THROW(APDU_CODE_OK);
}

const char *error_msg = tx_parse();
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 @@ -186,10 +198,61 @@ void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {

case INS_SIGN: {
CHECK_PIN_VALIDATED()
set_tx_type(tx_type_json);
handleSign(flags, tx, rx);
break;
}

case INS_SIGN_HASH: {
CHECK_PIN_VALIDATED()
set_tx_type(tx_type_hash);
handleSign(flags, tx, rx);
break;
}

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 7710fe6

Please sign in to comment.