Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile #210

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
291 changes: 144 additions & 147 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,186 +15,183 @@
# limitations under the License.
#*******************************************************************************

APPNAME = "Cardano ADA"
APPVERSION_M = 6
APPVERSION_N = 1
APPVERSION_P = 2
APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"
# based on https://github.com/LedgerHQ/app-boilerplate/blob/master/Makefile

ifeq ($(BOLOS_SDK),)
$(error Environment variable BOLOS_SDK is not set)
endif

include $(BOLOS_SDK)/Makefile.defines

ifeq ($(TARGET_NAME),TARGET_NANOS)
ICONNAME=icon_ada_nanos.gif
else ifeq ($(TARGET_NAME),TARGET_STAX)
ICONNAME=icon_ada_stax.gif
else
ICONNAME=icon_ada_nanox.gif
endif

##############
# Compiler #
##############

# based in part on https://interrupt.memfault.com/blog/best-and-worst-gcc-clang-compiler-flags
WERROR := -Werror=return-type -Werror=parentheses -Werror=format-security

CC := $(CLANGPATH)clang
CFLAGS += -std=gnu99 -Wall -Wextra -Wuninitialized -Wshadow -Wformat=2 -Wwrite-strings -Wundef -fno-common $(WERROR)

AS := $(GCCPATH)arm-none-eabi-gcc
LD := $(GCCPATH)arm-none-eabi-gcc
LDFLAGS += -Wall
LDLIBS += -lm -lgcc -lc


############
# Platform #
############

DEFINES += OS_IO_SEPROXYHAL
ifneq ($(TARGET_NAME),TARGET_STAX)
DEFINES += HAVE_BAGL
endif
DEFINES += HAVE_SPRINTF HAVE_SNPRINTF_FORMAT_U
DEFINES += APPVERSION=\"$(APPVERSION)\"
DEFINES += MAJOR_VERSION=$(APPVERSION_M) MINOR_VERSION=$(APPVERSION_N) PATCH_VERSION=$(APPVERSION_P)

## USB HID?
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=4 IO_HID_EP_LENGTH=64 HAVE_USB_APDU
########################################
# Mandatory configuration #
########################################
# Application name
APPNAME = "Cardano ADA"

## USB U2F
DEFINES += HAVE_U2F HAVE_IO_U2F U2F_PROXY_MAGIC=\"ADA\" USB_SEGMENT_SIZE=64

## WEBUSB
#WEBUSB_URL = https://www.ledger.com/pages/supported-crypto-assets
#DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=$(shell echo -n $(WEBUSB_URL) | wc -c) WEBUSB_URL=$(shell echo -n $(WEBUSB_URL) | sed -e "s/./\\\'\0\\\',/g")
DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL=""

## BLUETOOTH
ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX))
DEFINES += HAVE_BLE BLE_COMMAND_TIMEOUT_MS=2000 HAVE_BLE_APDU
endif

## Protect stack overflows
DEFINES += HAVE_BOLOS_APP_STACK_CANARY
# Application version
APPVERSION_M = 6
APPVERSION_N = 1
APPVERSION_P = 2
APPVERSION = "$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)"

# Application source files
APP_SOURCE_PATH += src

# Application icons following guidelines:
# https://developers.ledger.com/docs/embedded-app/design-requirements/#device-icon
ICON_NANOS = icons/app_ada_16px.gif
ICON_NANOX = icons/app_ada_14px.gif
ICON_NANOSP = icons/app_ada_14px.gif
ICON_STAX = icons/app_ada_32px.gif

# Application allowed derivation curves.
# Possibles curves are: secp256k1, secp256r1, ed25519 and bls12381g1
# If your app needs it, you can specify multiple curves by using:
# `CURVE_APP_LOAD_PARAMS = <curve1> <curve2>`
CURVE_APP_LOAD_PARAMS = ed25519

# Application allowed derivation paths.
# You should request a specific path for your app.
# This serve as an isolation mechanism.
# Most application will have to request a path according to the BIP-0044
# and SLIP-0044 standards.
# If your app needs it, you can specify multiple path by using:
# `PATH_APP_LOAD_PARAMS = "44'/1'" "45'/1'"`
PATH_APP_LOAD_PARAMS = "44'/1815'" "1852'/1815'" "1853'/1815'" "1854'/1815'" "1855'/1815'" "1694'/1815'"

# Setting to allow building variant applications
# - <VARIANT_PARAM> is the name of the parameter which should be set
# to specify the variant that should be build.
# - <VARIANT_VALUES> a list of variant that can be build using this app code.
# * It must at least contains one value.
# * Values can be the app ticker or anything else but should be unique.
VARIANT_PARAM = COIN
VARIANT_VALUES = cardano_ada

