Skip to content

Commit 843c748

Browse files
authored
Fix/bls (#257)
* Fix PIC issue on flex/stax * Add new line at the end of each page * Remove any inner ascii-control character or new line * Testing commit that later must be undonegit add app/rust/src/parser/consent_message/msg.rs tests_zemu/try.mjsgit add app/rust/src/parser/consent_message/msg.rs tests_zemu/try.mjsgst * Add display impl for HashTree type * Add pic function * Add Display impl for HashTree and use pic to adjust Decoder::new function * Fix clippy and add display impl for LineDisplayIterator * Remove logging * Update try script * Enable Bls test and its snappshots * Bump version and update snapshots * Remove conversion recursion and enhance conditional compilation of pic pointers * Add cfg-if dep and update insta snappshots * Fix more clippy warnings * Update zxlib * Try with cargo test directly * Fix clippy warnings * Revert concurrent testing due to bottelneck and disable pb test for add/remove keys * Remove duplicated line * Remove thread builder in test and make rustflags simple to avoid weird issues when compiling the app that was causing pic * Update snapshots * Silence warnings for custom cfg comming from ledger-rust dependencies * Optimize iterator * Do not remove inner ascii control and null terminators * Error if generic display message is received and ensure new line is added * Uppdate rust test and snapshots insta * Update zemu test and snapshots
1 parent c065697 commit 843c748

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+922
-260
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ jobs:
8989
restore-keys: |
9090
${{ runner.os }}-${{ github.sha }}
9191
- name: run rust tests
92-
run: make rust_test
92+
run: cd ./app/rust
93+
cargo test
9394

9495
size_nano_s:
9596
needs: build_ledger

app/Makefile.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ APPVERSION_M=3
33
# This is the minor version of this release
44
APPVERSION_N=2
55
# This is the patch version of this release
6-
APPVERSION_P=2
6+
APPVERSION_P=3

app/rust/.cargo/config.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ target-applies-to-host = true
66
host-config = true
77

88
[host]
9-
rustflags = ["-Ctarget-feature=-crt-static"]
9+
rustflags = ["-Ctarget-feature=-crt-static", "-Aunexpected_cfgs"]
1010

1111
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
1212
rustflags = [
@@ -18,6 +18,5 @@ rustflags = [
1818
"link-arg=-nostartfiles",
1919
"-C",
2020
"link-arg=-Tlink.ld",
21-
"-C",
22-
"inline-threshold=0",
21+
"-Aunexpected_cfgs",
2322
]

app/rust/Cargo.lock

Lines changed: 52 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/rust/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ arrayref = { version = "0.3.7", default-features = false }
1919
nom = { version = "7.1.3", default-features = false }
2020
bolos = { path = "../../deps/ledger-rust/bolos" }
2121
zemu-sys = { path = "../../deps/ledger-rust/zemu" }
22+
cfg-if = "1.0.0"
2223

2324
[dev-dependencies]
2425
no-std-compat = { version = "0.4.1", features = ["std"] }
@@ -36,17 +37,15 @@ serde = { version = "1.0.215", features = ["derive"] }
3637
no-std-compat = { version = "0.4.1", features = ["std"] }
3738

3839
[profile.release]
40+
lto = false
3941
codegen-units = 1
4042
debug = false
4143
opt-level = "z"
42-
lto = "thin"
43-
overflow-checks = false
44-
strip = "symbols"
45-
panic = "abort"
4644

4745
[profile.dev]
4846
panic = "abort"
4947

5048
[features]
5149
clippy = []
5250
derive-debug = []
51+
fuzzing = ["derive-debug"]

app/rust/src/ffi/ui.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use super::resources::UI;
2020

2121
#[no_mangle]
2222
pub unsafe extern "C" fn rs_getNumItems(num_items: *mut u8) -> u32 {
23-
crate::zlog("rs_getNumItems\x00");
2423
if num_items.is_null() || !UI.is_some() {
2524
return ParserError::ContextMismatch as u32;
2625
}
@@ -29,7 +28,6 @@ pub unsafe extern "C" fn rs_getNumItems(num_items: *mut u8) -> u32 {
2928
let ui = UI.as_ref().unwrap();
3029

3130
let Ok(num) = ui.num_items() else {
32-
crate::zlog("no_DATA\x00");
3331
return ParserError::NoData as _;
3432
};
3533

@@ -48,11 +46,8 @@ pub unsafe extern "C" fn rs_getItem(
4846
page_idx: u8,
4947
page_count: *mut u8,
5048
) -> u32 {
51-
crate::zlog("rs_getItem\x00");
5249
*page_count = 0u8;
5350

54-
let page_count = &mut *page_count;
55-
5651
let key = core::slice::from_raw_parts_mut(out_key as *mut u8, key_len as usize);
5752
let value = core::slice::from_raw_parts_mut(out_value as *mut u8, out_len as usize);
5853

app/rust/src/ffi/verify_certificate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub unsafe extern "C" fn rs_verify_certificate(
111111
else {
112112
return ParserError::InvalidCertificate as u32;
113113
};
114-
//
114+
115115
// Verify ingress_expiry aginst certificate timestamp
116116
if !cert.verify_time(call_request.ingress_expiry) {
117117
return ParserError::InvalidCertificate as u32;

app/rust/src/lib.rs

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
#![macro_use]
44
#![allow(dead_code)]
55
#![deny(unused_crate_dependencies)]
6+
// We used different config flags names
7+
// in order to not possibly colide with other
8+
// defined in dependencies
9+
#![allow(unexpected_cfgs)]
10+
#![allow(static_mut_refs)]
611

712
extern crate no_std_compat as std;
813

@@ -35,12 +40,15 @@ fn panic(_info: &PanicInfo) -> ! {
3540
}
3641

3742
pub fn zlog(_msg: &str) {
38-
#[cfg(all(not(test), not(feature = "clippy"), not(feature = "fuzzing")))]
39-
unsafe {
40-
zemu_log_stack(_msg.as_bytes().as_ptr());
43+
cfg_if::cfg_if! {
44+
if #[cfg(all(not(test), not(feature = "clippy"), not(feature = "fuzzing")))] {
45+
unsafe {
46+
zemu_log_stack(_msg.as_bytes().as_ptr());
47+
}
48+
} else {
49+
std::println!("{}", _msg);
50+
}
4151
}
42-
#[cfg(test)]
43-
std::println!("{}", _msg);
4452
}
4553

4654
pub fn check_canary() {
@@ -59,6 +67,7 @@ extern "C" {
5967
#[cfg(all(not(test), not(feature = "clippy"), not(feature = "fuzzing")))]
6068
extern "C" {
6169
fn io_heartbeat();
70+
fn pic(link_address: u32) -> u32;
6271
}
6372

6473
// Lets the device breath between computations
@@ -71,10 +80,25 @@ pub(crate) fn heartbeat() {
7180

7281
// Lets the device breath between computations
7382
pub(crate) fn log_num(s: &str, number: u32) {
74-
#[cfg(all(not(test), not(feature = "clippy"), not(feature = "fuzzing")))]
75-
unsafe {
76-
log_number(s.as_bytes().as_ptr(), number);
83+
cfg_if::cfg_if! {
84+
if #[cfg(all(not(test), not(feature = "clippy"), not(feature = "fuzzing")))] {
85+
unsafe {
86+
log_number(s.as_bytes().as_ptr(), number);
87+
}
88+
} else {
89+
std::println!("{s}: {number}");
90+
}
91+
}
92+
}
93+
94+
pub fn pic_addr(addr: u32) -> u32 {
95+
cfg_if::cfg_if! {
96+
if #[cfg(all(not(test), not(feature = "clippy"), not(feature = "fuzzing")))] {
97+
unsafe {
98+
pic(addr)
99+
}
100+
} else {
101+
addr
102+
}
77103
}
78-
#[cfg(test)]
79-
std::println!("{s}: {number}");
80104
}

app/rust/src/parser/call_request/arg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl<'a> FromBytes<'a> for RawArg<'a> {
2727
}
2828
}
2929

30-
impl<'a> RawArg<'a> {
30+
impl RawArg<'_> {
3131
pub fn raw_data(&self) -> &[u8] {
3232
self.0
3333
}

app/rust/src/parser/call_request/canister_call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct CanisterCall<'a> {
2424
pub ingress_expiry: u64,
2525
}
2626

27-
impl<'a> CanisterCall<'a> {
27+
impl CanisterCall<'_> {
2828
// this sums up the nonce although
2929
// it could be missing
3030
//

0 commit comments

Comments
 (0)