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

Refactor the code. #1

Closed
wants to merge 36 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ ColumnLimit: 100
PointerAlignment: Right
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: true
AllowAllParametersOfDeclarationOnNextLine: false
SortIncludes: false
SpaceAfterCStyleCast: true
AllowShortCaseLabelsOnASingleLine: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
BinPackArguments: false
Expand Down
13 changes: 12 additions & 1 deletion .clusterfuzzlite/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
FROM ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder-lite:latest AS LITE_BUILDER

# Base image with clang toolchain
FROM gcr.io/oss-fuzz-base/base-builder:v1
RUN apt-get update && apt-get install -y make libssl-dev libbsd-dev

RUN apt-get update && apt-get install -y libbsd-dev

# Copy the project's source code.
COPY . $SRC/app-stellar
COPY --from=LITE_BUILDER /opt/ledger-secure-sdk $SRC/app-stellar/BOLOS_SDK

# Working directory for build.sh
WORKDIR $SRC/app-stellar

# Copy build.sh into $SRC dir.
COPY .clusterfuzzlite/build.sh $SRC/
2 changes: 1 addition & 1 deletion .clusterfuzzlite/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# build fuzzers

pushd fuzz
cmake -DCMAKE_C_COMPILER=clang -Bbuild -H.
cmake -DBOLOS_SDK=../BOLOS_SDK -Bbuild -H.
make -C build
mv ./build/fuzz_tx $OUT/app-stellar-fuzz-tx
popd
2 changes: 1 addition & 1 deletion .clusterfuzzlite/project.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
language: c++
language: c
2 changes: 1 addition & 1 deletion .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

- name: Build unit tests
run: |
make tests-unit
CTEST_OUTPUT_ON_FAILURE=1 make tests-unit

- name: Generate code coverage
run: |
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/swap-ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
workflow_dispatch:
push:
branches:
- master
- develop
- master
- develop
pull_request:

jobs:
Expand All @@ -14,3 +14,4 @@ jobs:
with:
branch_for_stellar: ${{ github.ref }}
test_filter: '"XLM or xlm or Stellar or stellar"'
repo_for_stellar: lightsail-network/app-stellar
264 changes: 109 additions & 155 deletions Makefile
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,169 +1,128 @@
#*******************************************************************************
# Ledger Stellar App
# (c) 2017-2022 Ledger
# ****************************************************************************
# Ledger App Stellar
# (c) 2023 Ledger SAS.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#*******************************************************************************
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ****************************************************************************

ifeq ($(BOLOS_SDK),)
$(error Environment variable BOLOS_SDK is not set)
endif
include $(BOLOS_SDK)/Makefile.defines

APPNAME = Stellar
APPVERSION_M=5
APPVERSION_N=0
APPVERSION_P=3
APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)

ifeq ($(TARGET_NAME), TARGET_NANOS)
APP_LOAD_PARAMS = --appFlags 0x800 # APPLICATION_FLAG_LIBRARY
else
APP_LOAD_PARAMS = --appFlags 0xa00 # APPLICATION_FLAG_LIBRARY + APPLICATION_FLAG_BOLOS_SETTINGS
endif
APP_LOAD_PARAMS += --curve ed25519
APP_LOAD_PARAMS += --path "44'/148'"
APP_LOAD_PARAMS += $(COMMON_LOAD_PARAMS)

#prepare hsm generation
ifeq ($(TARGET_NAME),TARGET_NANOS)
ICONNAME=icons/nanos_app_stellar.gif
else ifeq ($(TARGET_NAME),TARGET_STAX)
ICONNAME=icons/stax_app_stellar.gif
else
ICONNAME=icons/nanox_app_stellar.gif
endif

################
# Default rule #
################
all: default

############
# Platform #
############
ifneq ($(TARGET_NAME),TARGET_STAX)
DEFINES += HAVE_BAGL HAVE_UX_FLOW
endif

DEFINES += OS_IO_SEPROXYHAL
DEFINES += HAVE_SPRINTF
DEFINES += HAVE_IO_USB HAVE_L4_USBLIB IO_USB_MAX_ENDPOINTS=4 IO_HID_EP_LENGTH=64 HAVE_USB_APDU
DEFINES += MAJOR_VERSION=$(APPVERSION_M) MINOR_VERSION=$(APPVERSION_N) PATCH_VERSION=$(APPVERSION_P)