# Use developer build for testing (e.g. on Speculos)
#DEVEL = 1

ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128
ifeq ($(DEVEL), 1)
DEFINES += DEVEL
# Automatically confirm all prompts to avoid manually clicking through UI
DEFINES += HEADLESS
# Enabling DEBUG flag will enable PRINTF and disable optimizations
DEBUG = 1
else
DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300
DEFINES += HAVE_GLO096
ifneq ($(TARGET_NAME),TARGET_STAX)
DEFINES += HAVE_BAGL BAGL_WIDTH=128 BAGL_HEIGHT=64
DEFINES += HAVE_UX_FLOW
DEFINES += RESET_ON_CRASH
endif

ifeq ($(TARGET_NAME),TARGET_STAX)
DEFINES += NBGL_QRCODE
SDK_SOURCE_PATH += qrcode
endif
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
endif

DEFINES += RESET_ON_CRASH

## Use developer build
#DEVEL = 1
#DEFINES += HEADLESS

# Enabling debug PRINTF
ifeq ($(DEVEL), 1)
DEFINES += DEVEL HAVE_PRINTF
ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += PRINTF=screen_printf
# restricted features for Nano S
# but not in DEVEL mode where we usually want to test all features with HEADLESS
ifeq ($(TARGET_NAME), TARGET_NANOS)
ifneq ($(DEVEL), 1)
APP_XS = 1
else
DEFINES += PRINTF=mcu_usb_printf
APP_XS = 0
endif
else
DEFINES += PRINTF\(...\)=
APP_XS = 0
endif


##################
# Dependencies #
##################

# import rules to compile glyphs
include $(BOLOS_SDK)/Makefile.glyphs

### computed variables
APP_SOURCE_PATH += src
SDK_SOURCE_PATH += lib_stusb lib_stusb_impl lib_u2f

ifneq ($(TARGET_NAME),TARGET_STAX)
SDK_SOURCE_PATH += lib_ux
ifeq ($(APP_XS), 1)
DEFINES += APP_XS
else
# features not included in the Nano S app
DEFINES += APP_FEATURE_OPCERT
DEFINES += APP_FEATURE_NATIVE_SCRIPT_HASH
DEFINES += APP_FEATURE_POOL_REGISTRATION
DEFINES += APP_FEATURE_POOL_RETIREMENT
DEFINES += APP_FEATURE_BYRON_ADDRESS_DERIVATION
DEFINES += APP_FEATURE_BYRON_PROTOCOL_MAGIC_CHECK
endif

ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_NANOX TARGET_STAX))
SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
# always include this, it's important for Plutus users
DEFINES += APP_FEATURE_TOKEN_MINTING

########################################
# Application custom permissions #
########################################
# See SDK `include/appflags.h` for the purpose of each permission
#HAVE_APPLICATION_FLAG_DERIVE_MASTER = 1
#HAVE_APPLICATION_FLAG_GLOBAL_PIN = 1
HAVE_APPLICATION_FLAG_BOLOS_SETTINGS = 1
#HAVE_APPLICATION_FLAG_LIBRARY = 1

########################################
# Application communication interfaces #
########################################
ENABLE_BLUETOOTH = 1
#ENABLE_NFC = 1

########################################
# NBGL custom features #
########################################
ENABLE_NBGL_QRCODE = 1
#ENABLE_NBGL_KEYBOARD = 1
#ENABLE_NBGL_KEYPAD = 1

########################################
# Features disablers #
########################################
# These advanced settings allow to disable some feature that are by
# default enabled in the SDK `Makefile.standard_app`.
#DISABLE_STANDARD_APP_FILES = 1
#DISABLE_DEFAULT_IO_SEPROXY_BUFFER_SIZE = 1 # To allow custom size declaration
#DISABLE_STANDARD_APP_DEFINES = 1 # Will set all the following disablers
#DISABLE_STANDARD_SNPRINTF = 1
#DISABLE_STANDARD_USB = 1
#DISABLE_STANDARD_WEBUSB = 1

ifeq ($(TARGET_NAME), TARGET_NANOS)
DISABLE_STANDARD_BAGL_UX_FLOW = 1
endif

################
# Default rule #
################
########################################
# Additional configuration #
########################################

all: default


##############
# Build #
##############

listvariants:
@echo VARIANTS COIN cardano_ada

# part of CI
analyze: clean
scan-build --use-cc=clang -analyze-headers -enable-checker security -enable-checker unix -enable-checker valist -o scan-build --status-bugs make default
# USB U2F
DEFINES += HAVE_U2F HAVE_IO_U2F U2F_PROXY_MAGIC=\"ADA\"
SDK_SOURCE_PATH += lib_u2f

