Skip to content

Commit

Permalink
Merge pull request #83 from Zondax/dev
Browse files Browse the repository at this point in the history
New Release
  • Loading branch information
emmanuelm41 authored Oct 31, 2024
2 parents ebf0adf + db755cd commit 68e23c5
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 48 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/reusable_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Build through reusable workflow

# This workflow is mandatory in all applications
# https://developers.ledger.com/docs/device-app/integration/requirements/development#workflows
#
# More information on the guidelines can be found in the repository:
# LedgerHQ/ledger-app-workflows/

on:
workflow_dispatch:
push:
branches:
- master
- main
- develop
- dev # for safety reasons
pull_request:

jobs:
build_application:
name: Build application using the reusable workflow
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_build.yml@v1
with:
builder: "ledger-app-builder"
31 changes: 29 additions & 2 deletions app/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
[env]
HEAP_SIZE = "16300"
HEAP_SIZE = "16384"
APPVERSION = "0.6.0"

[unstable]
build-std = ["core", "alloc"]
build-std-features = ["compiler-builtins-mem"]
build-std-features = ["compiler-builtins-mem"]


# The opt-level is set based on the device model because stack and binary size. While flex and stax has
# 44K of SRAM, Nanos2 and NanoX have 40K. That difference makes necessary an opt-level s for nano x and nano s2,
# because stack size is not enough otherwise.
# In the other hand, stax and flex should use z. They have more stack, but the app won't fit otherwise. The screen libs
# are heavier, and the app with clear signing won't fit.

# Opt-leve z optimize the size more, making the app less performant (consumes more stack)
# Opt-leve s optimize the size, but not that much, making the app a bit more performant (consumes less stack)

# From testing on Nano S2...
# heap 15k, opt-level=z -> 3 participants fail on signing because of heap fragmentation, app size XXX
# heap 16.3k, opt-level=s -> 3 participants work, app size 680K

[target.nanox]
rustflags = ["-C", "opt-level=s"]

[target.nanosplus]
rustflags = ["-C", "opt-level=s"]

[target.stax]
rustflags = ["-C", "opt-level=z"]

[target.flex]
rustflags = ["-C", "opt-level=z"]
8 changes: 4 additions & 4 deletions app/Cargo.lock

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

16 changes: 2 additions & 14 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ test = false
path = "bin-app/app.rs"

[dependencies]
# ledger_device_sdk = { git = "https://github.com/Zondax/ledger-device-rust-sdk", rev = "0f07d2b2afae6e9b194573e84f99f68f8755084e", optional = true }
ledger_device_sdk = { version = "1.17.3", optional = true }
#ledger_device_sdk = { git = "https://github.com/Zondax/ledger-device-rust-sdk", rev = "22b479a6227dc4193a7042d1daaee02af8de95c5", optional = true }
ledger_device_sdk = { version = "1.18.2", optional = true }
#ledger_device_sdk = { path="../ledger-device-rust-sdk/ledger_device_sdk" , optional = true}
include_gif = "1.2.0"
serde = { version = "1.0.192", default_features = false, features = ["derive"] }
Expand Down Expand Up @@ -56,18 +56,6 @@ serde_json = "1.0.85"
[profile.release]
lto = true

# The opt-level is set based on the device model because stack and binary size. While flex and stax has
# 44K of SRAM, Nanos2 and NanoX have 40K. That difference makes necessary an opt-level s for nano x and nano s2,
# because stack size is not enough otherwise.
# In the other hand, stax and flex should use z. They have more stack, but the app won't fit otherwise. The screen libs
# are heavier, and the app with clear signing won't fit.

# Opt-leve z optimize the size more, making the app less performant (consumes more stack)
# Opt-leve s optimize the size, but not that much, making the app a bit more performant (consumes less stack)

# From testing on Nano S2...
# heap 15k, opt-level=z -> 3 participants fail on signing because of heap fragmentation, app size XXX
# heap 16.3k, opt-level=s -> 3 participants work, app size 680K

[features]
default = ["ledger"]
Expand Down
18 changes: 7 additions & 11 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ ifndef COIN
COIN=IRON_DKG
endif