DEFINES += USB_SEGMENT_SIZE=64
DEFINES += BLE_SEGMENT_SIZE=32 #max MTU, min 20
DEFINES += APPVERSION=\"$(APPVERSION)\"

DEFINES += HAVE_WEBUSB WEBUSB_URL_SIZE_B=0 WEBUSB_URL=""

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


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

ifneq ($(NOCONSENT),)
DEFINES += NO_CONSENT
endif
include $(BOLOS_SDK)/Makefile.defines

########################################
# Mandatory configuration #
########################################
# Application name
APPNAME = "Stellar"

# Application version
APPVERSION_M = 5
APPVERSION_N = 2
APPVERSION_P = 0
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/nanos_app_stellar.gif
ICON_NANOX = icons/nanox_app_stellar.gif
ICON_NANOSP = icons/nanox_app_stellar.gif
ICON_STAX = icons/stax_app_stellar.gif
# ICON_FLEX = icons/app_boilerplate_40px.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'/148'"

# 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 = stellar

# Enabling DEBUG flag will enable PRINTF and disable optimizations
DEBUG = 0
ifneq ($(DEBUG),0)
DEFINES += HAVE_PRINTF
ifeq ($(TARGET_NAME),TARGET_NANOS)
DEFINES += PRINTF=screen_printf
else
DEFINES += PRINTF=mcu_usb_printf
endif
else
DEFINES += PRINTF\(...\)=
endif

##############
# Compiler #
##############
ifneq ($(BOLOS_ENV),)
$(info BOLOS_ENV=$(BOLOS_ENV))
CLANGPATH := $(BOLOS_ENV)/clang-arm-fropi/bin/
GCCPATH := $(BOLOS_ENV)/gcc-arm-none-eabi-5_3-2016q1/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)
########################################
# 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
#DISABLE_STANDARD_BAGL_UX_FLOW = 1
#DISABLE_DEBUG_LEDGER_ASSERT = 1
#DISABLE_DEBUG_THROW = 1

ENABLE_SWAP = 1

WITH_LIBSTELLAR=1
ifneq ($(WITH_LIBSTELLAR),0)
SOURCE_FILES += $(wildcard libstellar/*.c)
CFLAGS += -Ilibstellar/include
endif

CC := $(CLANGPATH)clang
AS := $(GCCPATH)arm-none-eabi-gcc
LD := $(GCCPATH)arm-none-eabi-gcc
LDLIBS += -lm -lgcc -lc
include $(BOLOS_SDK)/Makefile.standard_app

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

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

ifneq ($(TARGET_NAME),TARGET_STAX)
SDK_SOURCE_PATH += lib_ux
endif

ifeq ($(TARGET_NAME),TARGET_NANOX)
SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
else ifeq ($(TARGET_NAME),TARGET_STAX)
SDK_SOURCE_PATH += lib_blewbxx lib_blewbxx_impl
ifeq ($(TARGET_NAME), TARGET_NANOS)
APP_FLAGS_APP_LOAD_PARAMS = 0x800 # APPLICATION_FLAG_LIBRARY
else
APP_FLAGS_APP_LOAD_PARAMS = 0xa00 # APPLICATION_FLAG_LIBRARY + APPLICATION_FLAG_BOLOS_SETTINGS
endif


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

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

# import generic rules from the sdk
include $(BOLOS_SDK)/Makefile.rules

#add dependency on custom makefile filename
dep/%.d: %.c Makefile.genericwallet


listvariants:
@echo VARIANTS COIN stellar

tests-unit:
cd tests_common_js && npm install && npm run build
cd tests_generate_binary && npm install && npm run generate unit
Expand All @@ -173,8 +132,3 @@ tests-zemu:
./build_elfs.sh
cd tests_common_js && npm install && npm run build
cd tests_zemu && npm install && rm -rf snapshots-tmp && npm run test

fuzzing:
cd tests_common_js && npm install && npm run build
rm -rf fuzz/testcases && mkdir -p fuzz/testcases && cd tests_generate_binary && npm install && npm run generate fuzz
cd fuzz && rm -rf build && cmake -DCMAKE_C_COMPILER=clang -Bbuild -H. && make -C build && ./build/fuzz_tx testcases
2 changes: 1 addition & 1 deletion build_elfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ make clean

for sdk in "${DEVICE_SDKS[@]}"; do
echo "* Building elfs for $(basename "$sdk")..."
make -j DEBUG=1 BOLOS_SDK="$sdk"
make -j BOLOS_SDK="$sdk"
done

echo "done"
Loading
Loading