Skip to content

Commit 7eeb612

Browse files
authored
Merge pull request #214 from Zondax/app-size-improvements
App size improvements
2 parents ed57040 + 36aa17c commit 7eeb612

25 files changed

Lines changed: 84 additions & 6 deletions

File tree

.github/workflows/main.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ jobs:
7878
shell: bash -l {0}
7979
run: |
8080
make
81+
echo "size=$(python3 deps/ledger-zxlib/scripts/getSize.py s)" >> $GITHUB_OUTPUT
82+
83+
size_nano_s:
84+
needs: build_ledger
85+
runs-on: ubuntu-latest
86+
env:
87+
NANOS_LIMIT_SIZE: 136
88+
steps:
89+
- run: |
90+
echo "LNS app size: ${{needs.build_ledger.outputs.size}} KiB"
91+
[ ${{needs.build_ledger.outputs.size}} -le $NANOS_LIMIT_SIZE ]
92+
8193
build_ledger_val:
8294
needs: configure
8395
runs-on: ubuntu-latest

app/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ endif
7070

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

7574
include $(CURDIR)/../deps/ledger-zxlib/makefiles/Makefile.devices
7675
DEFINES += HAVE_INSPECT

app/Makefile.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
APPVERSION_M=2
22
APPVERSION_N=5
3-
APPVERSION_P=7
3+
APPVERSION_P=8

app/rust/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ log = "0.4.8"
3737
panic-halt = "0.2.0"
3838

3939
[profile.release]
40-
lto=false
40+
lto=true
4141
codegen-units = 1
4242
debug=true
4343
opt-level = "z"
44+
strip = true
4445

4546
[profile.dev]
4647
panic = "abort"

app/rust/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ use schnorrkel::{ExpansionMode, MiniSecretKey, PublicKey, SecretKey};
3535
use zeroize::Zeroize;
3636

3737
use crate::bolos::*;
38+
mod panic_handler;
39+
use panic_handler::PanicHandler;
3840

3941
mod bolos;
4042

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

165167
#[no_mangle]
166168
pub extern "C" fn get_sr25519_sk(sk_ed25519_expanded_ptr: *mut u8) {
167169
let sk_ed25519_expanded = unsafe { from_raw_parts_mut(sk_ed25519_expanded_ptr as *mut u8, 64) };
168-
let secret: SecretKey = SecretKey::from_ed25519_bytes(&sk_ed25519_expanded[..]).unwrap();
170+
let secret: SecretKey =
171+
SecretKey::from_ed25519_bytes(&sk_ed25519_expanded[..]).unwrap_handler();
169172
sk_ed25519_expanded.copy_from_slice(&secret.to_bytes());
170173
}
171174

app/rust/src/panic_handler.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*******************************************************************************
2+
* (c) 2021 Zondax GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
********************************************************************************/
16+
17+
pub trait PanicHandler: Sized {
18+
type Item;
19+
20+
fn unwrap_handler(self) -> Self::Item;
21+
22+
fn unwrap_expect(self, s: &str) -> Self::Item;
23+
}
24+
25+
impl<T, E> PanicHandler for Result<T, E> {
26+
type Item = T;
27+
28+
#[inline]
29+
fn unwrap_handler(self) -> Self::Item {
30+
match self {
31+
Ok(t) => t,
32+
Err(_) => unsafe { core::hint::unreachable_unchecked() },
33+
}
34+
}
35+
36+
#[inline]
37+
fn unwrap_expect(self, _: &str) -> Self::Item {
38+
match self {
39+
Ok(t) => t,
40+
Err(_) => unsafe { core::hint::unreachable_unchecked() },
41+
}
42+
}
43+
}
44+
45+
impl<T> PanicHandler for Option<T> {
46+
type Item = T;
47+
48+
#[inline]
49+
fn unwrap_handler(self) -> Self::Item {
50+
match self {
51+
Some(t) => t,
52+
None => unsafe { core::hint::unreachable_unchecked() },
53+
}
54+
}
55+
56+
#[inline]
57+
fn unwrap_expect(self, _: &str) -> Self::Item {
58+
match self {
59+
Some(t) => t,
60+
None => unsafe { core::hint::unreachable_unchecked() },
61+
}
62+
}
63+
}
3 Bytes
Loading
3 Bytes
Loading
3 Bytes
Loading

0 commit comments

Comments
 (0)