include $(CURDIR)/Makefile.version

$(info COIN = [$(COIN)])

ifeq ($(COIN),IRON_DKG)
Expand All @@ -66,10 +64,7 @@ endif

$(info PATHS LIST = $(APPPATH))

APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)
APPVERSION_STR=v$(APPVERSION)

APP_LOAD_PARAMS = --curve ed25519 --appName $(APPNAME) --appVersion $(APPVERSION)
APP_LOAD_PARAMS = --curve ed25519 --appName $(APPNAME)
APP_DELETE_PARAMS = --appName $(APPNAME)

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices
Expand All @@ -88,23 +83,23 @@ include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.side_loading

.PHONY: buildX
buildX:
BOLOS_SDK= APPVERSION_STR=$(APPVERSION_STR) PRODUCTION_BUILD=$(PRODUCTION_BUILD) RUSTFLAGS="-C opt-level=s" cargo ledger build nanox
BOLOS_SDK= PRODUCTION_BUILD=$(PRODUCTION_BUILD) cargo ledger build nanox
FOLDER=nanox make post-build

.PHONY: buildS2
buildS2:
BOLOS_SDK= APPVERSION_STR=$(APPVERSION_STR) PRODUCTION_BUILD=$(PRODUCTION_BUILD) RUSTFLAGS="-C opt-level=s" cargo ledger build nanosplus
BOLOS_SDK= PRODUCTION_BUILD=$(PRODUCTION_BUILD) cargo ledger build nanosplus
FOLDER=nanosplus make post-build

.PHONY: buildST
buildST:
BOLOS_SDK= APPVERSION_STR=$(APPVERSION_STR) PRODUCTION_BUILD=$(PRODUCTION_BUILD) RUSTFLAGS="-C opt-level=z" cargo ledger build stax
BOLOS_SDK= PRODUCTION_BUILD=$(PRODUCTION_BUILD) cargo ledger build stax
FOLDER=stax make post-build


.PHONY: buildFL
buildFL:
BOLOS_SDK= APPVERSION_STR=$(APPVERSION_STR) PRODUCTION_BUILD=$(PRODUCTION_BUILD) RUSTFLAGS="-C opt-level=z" cargo ledger build flex
BOLOS_SDK= PRODUCTION_BUILD=$(PRODUCTION_BUILD) cargo ledger build flex
FOLDER=flex make post-build


Expand Down Expand Up @@ -180,8 +175,9 @@ read-params-from-json:
$(eval T_ID := $(shell jq -r '.targetId' target/$(FOLDER)/release/app_$(FOLDER).json))
$(eval DATA_SIZE := $(shell jq -r '.dataSize' target/$(FOLDER)/release/app_$(FOLDER).json))
$(eval API_LEVEL := $(shell jq -r '.apiLevel' target/$(FOLDER)/release/app_$(FOLDER).json))
$(eval APPVERSION := $(shell sed -n 's/^APPVERSION = "\(.*\)"/\1/p' .cargo/config.toml))

$(eval APP_LOAD_PARAMS := $(APP_LOAD_PARAMS) --targetId $(T_ID) --dataSize $(DATA_SIZE) --apiLevel $(API_LEVEL))
$(eval APP_LOAD_PARAMS := $(APP_LOAD_PARAMS) --appVersion $(APPVERSION) --targetId $(T_ID) --dataSize $(DATA_SIZE) --apiLevel $(API_LEVEL))
$(eval APP_DELETE_PARAMS := $(APP_DELETE_PARAMS) --targetId $(T_ID))


Expand Down
6 changes: 0 additions & 6 deletions app/Makefile.version

This file was deleted.

16 changes: 11 additions & 5 deletions app/src/app_ui/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/

use alloc::string::String;
use include_gif::include_gif;
use ledger_device_sdk::io::{Comm, Event};

