Skip to content

Commit

Permalink
Fixes (#13)
Browse files Browse the repository at this point in the history
* fix overwrite issue

* update tests and snapshots

* add extra condition for signing

* reset indice context offset

* allow output dummy notes

* remove this check as it can happens in different sessions

* return payment address

* update rs lib

* update tests

* update deps

* update snapshots

* print self for change address

* update js

* update rs lib

* update snapshots

* size fixes

* improve cargo

* improve cargo for cpp_test feature

* small fixes
  • Loading branch information
chcmedeiros authored Dec 23, 2024
1 parent 99bfb87 commit c02740d
Show file tree
Hide file tree
Showing 65 changed files with 214 additions and 81 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,15 @@ else()
endif()

# Use debug mode for debugging tests
set(RUST_TARGET_DIR "${RUST_LIB_DIR}/target/${RUST_TARGET_TRIPLE}/debug")
set(RUST_TARGET_DIR "${RUST_LIB_DIR}/target/${RUST_TARGET_TRIPLE}/release")

# Custom target for the Rust library
add_custom_target(RustLibClean
COMMAND cargo clean
WORKING_DIRECTORY ${RUST_LIB_DIR}
)
add_custom_target(RustLibBuild
COMMAND cargo build --target ${RUST_TARGET_TRIPLE} --features cpp_tests
COMMAND cargo build --release --target ${RUST_TARGET_TRIPLE} --features cpp_tests
WORKING_DIRECTORY ${RUST_LIB_DIR}
DEPENDS RustLibClean
)
Expand Down
11 changes: 11 additions & 0 deletions app/rust/.cargo/config
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ rustflags = [
"-C", "relocation-model=ropi",
"-C", "link-arg=-nostartfiles",
"-C", "link-arg=-Tlink.ld",
"-C", "panic=abort",
]
[unstable]
build-std=["core"]
build-std-features=["panic_immediate_abort"]

[target.'cfg(target_os = "linux")']
rustflags = [
"-C",
"link-arg=-Wl,--gc-sections",
"-C",
"link-arg=-Wl,--as-needed",
"-C",
"panic=abort", # Add this line to disable unwinding
]
14 changes: 11 additions & 3 deletions app/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,28 @@ log = "0.4"
panic-halt = "0.2.0"

[profile.release]
lto = false
codegen-units = 1
debug = false
opt-level = "z"
panic = "abort"
# lto = false
# Settings below aimed to reduce
# binary size due to code
lto = "fat"
overflow-checks = false
strip = "symbols"

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

[features]
default = []
clippy = []
fuzzing = []
# use when compiling this crate as a lib for the cpp_tests suite
cpp_tests = []
60 changes: 48 additions & 12 deletions app/rust/src/bolos/blake2b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ use crate::personalization::{
use blake2b_simd::Params as Blake2bParams;
use blake2s_simd::Params as Blake2sParams;

#[cfg(all(
not(test),
not(feature = "clippy"),
not(feature = "fuzzing"),
not(feature = "cpp_tests")
))]
extern "C" {
fn c_zcash_blake2b_expand_seed(
input_a: *const u8,
Expand Down Expand Up @@ -45,7 +51,7 @@ extern "C" {
fn c_zcash_blake2b_redjubjub(a: *const u8, a_len: u32, b: *const u8, b_len: u32, out: *mut u8);
}

#[cfg(test)]
#[cfg(any(test, feature = "clippy", feature = "fuzzing", feature = "cpp_tests"))]
pub fn blake2b32_with_personalization(person: &[u8; 16], data: &[u8]) -> [u8; 32] {
let h = Blake2bParams::new()
.hash_length(32)
Expand All @@ -56,7 +62,12 @@ pub fn blake2b32_with_personalization(person: &[u8; 16], data: &[u8]) -> [u8; 32
hash
}

#[cfg(not(test))]
#[cfg(all(
not(test),
not(feature = "clippy"),
not(feature = "fuzzing"),
not(feature = "cpp_tests")
))]
pub fn blake2b32_with_personalization(person: &[u8; 16], data: &[u8]) -> [u8; 32] {
let mut hash = [0; 32];
unsafe {
Expand All @@ -70,7 +81,7 @@ pub fn blake2b32_with_personalization(person: &[u8; 16], data: &[u8]) -> [u8; 32
hash
}

#[cfg(test)]
#[cfg(any(test, feature = "clippy", feature = "fuzzing", feature = "cpp_tests"))]
pub fn blake2b64_with_personalization(person: &[u8; 16], data: &[u8]) -> [u8; 64] {
let h = Blake2bParams::new()
.hash_length(64)
Expand All @@ -81,7 +92,12 @@ pub fn blake2b64_with_personalization(person: &[u8; 16], data: &[u8]) -> [u8; 64
hash
}

#[cfg(not(test))]
#[cfg(all(
not(test),
not(feature = "clippy"),
not(feature = "fuzzing"),
not(feature = "cpp_tests")
))]
pub fn blake2b64_with_personalization(person: &[u8; 16], data: &[u8]) -> [u8; 64] {
let mut hash = [0; 64];
unsafe {
Expand All @@ -95,7 +111,7 @@ pub fn blake2b64_with_personalization(person: &[u8; 16], data: &[u8]) -> [u8; 64
hash
}

#[cfg(test)]
#[cfg(any(test, feature = "clippy", feature = "fuzzing", feature = "cpp_tests"))]
pub fn blake2b_redjubjub(a: &[u8], b: &[u8]) -> [u8; 64] {
let h = Blake2bParams::new()
.hash_length(64)
Expand All @@ -109,7 +125,12 @@ pub fn blake2b_redjubjub(a: &[u8], b: &[u8]) -> [u8; 64] {
result
}

#[cfg(not(test))]
#[cfg(all(
not(test),
not(feature = "clippy"),
not(feature = "fuzzing"),
not(feature = "cpp_tests")
))]
pub fn blake2b_redjubjub(a: &[u8], b: &[u8]) -> [u8; 64] {
let mut hash = [0; 64];
unsafe {
Expand All @@ -124,7 +145,12 @@ pub fn blake2b_redjubjub(a: &[u8], b: &[u8]) -> [u8; 64] {
hash
}

#[cfg(not(test))]
#[cfg(all(
not(test),
not(feature = "clippy"),
not(feature = "fuzzing"),
not(feature = "cpp_tests")
))]
pub fn blake2b_expand_seed(a: &[u8], b: &[u8]) -> [u8; 64] {
let mut hash = [0; 64];
unsafe {
Expand All @@ -139,7 +165,12 @@ pub fn blake2b_expand_seed(a: &[u8], b: &[u8]) -> [u8; 64] {
hash
}

#[cfg(not(test))]
#[cfg(all(
not(test),
not(feature = "clippy"),
not(feature = "fuzzing"),
not(feature = "cpp_tests")
))]
pub fn blake2b_expand_vec_two(in_a: &[u8], in_b: &[u8], in_c: &[u8]) -> [u8; 64] {
let mut hash = [0; 64];
unsafe {
Expand All @@ -156,7 +187,12 @@ pub fn blake2b_expand_vec_two(in_a: &[u8], in_b: &[u8], in_c: &[u8]) -> [u8; 64]
hash
}

#[cfg(not(test))]
#[cfg(all(
not(test),
not(feature = "clippy"),
not(feature = "fuzzing"),
not(feature = "cpp_tests")
))]
pub fn blake2b_expand_v4(
in_a: &[u8],
in_b: &[u8],
Expand All @@ -183,7 +219,7 @@ pub fn blake2b_expand_v4(
hash
}

#[cfg(test)]
#[cfg(any(test, feature = "clippy", feature = "fuzzing", feature = "cpp_tests"))]
pub fn blake2b_expand_seed(a: &[u8], b: &[u8]) -> [u8; 64] {
let h = Blake2bParams::new()
.hash_length(64)
Expand Down Expand Up @@ -214,7 +250,7 @@ pub fn blake2s_diversification(tag: &[u8]) -> [u8; 32] {
result
}

#[cfg(test)]
#[cfg(any(test, feature = "clippy", feature = "fuzzing", feature = "cpp_tests"))]
pub fn blake2b_expand_vec_two(sk: &[u8], a: &[u8], b: &[u8]) -> [u8; 64] {
let mut h = Blake2bParams::new()
.hash_length(64)
Expand All @@ -228,7 +264,7 @@ pub fn blake2b_expand_vec_two(sk: &[u8], a: &[u8], b: &[u8]) -> [u8; 64] {
hash
}

#[cfg(test)]
#[cfg(any(test, feature = "clippy", feature = "fuzzing", feature = "cpp_tests"))]
pub fn blake2b_expand_v4(
in_a: &[u8],
in_b: &[u8],
Expand Down
9 changes: 7 additions & 2 deletions app/rust/src/bolos/canary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ extern "C" {
fn check_app_canary();
}

#[cfg(not(test))]
#[cfg(all(
not(test),
not(feature = "clippy"),
not(feature = "fuzzing"),
not(feature = "cpp_tests")
))]
pub fn c_check_app_canary() {
unsafe { check_app_canary() }
}

#[cfg(test)]
#[cfg(any(test, feature = "clippy", feature = "fuzzing", feature = "cpp_tests"))]
pub fn c_check_app_canary() {}
14 changes: 12 additions & 2 deletions app/rust/src/bolos/heartbeat.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
#[cfg(not(test))]
#[cfg(all(
not(test),
not(feature = "clippy"),
not(feature = "fuzzing"),
not(feature = "cpp_tests")
))]
extern "C" {
fn io_heartbeat();
}

// Lets the device breath between computations
pub(crate) fn heartbeat() {
#[cfg(not(test))]
#[cfg(all(
not(test),
not(feature = "clippy"),
not(feature = "fuzzing"),
not(feature = "cpp_tests")
))]
unsafe {
io_heartbeat()
}
Expand Down
3 changes: 2 additions & 1 deletion app/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#![no_builtins]
#![allow(dead_code, unused_imports)]

#[cfg(all(not(test), not(feature = "clippy"), not(feature = "fuzzing"),))]
use core::panic::PanicInfo;

use constants::{DIV_DEFAULT_LIST_LEN, DIV_SIZE, GH_FIRST_BLOCK, SPENDING_KEY_GENERATOR};
Expand Down Expand Up @@ -187,7 +188,7 @@ pub extern "C" fn add_points(
ParserError::ParserOk
}

#[cfg(not(test))]
#[cfg(all(not(test), not(feature = "clippy"), not(feature = "fuzzing"),))]
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
Expand Down
Loading

0 comments on commit c02740d

Please sign in to comment.