Skip to content

Commit fd927e2

Browse files
authored
Merge pull request #14 from obsidiansystems/v2.2.5
Version 2.2.5
2 parents 20c020e + b8f96d4 commit fd927e2

37 files changed

+1663
-1302
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ obj
55
src/u2f_crypto_data.h
66
src/glyphs.h
77
src/glyphs.c
8+
src/delegates.h
89

910
#ide
1011
*.code-workspace

CONTRIBUTING.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ The `nix/` folder contains helper scripts for working with the ledger via Nix.
88
Use `./nix/install.sh` to install the apps onto the ledger using Nix.
99

1010
### Developing
11-
Use `nix/env.sh <s or x> to enter a shell where you can run `make` and it will just work. You can also pass a command instead, e.g. `nix/env.sh s make clean`.
11+
Use `nix/env.sh <s or x> to enter a shell where you can run `make` and it will just work. You can also pass a command instead, e.g. `nix/env.sh s --run "make clean SHELL=bash"`.
1212

13-
For development, use `nix/watch.sh s make APP=<tezos_baking|tezos_wallet>` to incrementally build on every change. Be sure to `nix/env.sh s make clean` if you start watching a different `APP`.
13+
For development, use `nix/watch.sh s make APP=<tezos_baking|tezos_wallet>` to incrementally build on every change. Be sure to `nix/env.sh s --run "make clean SHELL=bash"` if you start watching a different `APP`.
1414

1515
### Building
1616
To do a full Nix build run `nix/build.sh`. You can pass `nix-build` arguments to this to build specific attributes, e.g. `nix/build.sh -A nano.s.wallet`.

Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ GIT_DESCRIBE ?= $(shell git describe --tags --abbrev=8 --always --long --dirty 2
1919
VERSION_TAG ?= $(shell echo "$(GIT_DESCRIBE)" | cut -f1 -d-)
2020
APPVERSION_M=2
2121
APPVERSION_N=2
22-
APPVERSION_P=1
22+
APPVERSION_P=5
2323
APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)
2424

2525
# Only warn about version tags if specified/inferred
@@ -170,3 +170,8 @@ dep/%.d: %.c Makefile
170170

171171
listvariants:
172172
@echo VARIANTS APP tezos_wallet tezos_baking
173+
174+
# Generate delegates from baker list
175+
src/delegates.h: tools/gen-delegates.sh tools/BakersRegistryCoreUnfilteredData.json
176+
bash ./tools/gen-delegates.sh ./tools/BakersRegistryCoreUnfilteredData.json
177+
dep/to_string.d: src/delegates.h

README.md

+37-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ Currently there are two other ways to do this:
426426

