Skip to content

Commit

Permalink
Adjust to burst.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjos2372 committed May 17, 2020
1 parent fc6b6c5 commit cf6e1d2
Show file tree
Hide file tree
Showing 28 changed files with 746 additions and 997 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@

bin/

dev-env/

ledger/

debug/

dep/
Expand All @@ -13,5 +17,4 @@ src/glyphs\.h

usbtool/

src/txnTypeLists.c
.vscode/
Binary file removed ArdorIconNanoS.gif
Binary file not shown.
Binary file removed ArdorIconNanoX.gif
Binary file not shown.
50 changes: 11 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# limitations under the License.
#*******************************************************************************

#Defines
DEVEL = 0#This means we are in DEBUG mode, change this up when releasing in production
# DEVEL = 1 we are in DEBUG mode, change this up when releasing in production
DEVEL = 1

#####################################3

Expand All @@ -27,35 +27,17 @@ endif

include $(BOLOS_SDK)/Makefile.defines

ifndef COIN
COIN=ardor
endif

ifeq ($(COIN),ardor)
APPNAME = Ardor
DEFINES = "PATH_PREFIX={44|0x80000000,16754|0x80000000}"
PATH_PREFIX = "44'/16754'"
DEFINES += APP_PREFIX=\"ARDOR-\"
APPNAME = Burstcoin
DEFINES = "PATH_PREFIX={44|0x80000000,30|0x80000000}"
PATH_PREFIX = "44'/30'"
DEFINES += APP_PREFIX=\"BURST-\"

ifeq ($(TARGET_NAME),TARGET_NANOX)
ICONNAME = ArdorIconNanoX.gif
else
ICONNAME = ArdorIconNanoS.gif
endif
else ifeq ($(COIN),nxt)
APPNAME = NXT
DEFINES = "PATH_PREFIX={44|0x80000000,29|0x80000000}"
PATH_PREFIX = "44'/29'"
DEFINES += APP_PREFIX=\"NXT-\"

ifeq ($(TARGET_NAME),TARGET_NANOX)
ICONNAME = NXTIconNanoX.gif
else
ICONNAME = NXTIconNanoS.gif
endif
ifeq ($(TARGET_NAME),TARGET_NANOX)
ICONNAME = icons/nanox_app_burst.gif
else
$(error /!\ Coin "$(COIN)" not in list of allowed variants! Type "make listvariants" for variants list. Build non-default variant with "make COIN=<variant>")
ICONNAME = icons/nanos_app_burst.gif
endif

$(info Building $(APPNAME) app...)

############
Expand Down Expand Up @@ -95,7 +77,7 @@ endif

DEFINES += HAVE_UX_FLOW

APPVERSION_M = 1
APPVERSION_M = 0
APPVERSION_N = 0
APPVERSION_P = 1

Expand Down Expand Up @@ -139,20 +121,12 @@ else
DEFINES += PRINTF\(...\)=
endif

AUTOGEN_SRC := src/txnTypeLists.c
AUTOGEN_OBJ := $(AUTOGEN_SRC:src/%.c=obj/%.o)

SOURCE_FILES += $(AUTOGEN_SRC)

.PHONY: realclean clean

all: default

$(AUTOGEN_OBJ): src/authAndSignTxn.c $(AUTOGEN_SRC)

$(AUTOGEN_SRC): createTxnTypes.py txtypes.txt
python ./createTxnTypes.py > $@

load: all
python -m ledgerblue.loadApp $(APP_LOAD_PARAMS)

Expand Down Expand Up @@ -199,5 +173,3 @@ include $(BOLOS_SDK)/Makefile.rules

dep/%.d: %.c Makefile

listvariants:
@echo VARIANTS COIN ardor nxt
Binary file removed NXTIconNanoS.gif
Binary file not shown.
Binary file removed NXTIconNanoX.gif
Binary file not shown.
53 changes: 24 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
# Ledger App for Ardor
# Ledger App for Burst