##############
# Load #
##############
# Protect against stack overflows
DEFINES += HAVE_BOLOS_APP_STACK_CANARY

NANOS_ID = 1
# mnemonic and PIN for testing on a physical device / Speculos
WORDS = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
PIN = 5555

APP_LOAD_PARAMS =--appFlags 0x200 --curve ed25519 --path "44'/1815'" --path "1852'/1815'" --path "1853'/1815'" --path "1854'/1815'" --path "1855'/1815'" --path "1694'/1815'"
APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS)

load:
python -m ledgerblue.loadApp $(APP_LOAD_PARAMS)
# based in part on https://interrupt.memfault.com/blog/best-and-worst-gcc-clang-compiler-flags
CFLAGS += -Wuninitialized -Wreturn-type -Wparentheses -fno-common

delete:
python -m ledgerblue.deleteApp $(COMMON_DELETE_PARAMS)
########################################
# Additional targets #
########################################

seed:
python -m ledgerblue.hostOnboard --id $(NANOS_ID) --words $(WORDS) --pin $(PIN)
# code style
format:
astyle --options=.astylerc "src/*.h" "src/*.c"

# prints app size, max is about 140K
size: all
$(GCCPATH)arm-none-eabi-size --format=gnu bin/app.elf

##############
# Style #
##############
# device-specific builds
nanos: clean
BOLOS_SDK=$(NANOS_SDK) make

format:
astyle --options=.astylerc "src/*.h" "src/*.c" --exclude=src/glyphs.h --exclude=src/glyphs.c --ignore-exclude-errors
nanosp: clean
BOLOS_SDK=$(NANOSP_SDK) make

nanox: clean
BOLOS_SDK=$(NANOX_SDK) make

##############
# Size #
##############
stax: clean
BOLOS_SDK=$(STAX_SDK) make

# prints app size, max is about 140K
# part of CI
analyze: clean
scan-build --use-cc=clang -analyze-headers -enable-checker security -enable-checker unix -enable-checker valist -o scan-build --status-bugs make default

size: all
$(GCCPATH)arm-none-eabi-size --format=gnu bin/app.elf

# import generic rules from the sdk
include $(BOLOS_SDK)/Makefile.rules
include $(BOLOS_SDK)/Makefile.standard_app
2 changes: 1 addition & 1 deletion doc/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- Install Docker
- Pull the required containers as discussed in https://github.com/LedgerHQ/ledger-app-builder/ (lite container is sufficient for a C build):

`sudo docker pull ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest`
`docker pull ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest`

## Compiling the app

Expand Down
11 changes: 11 additions & 0 deletions doc/features.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Features (not) available on specific Ledger devices

Nano S has a very limited space for storing applications. It is not enough to fit all Cardano features there, so some of them are only available on Nano S+ and other more spacious Ledger devices (e.g. Nano X and Stax).

The features not supported on Nano S, Cardano app version 7 and above:
* pool registration and retirement
* signing of operational certificates
* computation of native script hashes
* details in Byron change outputs (only the address is shown)

Details can be found in [Makefile](../Makefile) and in the code (search for compilation flags beginning with `APP_FEATURE_`).
4 changes: 1 addition & 3 deletions doc/ins_get_public_keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ Concatenation of `pub_key` and `chain_code` representing the extended public key
- Ledger might impose more restrictions, see implementation of `policyForGetExtendedPublicKey` in [src/securityPolicy.c](../src/securityPolicy.c) for details
- calculate extended public key
- respond with extended public key

**TODOs**
- ❓(IOHK): Should we also support BTC app like token validation? (Note: Token validation is to prevent concurrent access to the Ledger by two different host apps which could confuse user into performing wrong actions)
- ❓(IOHK): Should we support permanent app setting where Ledger forces user to acknowledge public key retrieval before sending it to host? (Note: probably not in the first version of the app)
- ❓(IOHK): Should there be an option to show the public key on display? Is it useful in any way? (Note: probably not)
9 changes: 9 additions & 0 deletions fuzzing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ add_compile_definitions(
HAVE_HASH
HAVE_SHA256
HAVE_SHA3

# include all app features, incl. those removed from Nano S
APP_FEATURE_OPCERT
APP_FEATURE_NATIVE_SCRIPT_HASH
APP_FEATURE_POOL_REGISTRATION
APP_FEATURE_POOL_RETIREMENT
APP_FEATURE_BYRON_ADDRESS_DERIVATION
APP_FEATURE_BYRON_PROTOCOL_MAGIC_CHECK
APP_FEATURE_TOKEN_MINTING
)

set(SOURCE
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Loading