Skip to content

Commit

Permalink
Fixed issue with restarting input from a previous word on Nano S
Browse files Browse the repository at this point in the history
Fixes #9
  • Loading branch information
aido committed Nov 18, 2023
1 parent 05b78c8 commit 0e3f5df
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 38 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Change log

## [1.5.3] - 2023-11-16
## [1.5.3] - 2023-11-18
### Added
- Added unit tests for BIP39
- Added unit tests for BIP39 word list and SSKR word list
Expand All @@ -10,6 +10,7 @@

### Fixed
- Fixed CodeQL warnings about sign check of a bitwise operation
- Fixed issue with restarting input from a previous word on Nano S

## [1.5.2] - 2023-11-15
### Added
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ For more information about SSKR, see [SSKR for Users](https://github.com/Blockch
## Check Shamir's secret shares
The Ledger application also provides an option to confirm the onboarded seed against SSKR shares.

## Generate BIP39
When the Shamir's secret shares have been validated the user can generate the BIP39 recovery phrase derived from those shares. This option takes advantage of SSKR's ability to perform a BIP39 <-> SSKR round trip. If a user has lost or damaged their original Ledger device they may need to generate the BIP39 recovery phrase on another secure device. A BIP39 recovery phrase may still be generated even if the SSKR phrases do not match the onboarded seed of a device but are still valid SSKR shares.

## Generate [BIP85](https://github.com/bitcoin/bips/blob/master/bip-0085.mediawiki)
Coming soon!!!!

Expand Down
63 changes: 37 additions & 26 deletions src/nano/nanos_enter_phrase.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
#ifdef TARGET_NANOS

// allow to edit back any entered word
#define RESTORE_WORD_MAX_BACKWARD_STEPS 24
#define RESTORE_BIP39_WORD_MAX_BACKWARD_STEPS 24
#define RESTORE_SSKR_WORD_MAX_BACKWARD_STEPS 46

const bagl_element_t* screen_onboarding_restore_word_before_element_display_callback(
const bagl_element_t* element);
Expand Down Expand Up @@ -280,9 +281,15 @@ const bagl_element_t* screen_onboarding_restore_word_keyboard_callback(unsigned
// update the slider's possible words
// account for the extra clear word, and clear any previous word items (go back
// in the onboarding process)
bolos_ux_hslider3_init(G_bolos_ux_context.onboarding_words_checked +
MIN(G_bolos_ux_context.onboarding_step + 1,
RESTORE_WORD_MAX_BACKWARD_STEPS));
if (G_bolos_ux_context.onboarding_type == ONBOARDING_TYPE_BIP39) {
bolos_ux_hslider3_init(G_bolos_ux_context.onboarding_words_checked +
MIN(G_bolos_ux_context.onboarding_step + 1,
RESTORE_BIP39_WORD_MAX_BACKWARD_STEPS));
} else if (G_bolos_ux_context.onboarding_type == ONBOARDING_TYPE_SSKR) {
bolos_ux_hslider3_init(G_bolos_ux_context.onboarding_words_checked +
MIN(G_bolos_ux_context.onboarding_step + 1,
RESTORE_SSKR_WORD_MAX_BACKWARD_STEPS));
}
screen_onboarding_restore_word_display_word_selection();
}
return NULL;
Expand Down Expand Up @@ -635,28 +642,33 @@ unsigned int screen_onboarding_restore_word_select_button(unsigned int button_ma
G_bolos_ux_context.onboarding_words_checked;
// remove x words
while (word_to_delete--) {
if (G_bolos_ux_context.onboarding_step &&
G_bolos_ux_context.words_buffer_length) {
// remove the last space and up to the previous space (but keep the
// previous space)
do {
G_bolos_ux_context
.words_buffer[G_bolos_ux_context.words_buffer_length - 1] = 0;
G_bolos_ux_context.words_buffer_length--;
if (G_bolos_ux_context.onboarding_type == ONBOARDING_TYPE_BIP39) {
if (G_bolos_ux_context.onboarding_step &&
G_bolos_ux_context.words_buffer_length) {
// remove the last space and up to the previous space (but keep the
// previous space)
do {
G_bolos_ux_context
.words_buffer[G_bolos_ux_context.words_buffer_length - 1] = 0;
G_bolos_ux_context.words_buffer_length--;
}
// until a previous word exists!
while (
G_bolos_ux_context.words_buffer_length &&
G_bolos_ux_context
.words_buffer[G_bolos_ux_context.words_buffer_length - 1] !=
' ');

// decrement onboarding_step (current word #)
G_bolos_ux_context.onboarding_step--;
}
} else if (G_bolos_ux_context.onboarding_type == ONBOARDING_TYPE_SSKR) {
if (G_bolos_ux_context.onboarding_step &&
G_bolos_ux_context.sskr_words_buffer_length) {
G_bolos_ux_context.sskr_words_buffer_length--;
// decrement onboarding_step (current word #)
G_bolos_ux_context.onboarding_step--;
}
// until a previous word exists!
while (G_bolos_ux_context.words_buffer_length &&
G_bolos_ux_context
.words_buffer[G_bolos_ux_context.words_buffer_length - 1] !=
' ');

// decrement onboarding_step (current word #)
G_bolos_ux_context.onboarding_step--;
}
if (G_bolos_ux_context.onboarding_type == ONBOARDING_TYPE_SSKR) {
G_bolos_ux_context
.sskr_words_buffer[G_bolos_ux_context.sskr_words_buffer_length - 1] = 0;
G_bolos_ux_context.sskr_words_buffer_length--;
}
}
// clear previous word
Expand All @@ -673,7 +685,6 @@ void screen_onboarding_restore_word_init(unsigned int action) {
// start by restore first word (+1 when displayed)
G_bolos_ux_context.onboarding_step = 0;
G_bolos_ux_context.sskr_share_index = 0;
G_bolos_ux_context.sskr_share_count = 0;

// flush the words first
memzero(G_bolos_ux_context.words_buffer, sizeof(G_bolos_ux_context.words_buffer));
Expand Down
1 change: 0 additions & 1 deletion src/nano/nanox_enter_phrase.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,6 @@ void screen_onboarding_restore_word_init(unsigned int firstWord) {
// start by restore first word (+1 when displayed)
G_bolos_ux_context.onboarding_step = 0;
G_bolos_ux_context.sskr_share_index = 0;
G_bolos_ux_context.sskr_share_count = 0;

// flush the words first
memzero(G_bolos_ux_context.words_buffer, sizeof(G_bolos_ux_context.words_buffer));
Expand Down
20 changes: 10 additions & 10 deletions tests/deprecated/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ There are a couple of ways of running each test. Using curl to POST button pushe
### 12 Word Tests
#### API with curl
```bash
./speculos.py ../app-sskr-check/build/nanos/bin/app.elf --model nanos --seed "fly mule excess resource treat plunge nose soda reflect adult ramp planet"
./speculos.py ../app-seed-tool/build/nanos/bin/app.elf --model nanos --seed "fly mule excess resource treat plunge nose soda reflect adult ramp planet"
```
##### nanos
```bash
Expand All @@ -22,12 +22,12 @@ cut -d# -f1 ./tests/deprecated/stax-bip39-12-word.test | while read LINE ; do ec
```
#### Speculos automation
```bash
./speculos.py --automation file:../app-sskr-check/test/speculos/nanos-bip39-12-word.json ../app-sskr-check/build/nanos/bin/app.elf --model nanos --seed "fly mule excess resource treat plunge nose soda reflect adult ramp planet"
./speculos.py --automation file:../app-seed-tool/test/speculos/nanos-bip39-12-word.json ../app-seed-tool/build/nanos/bin/app.elf --model nanos --seed "fly mule excess resource treat plunge nose soda reflect adult ramp planet"
```
### 18 Word Tests
#### API with curl
```bash
./speculos.py ../app-sskr-check/build/nanos/bin/app.elf --model nanos --seed "profit result tip galaxy hawk immune hockey series melody grape unusual prize nothing federal dad crew pact sad"
./speculos.py ../app-seed-tool/build/nanos/bin/app.elf --model nanos --seed "profit result tip galaxy hawk immune hockey series melody grape unusual prize nothing federal dad crew pact sad"
```
```bash
while read -a LINE
Expand All @@ -37,12 +37,12 @@ done < ./test/speculos/nanos-bip39-18-word.test > /dev/null 2>&1 &
```
#### Speculos automation
```bash
./speculos.py --automation file:../app-sskr-check/test/speculos/nanos-bip39-18-word.json ../app-sskr-check/build/nanos/bin/app.elf --model nanos --seed "profit result tip galaxy hawk immune hockey series melody grape unusual prize nothing federal dad crew pact sad"
./speculos.py --automation file:../app-seed-tool/test/speculos/nanos-bip39-18-word.json ../app-seed-tool/build/nanos/bin/app.elf --model nanos --seed "profit result tip galaxy hawk immune hockey series melody grape unusual prize nothing federal dad crew pact sad"
```
### 24 Word Tests
#### API with curl
```bash
./speculos.py ../app-sskr-check/build/nanos/bin/app.elf --model nanos --seed "toe priority custom gauge jacket theme arrest bargain gloom wide ill fit eagle prepare capable fish limb cigar reform other priority speak rough imitate"
./speculos.py ../app-seed-tool/build/nanos/bin/app.elf --model nanos --seed "toe priority custom gauge jacket theme arrest bargain gloom wide ill fit eagle prepare capable fish limb cigar reform other priority speak rough imitate"
```
```bash
while read -a LINE
Expand All @@ -52,15 +52,15 @@ done < ./test/speculos/nanos-bip39-24-word.test > /dev/null 2>&1 &
```
#### Speculos automation
```bash
./speculos.py --automation file:../app-sskr-check/test/speculos/nanos-bip39-24-word.json ../app-sskr-check/build/nanos/bin/app.elf --model nanos --seed "toe priority custom gauge jacket theme arrest bargain gloom wide ill fit eagle prepare capable fish limb cigar reform other priority speak rough imitate"
./speculos.py --automation file:../app-seed-tool/test/speculos/nanos-bip39-24-word.json ../app-seed-tool/build/nanos/bin/app.elf --model nanos --seed "toe priority custom gauge jacket theme arrest bargain gloom wide ill fit eagle prepare capable fish limb cigar reform other priority speak rough imitate"
```
## SSKR
### 128-bit seed
Tests taken from the [SSKR Example & Test Vector]( https://github.com/BlockchainCommons/crypto-commons/blob/master/Docs/sskr-test-vector.md#128-bit-seed) page.

#### API with curl
```bash
./speculos.py ../app-sskr-check/build/nanos/bin/app.elf --model nanos --seed "fly mule excess resource treat plunge nose soda reflect adult ramp planet"
./speculos.py ../app-seed-tool/build/nanos/bin/app.elf --model nanos --seed "fly mule excess resource treat plunge nose soda reflect adult ramp planet"
```
```bash
while read -a LINE
Expand All @@ -70,13 +70,13 @@ done < ./test/speculos/nanos-sskr-128bit.test > /dev/null 2>&1 &
```
#### Speculos automation
```bash
./speculos.py --automation file:../app-sskr-check/test/speculos/nanos-sskr-128bit.json ../app-sskr-check/build/nanos/bin/app.elf --model nanos --seed "fly mule excess resource treat plunge nose soda reflect adult ramp planet"
./speculos.py --automation file:../app-seed-tool/test/speculos/nanos-sskr-128bit.json ../app-seed-tool/build/nanos/bin/app.elf --model nanos --seed "fly mule excess resource treat plunge nose soda reflect adult ramp planet"
```
### 256-bit seed
Tests taken from the [SSKR Example & Test Vector]( https://github.com/BlockchainCommons/crypto-commons/blob/master/Docs/sskr-test-vector.md#256-bit-seed) page.
#### API with curl
```bash
./speculos.py ../app-sskr-check/build/nanos/bin/app.elf --model nanos --seed "toe priority custom gauge jacket theme arrest bargain gloom wide ill fit eagle prepare capable fish limb cigar reform other priority speak rough imitate"
./speculos.py ../app-seed-tool/build/nanos/bin/app.elf --model nanos --seed "toe priority custom gauge jacket theme arrest bargain gloom wide ill fit eagle prepare capable fish limb cigar reform other priority speak rough imitate"
```
```bash
while read -a LINE
Expand All @@ -86,5 +86,5 @@ done < ./test/speculos/nanos-sskr-256bit.test > /dev/null 2>&1 &
```
#### Speculos automation
```bash
./speculos.py --automation file:../app-sskr-check/test/speculos/nanos-sskr-256bit.json ../app-sskr-check/build/nanos/bin/app.elf --model nanos --seed "toe priority custom gauge jacket theme arrest bargain gloom wide ill fit eagle prepare capable fish limb cigar reform other priority speak rough imitate"
./speculos.py --automation file:../app-seed-tool/test/speculos/nanos-sskr-256bit.json ../app-seed-tool/build/nanos/bin/app.elf --model nanos --seed "toe priority custom gauge jacket theme arrest bargain gloom wide ill fit eagle prepare capable fish limb cigar reform other priority speak rough imitate"
```

0 comments on commit 0e3f5df

Please sign in to comment.