Skip to content

Commit

Permalink
Merge pull request #76 from Zondax/feature/ledger-v5-new
Browse files Browse the repository at this point in the history
Adding support for v5 transactions
  • Loading branch information
IdaTucker committed May 30, 2023
2 parents 5049c24 + a27fabc commit cb23774
Show file tree
Hide file tree
Showing 99 changed files with 1,547 additions and 551 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
- name: Install node
uses: actions/setup-node@v2
with:
node-version: '14.17.0'
node-version: '14.19.0'
- name: Install yarn
run: |
npm install -g yarn
Expand Down Expand Up @@ -193,4 +193,4 @@ jobs:
files: ./app/pkg/installer_nanos_plus.sh
tag_name: ${{ steps.nanosp.outputs.tag_name }}
draft: false
prerelease: false
prerelease: false
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ yarn.lock
/app/rust/Cargo.lock
/zcashtools/target/
!/zcashtools/neon/yarn.lock
app/build/*

app/glyphs/glyphs.c

Expand Down
152 changes: 12 additions & 140 deletions app/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#*******************************************************************************
# Ledger App
# (c) 2018 - 2022 Zondax AG
# (c) 2018 - 2023 Zondax AG
# (c) 2017 Ledger
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -22,31 +22,13 @@ endif

MY_DIR := $(dir $(lastword $(MAKEFILE_LIST)))

all: bin/app.elf
@echo "#!/usr/bin/env bash" > $(OUTPUT_INSTALLER)
@echo "APPNAME=\"${APPNAME}\"" >> $(OUTPUT_INSTALLER)
@echo "APPVERSION=\"${APPVERSION}\"" >> $(OUTPUT_INSTALLER)
@echo "APPPATH=\""${APPPATH}"\"" >> $(OUTPUT_INSTALLER)
@echo "LOAD_PARAMS=($$(echo "${APP_LOAD_PARAMS}" | sed -e "s|"${APPNAME}"|\""${APPNAME}"\"|"))" >> $(OUTPUT_INSTALLER)
@echo "DELETE_PARAMS=($$(echo "${COMMON_DELETE_PARAMS}" | sed -e "s|"${APPNAME}"|\""${APPNAME}"\"|"))" >> $(OUTPUT_INSTALLER)
@echo "APPHEX=\"" >> $(OUTPUT_INSTALLER)
@cat $(CURDIR)/bin/app.hex >> $(OUTPUT_INSTALLER)
@echo "\"" >> $(OUTPUT_INSTALLER)
@cat $(CURDIR)/../deps/ledger-zxlib/scripts/template.sh >> $(OUTPUT_INSTALLER)
@chmod +x $(OUTPUT_INSTALLER)
@cp $(CURDIR)/bin/* $(CURDIR)/output
@cp $(CURDIR)/output/app.elf ${OUTPUT_ELF}
@rm $(CURDIR)/output/app.elf
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.installer_script

include $(BOLOS_SDK)/Makefile.defines

$(info ************ TARGET_NAME = [$(TARGET_NAME)])

ifeq ($(APP_TESTING),1)
DEFINES += APP_TESTING
DEFINES += ZEMU_LOGGING
$(info ************ LOGGING ENABLED ************)
endif
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.app_testing

ifndef COIN
COIN=ZEC
Expand All @@ -62,39 +44,15 @@ APPNAME = "Zcash"
APPPATH = "44'/133'"
else
define error_message


COIN value not supported: [$(COIN)]


endef
$(error "$(error_message)")
endif

APP_LOAD_PARAMS = $(COMMON_LOAD_PARAMS) --path $(APPPATH)
APP_LOAD_PARAMS = --curve secp256k1 $(COMMON_LOAD_PARAMS) --path $(APPPATH)

ifeq ($(TARGET_NAME),TARGET_NANOS)
APP_LOAD_PARAMS += --appFlags 0x000
APP_STACK_SIZE:=3216
ICONNAME:=$(CURDIR)/nanos_icon.gif
OUTPUT_ELF ?= $(CURDIR)/output/app_s.elf
OUTPUT_INSTALLER := $(CURDIR)/pkg/installer_s.sh
endif

ifeq ($(TARGET_NAME),TARGET_NANOX)
APP_LOAD_PARAMS += --appFlags 0x200
ICONNAME:=$(CURDIR)/nanox_icon.gif
OUTPUT_ELF ?= $(CURDIR)/output/app_x.elf
OUTPUT_INSTALLER:= $(CURDIR)/pkg/installer_x.sh
endif

ifeq ($(TARGET_NAME),TARGET_NANOS2)
APP_LOAD_PARAMS += --appFlags 0x000
SCRIPT_LD:=$(CURDIR)/script_s2.ld
ICONNAME:=$(CURDIR)/nanox_icon.gif
OUTPUT_ELF ?= $(CURDIR)/output/app_s2.elf
OUTPUT_INSTALLER:= $(CURDIR)/pkg/installer_s2.sh
endif
NANOS_STACK_SIZE := 3216
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices

$(info TARGET_NAME = [$(TARGET_NAME)])
$(info ICONNAME = [$(ICONNAME)])
Expand All @@ -103,102 +61,16 @@ ifndef ICONNAME
$(error ICONNAME is not set)
endif

############
# Platform
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.platform

DEFINES += PRINTF\(...\)=

APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)
DEFINES += APPVERSION=\"$(APPVERSION)\"

DEFINES += OS_IO_SEPROXYHAL
DEFINES += HAVE_BAGL HAVE_SPRINTF
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=7 IO_HID_EP_LENGTH=64 HAVE_USB_APDU

DEFINES += LEDGER_MAJOR_VERSION=$(APPVERSION_M) LEDGER_MINOR_VERSION=$(APPVERSION_N) LEDGER_PATCH_VERSION=$(APPVERSION_P)

DEFINES += USB_SEGMENT_SIZE=64
DEFINES += HAVE_BOLOS_APP_STACK_CANARY

DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL=""
DEFINES += HAVE_HASH HAVE_BLAKE2 HAVE_SHA256 HAVE_SHA512

ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
else
# Assume Nano X/S+
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300

DEFINES += HAVE_GLO096
DEFINES += HAVE_BAGL BAGL_WIDTH=128 BAGL_HEIGHT=64
DEFINES += HAVE_BAGL_ELLIPSIS # long label truncation feature
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_REGULAR_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_EXTRABOLD_11PX
DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX

DEFINES += HAVE_UX_FLOW
endif

ifeq ($(TARGET_NAME),TARGET_NANOX)
# X specific
DEFINES += HAVE_BLE
DEFINES += HAVE_BLE_APDU BLE_COMMAND_TIMEOUT_MS=2000

SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
endif

# App specific

#Feature temporarily disabled
DEFINES += LEDGER_SPECIFIC

# Compiler, assembler, and linker

ifneq ($(BOLOS_ENV),)
$(info BOLOS_ENV is $(BOLOS_ENV))
CLANGPATH := /usr/bin/
GCCPATH := /usr/bin/
else
$(info BOLOS_ENV is not set: falling back to CLANGPATH and GCCPATH)
endif

ifeq ($(CLANGPATH),)
$(info CLANGPATH is not set: clang will be used from PATH)
endif

ifeq ($(GCCPATH),)
$(info GCCPATH is not set: arm-none-eabi-* will be used from PATH)
endif

#########################

CC := $(CLANGPATH)clang
CFLAGS += -O3 -Os -Wno-unknown-pragmas -Wno-unused-parameter -Wvla

AS := $(GCCPATH)arm-none-eabi-gcc
AFLAGS +=

LD := $(GCCPATH)arm-none-eabi-gcc
LDFLAGS += -O3 -Os
LDFLAGS += -z muldefs
LDLIBS += -lm -lgcc -lc
LDLIBS += -Lrust/target/thumbv6m-none-eabi/release -lrslib

##########################
GLYPH_SRC_DIR = glyphs
INCLUDES_PATH += $(MY_DIR)/glyphs
include $(BOLOS_SDK)/Makefile.glyphs

APP_SOURCE_PATH += $(MY_DIR)/src
APP_SOURCE_PATH += $(MY_DIR)/glyphs
APP_SOURCE_PATH += $(MY_DIR)/rust/include
APP_SOURCE_PATH += $(MY_DIR)/../deps/ledger-zxlib/include
APP_SOURCE_PATH += $(MY_DIR)/../deps/ledger-zxlib/src
APP_SOURCE_PATH += $(MY_DIR)/../deps/ledger-zxlib/app/common
APP_SOURCE_PATH += $(CURDIR)/rust/include
APP_SOURCE_PATH += $(MY_DIR)/../deps/tiny-aes/src

SDK_SOURCE_PATH += lib_stusb lib_stusb_impl
SDK_SOURCE_PATH += lib_ux
LDFLAGS += -z muldefs
LDLIBS += -Lrust/target/thumbv6m-none-eabi/release -lrslib

APP_CUSTOM_LINK_DEPENDENCIES = rust

.PHONY: rust
rust:
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=3
# This is the minor version of this release
APPVERSION_N=1
# This is the patch version of this release
APPVERSION_P=1
APPVERSION_P=2
35 changes: 0 additions & 35 deletions app/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions app/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ crate-type = ["staticlib"]
[dependencies]
jubjub = { version = "0.9", default-features = false }
rand = { version = "0.7", default-features = false }
subtle = { version = "2.4.1", default-features = false }
blake2b_simd = { version = "0.5", default-features = false }
blake2s_simd = { version = "0.5", default-features = false }
binary-ff1 = { version = "0.1.0", default-features = false }
aes = { version = "0.3", default-features = false }
byteorder = { version = "1", default-features = false }
itertools = { version = "0.9.0", default-features = false }
hex = { version = "0.4.2", default-features = false }
cstr_core = { version = "0.2.0", default-features = false }
nom = { version = "5.1.1", default-features = false }
arrayvec = { version = "0.5.1", default-features = false }
group = { version = "0.12", default-features = false }

[dependencies.chacha20poly1305]
Expand All @@ -46,7 +42,6 @@ serde_json = "1.0.53"
hex = { version = "0.4", default-features = false }
serde = { version = "1.0.110", features = ["derive"] }


[profile.release]
lto = false
codegen-units = 1
Expand Down
4 changes: 0 additions & 4 deletions app/rust/include/rslib.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
* ********************************************************************************/