Expand All @@ -36,7 +36,10 @@ pub fn ui_menu_main(comm: &mut Comm) -> Event<Instruction> {
let mut _first_page_label: [&str; 2];

let production_build = option_env!("PRODUCTION_BUILD").unwrap_or("1");
let app_version = option_env!("APPVERSION_STR").unwrap_or("v0.0.0");

let app_version_value = option_env!("APPVERSION").unwrap_or("0.0.0");
let mut app_version = String::from("v");
app_version.push_str(app_version_value);

if production_build == "0" {
_first_page_label = ["Ironfish DKG DEMO", "DO NOT USE"];
Expand All @@ -46,7 +49,7 @@ pub fn ui_menu_main(comm: &mut Comm) -> Event<Instruction> {

let pages = [
&Page::from((_first_page_label, &APP_ICON)),
&Page::from((["Ironfish DKG", app_version], true, true)),
&Page::from((["Ironfish DKG", app_version.as_str()], true, true)),
&Page::from((["Developed by", "Zondax.ch"], true, true)),
&Page::from((["License", "Apache 2.0"], true, true)),
&Page::from(("Quit", &DASHBOARD)),
Expand All @@ -71,7 +74,10 @@ pub fn ui_menu_main(_: &mut Comm) -> Event<Instruction> {
const FERRIS: NbglGlyph = NbglGlyph::from_include(include_gif!("flex_icon.gif", NBGL));

let production_build = option_env!("PRODUCTION_BUILD").unwrap_or("1");
let app_version = option_env!("APPVERSION_STR").unwrap_or("v0.0.0");

let app_version_value = option_env!("APPVERSION").unwrap_or("0.0.0");
let mut app_version = String::from("v");
app_version.push_str(app_version_value);

let name: &str = if production_build == "0" {
"Ironfish DKG DEMO"
Expand All @@ -82,6 +88,6 @@ pub fn ui_menu_main(_: &mut Comm) -> Event<Instruction> {
// Display the home screen.
NbglHomeAndSettings::new()
.glyph(&FERRIS)
.infos(name, app_version, "Zondax AG")
.infos(name, app_version.as_str(), "Zondax AG")
.show()
}
4 changes: 2 additions & 2 deletions app/src/handlers/get_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const BOLOS_UX_CONTINUE: u32 = 0x00;

#[inline(never)]
pub fn handler_get_version(comm: &mut io::Comm) -> Result<(), AppSW> {
let v = option_env!("APPVERSION_STR").unwrap_or("v0.0.0");
let v = option_env!("APPVERSION").unwrap_or("0.0.0");
if let Some((major, minor, patch)) = parse_version_string(v) {
let mut resp: [u8; 8] = [0u8; 8];

Expand Down Expand Up @@ -59,7 +59,7 @@ fn parse_version_string(input: &str) -> Option<(u16, u16, u16)> {
// Input should be of the form "major.minor.patch",
// where "major", "minor", and "patch" are integers.

let mut parts = input[1..].split('.');
let mut parts = input[0..].split('.');
let major = u16::from_str(parts.next()?).ok()?;
let minor = u16::from_str(parts.next()?).ok()?;
let patch = u16::from_str(parts.next()?).ok()?;
Expand Down
2 changes: 1 addition & 1 deletion app/src/nvm/dkg_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ledger_device_sdk::NVMData;

// This is necessary to store the object in NVM and not in RAM
// The max data saved here is for 4 participants, which sends 1024 bytes.
pub const DKG_KEYS_MAX_SIZE: usize = 1500;
pub const DKG_KEYS_MAX_SIZE: usize = 3000;

// Fix positions with u8 values
const DKG_STATUS: usize = 0;
Expand Down
2 changes: 1 addition & 1 deletion deps/ledger-zxlib
Binary file modified tests_zemu/snapshots/sp-dkg-1-identity/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests_zemu/snapshots/sp-dkg-1-identity/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions tests_zemu/tests/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ describe('Basic', function () {

expect(resp.testMode).toBe(false)
expect(resp.major).toBe(0)
expect(resp.minor).toBe(5)
expect(resp.patch).toBe(4)
expect(resp.minor).toBe(6)
expect(resp.patch).toBe(0)
} finally {
await sim.close()
}
Expand Down

0 comments on commit 68e23c5

Please sign in to comment.