This is the official [Ardor](https://www.jelurida.com/ardor) ledger wallet app for the Ledger Nano S and X devices
This is the official [Burst](https://burst-coin.org) ledger wallet app for the Ledger Nano S and X devices.
Initially forked from app-ledger-ardor but transaction parsing and signing were rewritten.

## Documentation

[Ardor Wiki](https://ardordocs.jelurida.com/Connect_Ledger_Nano_S_to_your_Ardor_Wallet), [Ledger Documentation Hub](https://ledger.readthedocs.io/en/latest/)
[Burst Wiki](https://burstwiki.org/en/), [Ledger Documentation Hub](https://ledger.readthedocs.io/en/latest/)

## Developer Resources

### Enable Log Messages
### Prepare the environment

To turn on logging on the Ledger app
1. Install the [debug firmware](https://ledger.readthedocs.io/en/latest/userspace/debugging.html)
2. Enable debugging in the makefile (DEVEL = 1) - make sure not to commit this change
3. Execute `make clean` and then `make load` to generate the source code for all the PRINTF statements
First, **update your ledger to the latest firmware**.

### Switch Between Target Builds
After that, install prerequisite packages:

In order to build the Nano S or Nano X version you just need to make sure the `BOLOS_SDK` environment variable points to the corresponding SDK.
```bash
sudo apt install python3-venv python3-dev libudev-dev libusb-1.0-0-dev libtinfo.so.5
```

Make sure you rebuild the whole project by executing `make clean` and then `make load`.
Now use the `prepare-devenv.sh` script to prepare a local development environment with the right target (`s` or `x`).

### Avoid Numeric Underflow
```bash
# (x or s, depending on your device)
source prepare-devenv.sh s
```

Be careful not to underflow unsigned numeric types, for example:
### Enable Log Messages (optional)

`n = (dataLength - 32) / sizeof(uint32_t);`

This line would underflow in case the `dataLength` variable is smaller than 32 which might lead to disaster
so please review carefully all substraction operations.
To turn on logging on the Ledger app
1. Install the [debug firmware](https://ledger.readthedocs.io/en/latest/userspace/debugging.html)
2. Enable debugging in the makefile (DEVEL = 1) - make sure not to commit this change
3. Execute `make clean` and then `make load` to generate the source code for all the PRINTF statements

### Zero Tolerance for Compilation Warnings

Expand All @@ -39,7 +42,7 @@ since they are externally imported.

### State Cleaning

Since we use a union data type for command handlers state (`states_t` in `ardor.h`) to save memory, make sure to **clear this state**
Since we use a union data type for command handlers state (`states_t` in `burst.h`) to save memory, make sure to **clear this state**
to avoid some attack vectors.

This is done by passing `true` in the `isLastCommandDifferent` parameter of the handler function. In this case the handler has
Expand All @@ -53,17 +56,9 @@ Do not include statement for C source code inside other C source code to prevent

Store constants and hardcoded values in config.h

### Transaction Types

The `txnTypesList.c` source file is autogenerated by the `createTxnTypes.py` script from the `txtypes.txt` file. This step is automatically handled by the makefile.

`txtypes.txt` should be generated externally by the Ardor developers whenever they add a new transaction type.

Changes to the `txtypes.txt` should be picked up by the make process and a new `txnTypesList.c` automatically generated. The `txnTypesList.c` is not deleted on `make clean` but you can use `make realclean` that cleans everything.

### Code Flow

The code flow starts at ardor_main (`main.c`) which uses a global try/catch to prevent the app from crashing on error.
The code flow starts at burst_main (`main.c`) which uses a global try/catch to prevent the app from crashing on error.
The code loops on io_exchange waiting for the next command buffer, then calling the appropriate handler function
implemented in the different .c files.

Expand Down Expand Up @@ -114,9 +109,9 @@ All return values for functions should be checked in every function.

## Key Derivation Algorithm

Ardor signatures are based on the EC-KCDSA over Curve25519 algorithm which is not supported natively by Ledger.
Burst signatures are based on the EC-KCDSA over Curve25519 algorithm which is not supported natively by Ledger.

To support standard BIP32 key derivation we implemented curve conversion for Ardor using the protocol
To support standard BIP32 key derivation we implemented curve conversion for Burst using the protocol
[Yaffe-Bender HD key derivation for EC-KCDSA](https://www.jelurida.com/sites/default/files/kcdsa.pdf)

Technically a public key is a Point (X,Y) on a curve C. X,Y are integers modulo some field F with a base point on the curve G.
Expand Down
30 changes: 0 additions & 30 deletions createTxnTypes.py

This file was deleted.

Binary file modified glyphs/icon_dashboard.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/nanos_app_burst.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/nanox_app_burst.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed nanos_1.gif
Binary file not shown.
79 changes: 79 additions & 0 deletions prepare-devenv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# shellcheck disable=SC1091,SC2155

# SOURCE THIS FILE
# . prepare-devenv blue|s|x

if [ $# -ne 1 ]; then
echo "Possible options: blue, s or x"
return
elif [[ $1 == "-h" ]]; then
echo "Possible options: blue, s or x"
return
elif [[ $1 != "blue" ]] && [[ $1 != "s" ]] && [[ $1 != "x" ]]; then
echo "Possible options: blue, s or x"
return
fi

if [[ $(dpkg-query -s python3-venv 2>&1) == *'is not installed'* ]]; then
printf "\nPackage python3-venv is missing.\nOn Debian-like distros, run:\n\napt install python3-venv\n\n"
return
fi

if [[ $(cat /etc/udev/rules.d/20-hw1.rules) == *'ATTRS{idVendor}=="2c97", ATTRS{idProduct}=="0004"'* ]]; then
printf "\nMissing udev rules. Please refer to https://support.ledger.com/hc/en-us/articles/115005165269-Fix-connection-issues\n\n"
return
fi


if [ ! -d dev-env ]; then
mkdir dev-env
mkdir dev-env/SDK
mkdir dev-env/CC
mkdir dev-env/CC/others
mkdir dev-env/CC/nanox

wget https://launchpad.net/gcc-arm-embedded/5.0/5-2016-q1-update/+download/gcc-arm-none-eabi-5_3-2016q1-20160330-linux.tar.bz2
tar xf gcc-arm-none-eabi-5_3-2016q1-20160330-linux.tar.bz2
rm gcc-arm-none-eabi-5_3-2016q1-20160330-linux.tar.bz2
cp -r gcc-arm-none-eabi-5_3-2016q1 dev-env/CC/nanox/gcc-arm-none-eabi-5_3-2016q1
mv gcc-arm-none-eabi-5_3-2016q1 dev-env/CC/others/gcc-arm-none-eabi-5_3-2016q1

wget http://releases.llvm.org/4.0.0/clang+llvm-4.0.0-x86_64-linux-gnu-ubuntu-16.10.tar.xz -O clang+llvm.tar.xz
tar xf clang+llvm.tar.xz
rm clang+llvm.tar.xz
mv clang+llvm* dev-env/CC/others/clang-arm-fropi

wget http://releases.llvm.org/7.0.0/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz -O clang+llvm.tar.xz
tar xf clang+llvm.tar.xz
rm clang+llvm.tar.xz
mv clang+llvm* dev-env/CC/nanox/clang-arm-fropi

wget https://github.com/LedgerHQ/blue-secure-sdk/archive/blue-r21.1.tar.gz -O blue-secure-sdk.tar.gz
tar xf blue-secure-sdk.tar.gz
rm blue-secure-sdk.tar.gz
mv blue-secure-sdk* dev-env/SDK/blue-secure-sdk

wget https://github.com/LedgerHQ/nanos-secure-sdk/archive/nanos-160.tar.gz -O nanos-secure-sdk.tar.gz
tar xf nanos-secure-sdk.tar.gz
rm nanos-secure-sdk.tar.gz
mv nanos-secure-sdk* dev-env/SDK/nanos-secure-sdk

python3 -m venv dev-env/ledger_py3
source dev-env/ledger_py3/bin/activate
pip install wheel
pip install ledgerblue
fi


source dev-env/ledger_py3/bin/activate

if [[ $1 == "blue" ]]; then
export BOLOS_SDK=$(pwd)/dev-env/SDK/blue-secure-sdk
export BOLOS_ENV=$(pwd)/dev-env/CC/others
elif [[ $1 == "s" ]]; then
export BOLOS_SDK=$(pwd)/dev-env/SDK/nanos-secure-sdk
export BOLOS_ENV=$(pwd)/dev-env/CC/others
elif [[ $1 == "x" ]]; then
export BOLOS_SDK=$(pwd)/dev-env/SDK/nanox-secure-sdk
export BOLOS_ENV=$(pwd)/dev-env/CC/nanox
fi
Loading

0 comments on commit cf6e1d2

Please sign in to comment.