//ZIP32 functions
void ask_to_ak(const uint8_t *ask_ptr, uint8_t *ak_ptr);

void get_pkd(const uint8_t *seed_ptr, const uint32_t pos, const uint8_t *diversifier_ptr, uint8_t *pkd);

void get_pkd_from_seed(const uint8_t *seed_ptr, const uint32_t pos, const uint8_t *start_index, uint8_t *diversifier_ptr, uint8_t *pkd);
Expand Down Expand Up @@ -55,8 +53,6 @@ void compute_value_commitment(const uint64_t value, const uint8_t *rcmptr, uint8

void compute_nullifier(uint8_t *ncmptr, uint64_t pos, const uint8_t *nsk_ptr, uint8_t *outputptr);

void compute_valueBalance_commitment(const uint64_t u64, uint8_t *output);

//Note encryption
void blake2b_prf(uint8_t *inputptr, uint8_t *outptr);

Expand Down
3 changes: 0 additions & 3 deletions app/rust/src/bolos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use aes::{
use blake2b_simd::{Hash as Blake2bHash, Params as Blake2bParams};
use blake2s_simd::{blake2s, Hash as Blake2sHash, Params as Blake2sParams};
use core::convert::TryInto;
use cstr_core::CStr;
#[cfg(test)]
#[cfg(any(unix, windows))]
use getrandom::getrandom;
Expand Down Expand Up @@ -69,7 +68,6 @@ extern "C" {

#[cfg(not(test))]
pub fn sdk_jubjub_scalarmult_spending_base(point: &mut [u8], scalar: &[u8]) {
c_zemu_log_stack(b"scalarmult spending base in sdk\x00".as_ref());
unsafe {
c_jubjub_spending_base_scalarmult(point.as_mut_ptr(), scalar.as_ptr());
check_app_canary();
Expand All @@ -86,7 +84,6 @@ pub fn sdk_jubjub_scalarmult_spending_base(point: &mut [u8], scalar: &[u8]) {

#[cfg(not(test))]
pub fn sdk_jubjub_scalarmult(point: &mut [u8], scalar: &[u8]) {
c_zemu_log_stack(b"scalarmult in sdk\x00".as_ref());
unsafe {
c_jubjub_scalarmult(point.as_mut_ptr(), scalar.as_ptr());
}
Expand Down
5 changes: 2 additions & 3 deletions app/rust/src/commitments.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use blake2s_simd::{blake2s, Hash as Blake2sHash, Params as Blake2sParams};
use byteorder::{BigEndian, ByteOrder, LittleEndian};
use blake2s_simd::Params as Blake2sParams;
use byteorder::LittleEndian;
use jubjub::{AffineNielsPoint, AffinePoint, ExtendedPoint, Fq, Fr};

use crate::bolos::c_zemu_log_stack;
Expand Down Expand Up @@ -128,7 +128,6 @@ pub fn add_points(a: ExtendedPoint, b: ExtendedPoint) -> ExtendedPoint {

#[inline(never)]
pub fn multiply_with_pedersenbase(val: &[u8; 32]) -> ExtendedPoint {
c_zemu_log_stack(b"mult_pedersen\x00".as_ref());
PEDERSEN_RANDOMNESS_BASE.multiply_bits(val)
}

Expand Down
5 changes: 2 additions & 3 deletions app/rust/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use group::Group;
use jubjub::{AffineNielsPoint, AffinePoint, Fq, SubgroupPoint};
use jubjub::{AffineNielsPoint, AffinePoint, Fq};

pub const SPENDING_KEY_BASE: AffineNielsPoint = AffinePoint::from_raw_unchecked(
Fq::from_raw([
Expand Down Expand Up @@ -82,4 +81,4 @@ pub const AK_NK: u8 = 0;
pub const DK: u8 = 2;
pub const AK_NSK: u8 = 3;
pub const ASK_NSK: u8 = 4;
pub const DK_AK_NK: u8 = 5;
pub const DK_AK_NK: u8 = 5;

0 comments on commit cb23774

Please sign in to comment.