Skip to content

Commit

Permalink
Feat/m1 fixes (#1)
Browse files Browse the repository at this point in the history
* add address index

add comment

* Use default path as it is without prepending the account

* Show account and remove path from UI

* Update expected address and improve testing by showing device name on tests

Update tests and snapshots

Enable other devices

Update test and expected value

Update snapshots

* Update js package

* Bump version and update snapshots

remove code

make concurrent zemu test

* fix coin name

* update submodule

* update snapshots

* remove nanos

* Disable all penumbre api for nanos

* Fix CI by removing support for nanos packaging and checks

* Remove switch statemnet

* Disable version check for PR to dev as it is our working branch

* Renable version check in dev

* update APDUSPEC

* Fix typo

---------

Co-authored-by: abenso <[email protected]>
  • Loading branch information
neithanmo and abenso authored Nov 25, 2024
1 parent a9e804a commit 802f4b9
Show file tree
Hide file tree
Showing 77 changed files with 228 additions and 282 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- main
- develop
- master # for safety reasons
- dev # for safety reasons
- dev # for safety reasons

jobs:
configure:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- main
- develop
- master # for safety reasons
- dev # for safety reasons
- dev # for safety reasons

jobs:
analyse:
Expand All @@ -17,7 +17,7 @@ jobs:
if: github.event.repository.private == false
strategy:
matrix:
sdk: ["$NANOS_SDK", "$NANOX_SDK", "$NANOSP_SDK", "$STAX_SDK", "$FLEX_SDK"]
sdk: ["$NANOX_SDK", "$NANOSP_SDK", "$STAX_SDK", "$FLEX_SDK"]
container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-legacy:latest

Expand Down
86 changes: 7 additions & 79 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,61 +58,6 @@ jobs:
cd ./app/rust
cargo clippy --all-targets --features "clippy"
build_ledger:
needs: configure
runs-on: ubuntu-latest
container:
image: zondax/ledger-app-builder:latest
options: --user ${{ needs.configure.outputs.uid_gid }}
env:
BOLOS_SDK: /opt/nanos-secure-sdk
outputs:
size: ${{steps.build.outputs.size}}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build Standard app
id: build
shell: bash -l {0}
run: |
make PRODUCTION_BUILD=0
echo "size=$(python3 deps/ledger-zxlib/scripts/getSize.py s)" >> $GITHUB_OUTPUT
build_ledger_production:
needs: configure
runs-on: ubuntu-latest
container:
image: zondax/ledger-app-builder:latest
options: --user ${{ needs.configure.outputs.uid_gid }}
env:
BOLOS_SDK: /opt/nanos-secure-sdk
outputs:
size: ${{steps.build.outputs.size}}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build Production app
id: build
shell: bash -l {0}
run: |
make PRODUCTION_BUILD=1
echo "size=$(python3 deps/ledger-zxlib/scripts/getSize.py s)" >> $GITHUB_OUTPUT
size_nano_s:
needs: build_ledger
runs-on: ubuntu-latest
continue-on-error: true
env:
NANOS_LIMIT_SIZE: 136
steps:
- run: |
echo "LNS app size: ${{needs.build_ledger.outputs.size}} KiB"
[ ${{needs.build_ledger.outputs.size}} -le $NANOS_LIMIT_SIZE ]
test_zemu:
runs-on: ${{ github.repository_owner == 'zondax' && 'zondax-runners' || 'ubuntu-latest' }}
steps:
Expand Down Expand Up @@ -157,41 +102,24 @@ jobs:
name: snapshots-tmp
path: tests_zemu/snapshots-tmp/

build_package_nanos:
needs: [configure, build_ledger, test_zemu, rust_tests]
if: ${{ github.ref == 'refs/heads/master' }}
build_ledger:
needs: configure
runs-on: ubuntu-latest
container:
image: zondax/ledger-app-builder:latest
options: --user ${{ needs.configure.outputs.uid_gid }}
env:
BOLOS_SDK: /opt/nanos-secure-sdk
BOLOS_SDK: /opt/nanosplus-secure-sdk
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Install deps
run: pip install ledgerblue

- name: Build NanoS
submodules: recursive
- name: Build Standard app
id: build
shell: bash -l {0}
run: |
PRODUCTION_BUILD=0 make
mv ./app/pkg/installer_s.sh ./app/pkg/installer_nanos.sh
- name: Set tag
id: nanos
run: echo "tag_name=$(./app/pkg/installer_nanos.sh version)" >> $GITHUB_OUTPUT
- name: Create or Update Release (1)
id: create_release_0
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
files: ./app/pkg/installer_nanos.sh
tag_name: ${{ steps.nanos.outputs.tag_name }}
draft: false
prerelease: false
make PRODUCTION_BUILD=0
build_package_nanosp:
needs: [configure, build_ledger, test_zemu, rust_tests]
Expand Down
6 changes: 3 additions & 3 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ DEFINES += PRODUCTION_BUILD=$(PRODUCTION_BUILD)
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.app_testing

ifndef COIN
COIN=PEN
COIN=UM
endif

include $(CURDIR)/Makefile.version

$(info COIN = [$(COIN)])

ifeq ($(COIN), PEN)
ifeq ($(COIN), UM)
# Main app configuration
DEFINES += APP_STANDARD
APPNAME = "Penumbra"
Expand Down Expand Up @@ -160,7 +160,7 @@ dep/%.d: %.c Makefile

.PHONY: listvariants
listvariants:
@echo VARIANTS COIN PEN
@echo VARIANTS COIN UM

.PHONY: version
version:
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=1
APPVERSION_P=2
33 changes: 17 additions & 16 deletions app/src/addr.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "zxmacros.h"

bool is_randomized = false;
uint32_t address_idx_account = 0;

#define BECH32_PREFIX "penumbra"

Expand All @@ -52,12 +53,8 @@ bool is_randomized = false;

zxerr_t addr_getNumItems(uint8_t *num_items) {
zemu_log_stack("addr_getNumItems");
// address and is_randomized flag
*num_items = 2;
// in expert mode we show the path
if (app_mode_expert()) {
*num_items = 3;
}
// address, account and is_randomized flag
*num_items = 3;
return zxerr_ok;
}

Expand All @@ -77,23 +74,27 @@ zxerr_t addr_getItem(int8_t displayIdx, char *outKey, uint16_t outKeyLen, char *
if (ret < 0) return zxerr_unknown;

pageString(outVal, outValLen, encoded_addr, pageIdx, pageCount);

return zxerr_ok;

case 1: {
snprintf(outKey, outKeyLen, "Randomized");
const char *buffer = is_randomized ? "Yes" : "No";
snprintf(outKey, outKeyLen, "Account");
char buffer[100] = {0};
ZEMU_LOGF(50, "[Account****] %d\n", address_idx_account)

const char *err = NULL;
err = uint32_to_str(buffer, sizeof(buffer), address_idx_account);

if (err != NULL) {
return zxerr_unknown;
}

pageString(outVal, outValLen, buffer, pageIdx, pageCount);

return zxerr_ok;
}
case 2: {
if (!app_mode_expert()) {
return zxerr_no_data;
}

snprintf(outKey, outKeyLen, "Your Path");
char buffer[300];
bip32_to_str(buffer, sizeof(buffer), hdPath, HDPATH_LEN_DEFAULT);
snprintf(outKey, outKeyLen, "Randomized");
const char *buffer = is_randomized ? "Yes" : "No";
pageString(outVal, outValLen, buffer, pageIdx, pageCount);

return zxerr_ok;
Expand Down
91 changes: 67 additions & 24 deletions app/src/apdu_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,26 @@ void extractHDPath(uint32_t rx, uint32_t offset) {
memcpy(hdPath, G_io_apdu_buffer + offset, sizeof(uint32_t) * HDPATH_LEN_DEFAULT);

// #{TODO} --> testnet necessary?
const bool mainnet = hdPath[0] == HDPATH_0_DEFAULT && hdPath[1] == HDPATH_1_DEFAULT;
const bool mainnet = hdPath[0] == HDPATH_0_DEFAULT && hdPath[1] == HDPATH_1_DEFAULT && hdPath[2] == HDPATH_2_DEFAULT;

if (!mainnet) {
THROW(APDU_CODE_DATA_INVALID);
}
}

void extractAddressIndex(uint32_t rx, uint32_t offset, address_index_t *address_index) {
if (address_index == NULL) {
THROW(APDU_CODE_DATA_INVALID);
}

// check for account data
if (rx < offset || (rx - offset) < sizeof(address_index_t)) {
THROW(APDU_CODE_WRONG_LENGTH);
}

memcpy(address_index, &G_io_apdu_buffer[offset], sizeof(address_index_t));
}

__Z_INLINE bool process_chunk(__Z_UNUSED volatile uint32_t *tx, uint32_t rx) {
const uint8_t payloadType = G_io_apdu_buffer[OFFSET_PAYLOAD_TYPE];
if (rx < OFFSET_DATA) {
Expand Down Expand Up @@ -104,30 +117,10 @@ __Z_INLINE void handleGetAddr(volatile uint32_t *flags, volatile uint32_t *tx, u
const uint8_t requireConfirmation = G_io_apdu_buffer[OFFSET_P1];

// go to the account + randomizer data
uint32_t account_offset = OFFSET_DATA + sizeof(uint32_t) * HDPATH_LEN_DEFAULT;
uint32_t rand_offset = account_offset + sizeof(uint32_t);

uint32_t account = 0;

// check for account data
if (rx < account_offset || (rx - account_offset) < sizeof(uint32_t)) {
THROW(APDU_CODE_WRONG_LENGTH);
}

U32_BE(&G_io_apdu_buffer[account_offset], account);
address_index_t address_index = {0};
extractAddressIndex(rx, OFFSET_DATA + sizeof(uint32_t) * HDPATH_LEN_DEFAULT, &address_index);

uint8_t *randomizer = NULL;
uint8_t rand_data[ADDR_RANDOMIZER_LEN] = {0};

// check if we received the randomizer, if so check also we received
// the expected amount of bytes for it.
if (rx > rand_offset && (rx - rand_offset) >= ADDR_RANDOMIZER_LEN) {
memcpy(rand_data, &G_io_apdu_buffer[rand_offset], ADDR_RANDOMIZER_LEN);
randomizer = &rand_data[0];
}

// TODO: I have to send 0 instead of account to get the same result as penumbra repo
zxerr_t zxerr = app_fill_address(0, randomizer);
zxerr_t zxerr = app_fill_address(address_index);

if (zxerr != zxerr_ok) {
*tx = 0;
Expand Down Expand Up @@ -219,6 +212,7 @@ __Z_INLINE void handle_getversion(__Z_UNUSED volatile uint32_t *flags, volatile
void handleTest(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) { THROW(APDU_CODE_OK); }
#endif

#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || defined(TARGET_FLEX)
void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
zemu_log("handleApdu\n");
volatile uint16_t sw = 0;
Expand Down Expand Up @@ -289,3 +283,52 @@ void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
}
END_TRY;
}
#elif defined(TARGET_NANOS)
void handleApdu(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) {
zemu_log("handleApdu\n");
volatile uint16_t sw = 0;

BEGIN_TRY {
TRY {
if (G_io_apdu_buffer[OFFSET_CLA] != CLA) {
zemu_log("CLA not supported\n");
THROW(APDU_CODE_CLA_NOT_SUPPORTED);
}

if (rx < APDU_MIN_LENGTH) {
THROW(APDU_CODE_WRONG_LENGTH);
}
if (G_io_apdu_buffer[OFFSET_INS] == INS_GET_VERSION) {
handle_getversion(flags, tx);
}
#if defined(APP_TESTING)
else if (G_io_apdu_buffer[OFFSET_INS] == INS_TEST) {
handleTest(flags, tx, rx);
THROW(APDU_CODE_OK);
}
#endif
else {
zemu_log("ins_not_supported**\n");
THROW(APDU_CODE_INS_NOT_SUPPORTED);
}
}
CATCH(EXCEPTION_IO_RESET) { THROW(EXCEPTION_IO_RESET); }
CATCH_OTHER(e) {
switch (e & 0xF000) {
case 0x6000:
case APDU_CODE_OK:
sw = e;
break;
default:
sw = 0x6800 | (e & 0x7FF);
break;
}
G_io_apdu_buffer[*tx] = sw >> 8;
G_io_apdu_buffer[*tx + 1] = sw & 0xFF;
*tx += 2;
}
FINALLY {}
}
END_TRY;
}
#endif
6 changes: 2 additions & 4 deletions app/src/coin.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@
extern "C" {
#endif

// #{TODO} ---> Replace CLA, Token symbol, HDPATH, etc etc
#define CLA 0x80

// according to penumbra docs:
// m/44'/6532'/x'
// m/44'/6532'/0'
#define HDPATH_LEN_DEFAULT 3
#define HDPATH_0_DEFAULT (0x80000000u | 0x2c) // 44
#define HDPATH_1_DEFAULT (0x80000000u | 0x1984) // 6532

#define HDPATH_2_DEFAULT (0x80000000u | 0u)
#define HDPATH_2_DEFAULT (0x80000000u | 0u) // 0

#define SECP256K1_PK_LEN 65u

Expand Down
Loading

0 comments on commit 802f4b9

Please sign in to comment.