427427
1. If you have the Nix package manager, use the
428428
[Tezos baking platform](https://gitlab.com/obsidian.systems/tezos-baking-platform).
429-
2. Build tezos from the tezos repo with [these instructions](http://tezos.gitlab.io/mainnet/introduction/howtoget.html#build-from-sources).
429+
2. Build tezos from the tezos repo with [these instructions](http://tezos.gitlab.io/introduction/howtoget.html#build-from-sources).
430430

431431
Depending on how you build it, you might need to prefix `./` to your commands, and the names
432432
of some of the binaries might be different.
@@ -981,6 +981,42 @@ If the Ledger application crashes when you load it, there are two primary causes
981981
* Out of date firmware: If the Ledger application doesn't work at all, make sure you are running firmware
982982
version 1.5.5.
983983

984+
### Error "Unexpected sequence number (expected 0, got 191)" on macOS
985+
986+
If `tezos-client` on macOS intermittently fails with an error that looks like
987+
988+
```
989+
client.signer.ledger: APDU level error: Unexpected sequence number (expected 0, got 191)
990+
```
991+
992+
then your installation of `tezos-client` was built with an older version of HIDAPI that doesn't work well with macOS (see [#30](https://github.com/obsidiansystems/ledger-app-tezos/issues/30)).
993+
994+
To fix this you need to get the yet-unreleased fixes from the [HIDAPI library](https://github.com/signal11/hidapi) and rebuild `tezos-client`.
995+
996+
If you got HIDAPI from Homebrew, you can update to the `master` branch of HIDAPI like this:
997+
998+
```shell
999+
$ brew install hidapi --HEAD
1000+
```
1001+
1002+
Then start a full rebuild of `tezos-client` with HIDAPI's `master` branch:
1003+
1004+
```shell
1005+
$ brew unlink hidapi # remove the current one
1006+
$ brew install autoconf automake libtool # Just keep installing stuff until the following command succeeds:
1007+
$ brew install hidapi --HEAD
1008+
```
1009+
1010+
Finally, rebuild `ocaml-hidapi` with Tezos. In the `tezos` repository:
1011+
1012+
```shell
1013+
$ opam reinstall hidapi
1014+
$ make all build-test
1015+
$ ./tezos-client list connected ledgers # should now work consistently
1016+
```
1017+
1018+
Note that you may still see warnings similar to `Unexpected sequence number (expected 0, got 191)` even after this update. The reason is that there is a separate, more cosmetic, issue in `tezos-client` itself which has already been fixed but may not be in your branch yet (see the [merge request](https://gitlab.com/tezos/tezos/merge_requests/600)).
1019+
9841020
### Contact Us
9851021
You can email us at [email protected] and request to join our Slack.
9861022
We have several channels about baking and one specifically for our Ledger applications.

default.nix

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ pkgs ? import nix/nixpkgs.nix {}, gitDescribe ? "TEST-dirty", nanoXSdk ? null, ... }:
1+
{ pkgs ? import ./nix/dep/nixpkgs {}, gitDescribe ? "TEST-dirty", nanoXSdk ? null, ... }:
22
let
33
fetchThunk = p:
44
if builtins.pathExists (p + /git.json)
@@ -20,9 +20,6 @@ let
2020
} ''
2121
python ${sdk + /icon.py} '${icons/nano-s-tezos.gif}' hexbitmaponly > "$out"
2222
'';
23-
nvramDataSize = appDir: pkgs.runCommand "${name}-nvram-data-size" {} ''
24-
grep _nvram_data_size '${appDir + /debug/app.map}' | tr -s ' ' | cut -f2 -d' ' > "$out"
25-
'';
2623
};
2724
x = rec {
2825
name = "x";
@@ -37,15 +34,10 @@ let
3734
} ''
3835
python '${sdk + /icon3.py}' --hexbitmaponly '${icons/nano-x-tezos.gif}' > "$out"
3936
'';
40-
nvramDataSize = appDir: pkgs.runCommand "${name}-nvram-data-size" {} ''
41-
envram_data="0x$(cat | grep _envram_data '${appDir + /debug/app.map}' | cut -f1 -d' ')"
42-
nvram_data="0x$(grep _nvram_data '${appDir + /debug/app.map}' | cut -f1 -d' ')"
43-
echo "$(($envram_data - $nvram_data))" > "$out"
44-
'';
4537
};
4638
};
4739

48-
src = pkgs.lib.sources.sourceFilesBySuffices (pkgs.lib.sources.cleanSource ./.) [".c" ".h" ".gif" "Makefile"];
40+
src = pkgs.lib.sources.sourceFilesBySuffices (pkgs.lib.sources.cleanSource ./.) [".c" ".h" ".gif" "Makefile" ".sh" ".json"];
4941

5042
build = bolos:
5143
let
@@ -57,6 +49,7 @@ let
5749
'';
5850
nativeBuildInputs = [
5951
(pkgs.python3.withPackages (ps: [ps.pillow ps.ledgerblue]))
52+
pkgs.jq
6053
];
6154
TARGET = bolos.target;
6255
GIT_DESCRIBE = gitDescribe;
@@ -75,14 +68,19 @@ let
7568
size $out/bin/app.elf
7669
'';
7770
};
71+
nvramDataSize = appDir: pkgs.runCommand "nvram-data-size" {} ''
72+
envram_data="$(grep _envram_data '${appDir + /debug/app.map}' | tr -s ' ' | cut -f2 -d' ')"
73+
nvram_data="$(grep _nvram_data '${appDir + /debug/app.map}' | tr -s ' ' | cut -f2 -d' ')"
74+
echo "$(($envram_data - $nvram_data))" > "$out"
75+
'';
7876
mkRelease = short_name: name: appDir: pkgs.runCommand "${short_name}-nano-${bolos.name}-release-dir" {} ''
7977
mkdir -p "$out"
8078
8179
cp '${appDir + /bin/app.hex}' "$out/app.hex"
8280
8381
cat > "$out/app.manifest" <<EOF
8482
name='${name}'
85-
nvram_size=$(cat '${bolos.nvramDataSize appDir}')
83+
nvram_size=$(cat '${nvramDataSize appDir}')
8684
target='nano_${bolos.name}'
8785
target_id=${bolos.targetId}
8886
version=$(echo '${gitDescribe}' | cut -f1 -d- | cut -f2 -dv)

