Skip to content

Commit

Permalink
Merge pull request #214 from Zondax/app-size-improvements
Browse files Browse the repository at this point in the history
App size improvements
  • Loading branch information
chcmedeiros committed Dec 11, 2023
2 parents ed57040 + 36aa17c commit 7eeb612
Show file tree
Hide file tree
Showing 25 changed files with 84 additions and 6 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ jobs:
shell: bash -l {0}
run: |
make
echo "size=$(python3 deps/ledger-zxlib/scripts/getSize.py s)" >> $GITHUB_OUTPUT
size_nano_s:
needs: build_ledger
runs-on: ubuntu-latest
env:
NANOS_LIMIT_SIZE: 136
steps:
- run: |
echo "LNS app size: ${{needs.build_ledger.outputs.size}} KiB"
[ ${{needs.build_ledger.outputs.size}} -le $NANOS_LIMIT_SIZE ]
build_ledger_val:
needs: configure
runs-on: ubuntu-latest
Expand Down
1 change: 0 additions & 1 deletion app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ endif

APP_LOAD_PARAMS = $(APPCURVE) $(COMMON_LOAD_PARAMS) --path ${APPPATH}
DEFINES += HAVE_PENDING_REVIEW_SCREEN
NANOS_STACK_SIZE := 2392

include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices
DEFINES += HAVE_INSPECT
Expand Down
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
APPVERSION_M=2
APPVERSION_N=5
APPVERSION_P=7
APPVERSION_P=8
3 changes: 2 additions & 1 deletion app/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ log = "0.4.8"
panic-halt = "0.2.0"

[profile.release]
lto=false
lto=true
codegen-units = 1
debug=true
opt-level = "z"
strip = true

[profile.dev]
panic = "abort"
Expand Down
7 changes: 5 additions & 2 deletions app/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ use schnorrkel::{ExpansionMode, MiniSecretKey, PublicKey, SecretKey};
use zeroize::Zeroize;

use crate::bolos::*;
mod panic_handler;
use panic_handler::PanicHandler;

mod bolos;

Expand Down Expand Up @@ -158,14 +160,15 @@ pub extern "C" fn sign_sr25519_phase2(
pub extern "C" fn expanded_sr25519_sk(sk_ed25519_ptr: *mut u8, sk_ed25519_expanded_ptr: *mut u8) {
let sk_ed25519 = unsafe { from_raw_parts_mut(sk_ed25519_ptr as *mut u8, 32) };
let sk_ed25519_expanded = unsafe { from_raw_parts_mut(sk_ed25519_expanded_ptr as *mut u8, 64) };
let secret: MiniSecretKey = MiniSecretKey::from_bytes(&sk_ed25519[..]).unwrap();
let secret: MiniSecretKey = MiniSecretKey::from_bytes(&sk_ed25519[..]).unwrap_handler();
sk_ed25519_expanded.copy_from_slice(&secret.expand(ExpansionMode::Uniform).to_bytes());
}

#[no_mangle]
pub extern "C" fn get_sr25519_sk(sk_ed25519_expanded_ptr: *mut u8) {
let sk_ed25519_expanded = unsafe { from_raw_parts_mut(sk_ed25519_expanded_ptr as *mut u8, 64) };
let secret: SecretKey = SecretKey::from_ed25519_bytes(&sk_ed25519_expanded[..]).unwrap();
let secret: SecretKey =
SecretKey::from_ed25519_bytes(&sk_ed25519_expanded[..]).unwrap_handler();
sk_ed25519_expanded.copy_from_slice(&secret.to_bytes());
}

Expand Down
63 changes: 63 additions & 0 deletions app/rust/src/panic_handler.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* (c) 2021 Zondax GmbH
*
* 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
*
* 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.
********************************************************************************/

pub trait PanicHandler: Sized {
type Item;

fn unwrap_handler(self) -> Self::Item;

fn unwrap_expect(self, s: &str) -> Self::Item;
}

impl<T, E> PanicHandler for Result<T, E> {
type Item = T;

#[inline]
fn unwrap_handler(self) -> Self::Item {
match self {
Ok(t) => t,
Err(_) => unsafe { core::hint::unreachable_unchecked() },
}
}

#[inline]
fn unwrap_expect(self, _: &str) -> Self::Item {
match self {
Ok(t) => t,
Err(_) => unsafe { core::hint::unreachable_unchecked() },
}
}
}

impl<T> PanicHandler for Option<T> {
type Item = T;

#[inline]
fn unwrap_handler(self) -> Self::Item {
match self {
Some(t) => t,
None => unsafe { core::hint::unreachable_unchecked() },
}
}

#[inline]
fn unwrap_expect(self, _: &str) -> Self::Item {
match self {
Some(t) => t,
None => unsafe { core::hint::unreachable_unchecked() },
}
}
}
2 changes: 1 addition & 1 deletion deps/ledger-zxlib
Binary file modified tests_zemu/snapshots/s-adr0008-0-mainmenu/00004.png
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/s-adr0008-0-mainmenu/00010.png
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/s-adr0008-5-mainmenu/00004.png
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/s-adr0008-5-mainmenu/00010.png
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/s-mainmenu/00004.png
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/s-mainmenu/00010.png
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-adr0008-0-mainmenu/00004.png
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-adr0008-0-mainmenu/00010.png
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-adr0008-5-mainmenu/00004.png
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-adr0008-5-mainmenu/00010.png
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-mainmenu/00004.png
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-mainmenu/00010.png
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/x-adr0008-0-mainmenu/00004.png
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/x-adr0008-0-mainmenu/00010.png
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/x-adr0008-5-mainmenu/00004.png
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/x-adr0008-5-mainmenu/00010.png
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/x-mainmenu/00004.png
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/x-mainmenu/00010.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7eeb612

Please sign in to comment.