nix/dep/flextesa-dev/default.nix

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# DO NOT HAND-EDIT THIS FILE
2+
let fetchGit = {url, rev, ref ? null, branch ? null, sha256 ? null, fetchSubmodules ? null}:
3+
assert !fetchSubmodules; (import <nixpkgs> {}).fetchgit { inherit url rev sha256; };
4+
in import (fetchGit (builtins.fromJSON (builtins.readFile ./git.json)))

nix/dep/flextesa-dev/git.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"url": "https://gitlab.com/obsidian.systems/tezos.git",
3+
"rev": "08c288ebe13d3647294a8603358ad98771eea7b1",
4+
"sha256": "0kdnzd3ib93r63h509jd5c85svj0wyqcyi1v85xkghg94raswj0b",
5+
"fetchSubmodules": false,
6+
"branch": "flextesa-dev-master"
7+
}

nix/dep/nanos-secure-sdk/github.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"owner": "LedgerHQ",
33
"repo": "nanos-secure-sdk",
4-
"branch": "master",
5-
"rev": "f9e1c7b8904df2eee0ae7e603f552b876c169334",
6-
"sha256": "1wzra32zkqw521a5cmvqsblpkbkfzgx2pbngqpymcgf8db20p50i"
4+
"branch": "og-1.6.0-1",
5+
"rev": "5844b50daaf70108ef5464b7004561be0442edd1",
6+
"sha256": "0r5bnn46ay01imxzsg0iy30aa6yaa9rx7j54ifj3a4ahlfw51nkc"
77
}

nix/dep/nixpkgs/default.nix

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# DO NOT HAND-EDIT THIS FILE
2+
import ((import <nixpkgs> {}).fetchFromGitHub (
3+
let json = builtins.fromJSON (builtins.readFile ./github.json);
4+
in { inherit (json) owner repo rev sha256;
5+
private = json.private or false;
6+
}
7+
))

nix/dep/nixpkgs/github.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"owner": "NixOS",
3+
"repo": "nixpkgs",
4+
"branch": "nixos-unstable",
5+
"rev": "41d921292e922a6cd1aba64259341c244d4c2cc7",
6+
"sha256": "01iq7phnmyz78qddxsjy6lnpgmzcffxk9h7k69sy61dbjsyy9b4q"
7+
}

nix/env.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ root="$(git rev-parse --show-toplevel)"
88
if [ $# -eq 0 ]; then
99
exec nix-shell "$root" -A "nano.${target}.wallet"
1010
else
11-
exec nix-shell "$root" -A "nano.${target}.wallet" --run "$(echo "$@")"
11+
exec nix-shell "$root" -A "nano.${target}.wallet" "$@"
1212
fi

nix/ledgerblue.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ pkgs ? import ../nix/nixpkgs.nix {}, ... }:
1+
{ pkgs ? import ../nix/dep/nixpkgs {}, ... }:
22
rec {
33
withLedgerblue = (pkgs.python36.withPackages (ps: with ps; [
44
ecpy hidapi pycrypto python-u2flib-host requests ledgerblue pillow pkgs.hidapi protobuf

nix/nixpkgs.nix

-10
This file was deleted.

nix/setup-vscode.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ cd "$root"
77
cp -f "$(nix-build -A env.s.ide.config.vscode --no-out-link)" "vscode.code-workspace"
88
chmod +w "vscode.code-workspace"
99

10-
bear="$(nix-build -E '(import nix/nixpkgs.nix {}).bear' --no-out-link)/bin/bear"
10+
bear="$(nix-build -E '(import ./nix/dep/nixpkgs {}).bear' --no-out-link)/bin/bear"
1111
# c.f. https://github.com/rizsotto/Bear/issues/182
12-
nix/env.sh s "export LANG=C.UTF-8; export LC_CTYPE=C.UTF-8; make clean && \"$bear\" make; make clean"
12+
nix/env.sh s --run "export LANG=C.UTF-8; export LC_CTYPE=C.UTF-8; make clean && \"$bear\" make; make clean"

nix/watch.sh

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ root="$(git rev-parse --show-toplevel)"
1313

1414
watchdirs=("$root/default.nix" "$root/nix" "$root/Makefile" "$root/src" "$root/icons")
1515

16-
inotifywait="$(nix-build "$root/nix/nixpkgs.nix" -A inotify-tools --no-out-link)/bin/inotifywait"
16+
inotifywait="$(nix-build "$root/nix/dep/nixpkgs" -A inotify-tools --no-out-link)/bin/inotifywait"
1717
while true; do
18-
"$root/nix/env.sh" "$target" <<EOF
19-
$@
20-
EOF
18+
"$root/nix/env.sh" "$target" "--run" "$@"
2119
if ! "$inotifywait" -qre close_write "${watchdirs[@]}"; then
2220
fail "inotifywait failed"
2321
fi

release.nix

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
let
2+
ledger-app-tezos = import ./. {};
3+
in {
4+
analysis-nanos-wallet = ledger-app-tezos.clangAnalysis.s.wallet;
5+
analysis-nanos-baking = ledger-app-tezos.clangAnalysis.s.baking;
6+
release-nanos-wallet = ledger-app-tezos.nano.s.release.wallet;
7+
release-nanos-baking = ledger-app-tezos.nano.s.release.baking;
8+
release-nanos-all = ledger-app-tezos.nano.s.release.all;
9+
}

src/apdu.c

+2
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ void main_loop(apdu_handler const *const handlers, size_t const handlers_size) {
7979
clear_apdu_globals(); // IMPORTANT: Application state must not persist through errors
8080

8181
uint16_t sw = e;
82+
PRINTF("Error caught at top level, number: %x\n", sw);
8283
switch (sw) {
8384
default:
8485
sw = 0x6800 | (e & 0x7FF);
8586
// FALL THROUGH
8687
case 0x6000 ... 0x6FFF:
8788
case 0x9000 ... 0x9FFF: {
89+
PRINTF("Line number: %d", sw & 0x0FFF);
8890
size_t tx = 0;
8991
G_io_apdu_buffer[tx++] = sw >> 8;
9092
G_io_apdu_buffer[tx++] = sw;

src/apdu_baking.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static bool reset_ok(void);
1919
size_t handle_apdu_reset(__attribute__((unused)) uint8_t instruction) {
2020
uint8_t *dataBuffer = G_io_apdu_buffer + OFFSET_CDATA;
2121
uint32_t dataLength = G_io_apdu_buffer[OFFSET_LC];
22-
if (dataLength != sizeof(int)) {
22+
if (dataLength != sizeof(level_t)) {
2323
THROW(EXC_WRONG_LENGTH_FOR_INS);
2424
}
2525
level_t const lvl = READ_UNALIGNED_BIG_ENDIAN(level_t, dataBuffer);

src/apdu_pubkey.c

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include "protocol.h"
88
#include "to_string.h"
99
#include "ui.h"
10+
#ifdef BAKING_APP
11+
#include "baking_auth.h"
12+
#endif // BAKING_APP
1013

1114
#include <string.h>
1215

0 commit comments

Comments
 (0)