Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Makefile.version
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ APPVERSION_M=1
# Minor
APPVERSION_N=2
# Patch
APPVERSION_P=3
APPVERSION_P=4
8 changes: 6 additions & 2 deletions app/rust/src/ffi/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl TryFrom<u8> for Instruction {
}
}

#[allow(static_mut_refs)]
#[no_mangle]
pub unsafe extern "C" fn _set_root_path(raw_path: *const u8, path_len_bytes: u16) -> u32 {
let path = core::slice::from_raw_parts(raw_path, path_len_bytes as usize);
Expand All @@ -111,10 +112,12 @@ pub unsafe extern "C" fn _set_root_path(raw_path: *const u8, path_len_bytes: u16
}

// important to use avax::signing::Sign
PATH.lock(Sign).replace(root_path);
let path_lock = PATH.lock(Sign);
*path_lock = Some(root_path);
ParserError::ParserOk as u32
}

#[allow(static_mut_refs)]
#[no_mangle]
pub unsafe extern "C" fn _set_tx_hash(hash: *const u8, hash_len_bytes: u16) -> u16 {
if hash_len_bytes != Sign::SIGN_HASH_SIZE as u16 {
Expand All @@ -127,7 +130,8 @@ pub unsafe extern "C" fn _set_tx_hash(hash: *const u8, hash_len_bytes: u16) -> u

// In this step the transaction has not been signed
// so store the hash for the next steps
HASH.lock(Sign).replace(hash);
let hash_lock = HASH.lock(Sign);
*hash_lock = Some(hash);

// next step requires SignHash handler to have
// access to the path and hash resources that this handler just updated
Expand Down
13 changes: 8 additions & 5 deletions app/rust/src/ffi/eth_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
use super::context::{parser_context_t, Instruction};

#[inline(never)]
#[allow(static_mut_refs)]
pub unsafe fn num_items_eth(ctx: *const parser_context_t, num_items: &mut u8) -> u32 {
let Ok(tx_type) = Instruction::try_from((*ctx).ins) else {
return ParserError::InvalidTransactionType as u32;
Expand All @@ -18,7 +19,8 @@ pub unsafe fn num_items_eth(ctx: *const parser_context_t, num_items: &mut u8) ->
return ParserError::InvalidTransactionType as u32;
}

if let Some(obj) = ETH_UI.lock(EthAccessors::Tx) {
let ui_lock = ETH_UI.lock(EthAccessors::Tx);
if let Some(obj) = ui_lock {
match obj.num_items() {
Ok(n) => {
*num_items = n;
Expand All @@ -32,6 +34,7 @@ pub unsafe fn num_items_eth(ctx: *const parser_context_t, num_items: &mut u8) ->
}

#[inline(never)]
#[allow(static_mut_refs)]
pub unsafe fn get_eth_item(
ctx: *const parser_context_t,
display_idx: u8,
Expand Down Expand Up @@ -70,21 +73,21 @@ pub unsafe fn get_eth_item(
}

#[no_mangle]
#[allow(static_mut_refs)]
unsafe extern "C" fn _accept_eth_tx(tx: *mut u16, buffer: *mut u8, buffer_len: u32) -> u16 {
if tx.is_null() || buffer.is_null() || buffer_len == 0 {
return ApduError::DataInvalid as u16;
}

let data = std::slice::from_raw_parts_mut(buffer, buffer_len as usize);

let code = if let Some(obj) = ETH_UI.lock(EthAccessors::Tx) {
let ui_lock = ETH_UI.lock(EthAccessors::Tx);
if let Some(obj) = ui_lock {
let (_tx, code) = obj.accept(data);
*tx = _tx as u16;
code
} else {
// No ethereum transaction has been processed yet
ApduError::DataInvalid as u16
};

code
}
}
1 change: 1 addition & 0 deletions app/rust/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub mod eth;
mod utils;
pub use utils::*;

#[allow(static_mut_refs)]
pub mod resources {
use crate::constants::MAX_BIP32_PATH_DEPTH;

Expand Down
5 changes: 4 additions & 1 deletion app/rust/src/handlers/avax/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::{

pub struct Sign;

#[allow(static_mut_refs)]
impl Sign {
// For avax signing which includes P, C, X chains,
// sha256 is used
Expand Down Expand Up @@ -65,7 +66,7 @@ impl Sign {

let ui = SignUI { hash: digest, msg };

crate::show_ui!(ui.show(flags))
crate::show_ui!(unsafe { ui.show(flags) })
}
}

Expand All @@ -89,6 +90,7 @@ pub(crate) struct SignUI {
msg: AvaxMessage<'static>,
}

#[allow(static_mut_refs)]
impl Viewable for SignUI {
fn num_items(&mut self) -> Result<u8, ViewError> {
self.msg.num_items()
Expand Down Expand Up @@ -128,6 +130,7 @@ impl Viewable for SignUI {
}
}

#[allow(static_mut_refs)]
fn cleanup_globals() -> Result<(), Error> {
unsafe {
if let Ok(path) = PATH.acquire(Sign) {
Expand Down
6 changes: 5 additions & 1 deletion app/rust/src/handlers/avax/sign_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::{

pub struct Sign;

#[allow(static_mut_refs)]
impl Sign {
// For avax transactions which includes P, C, X chains,
// sha256 is used
Expand Down Expand Up @@ -129,7 +130,7 @@ impl Sign {
hash: unsigned_hash,
};

crate::show_ui!(ui.show(flags))
crate::show_ui!(unsafe { ui.show(flags) })
}

pub fn get_signing_info(data: &[u8]) -> Result<BIP32Path<MAX_BIP32_PATH_DEPTH>, Error> {
Expand Down Expand Up @@ -170,6 +171,7 @@ impl SignUI {
}
}

#[allow(static_mut_refs)]
impl Viewable for SignUI {
fn num_items(&mut self) -> Result<u8, ViewError> {
Ok(1)
Expand Down Expand Up @@ -199,6 +201,7 @@ impl Viewable for SignUI {
handle_ui_message(&hex[..size], message, page)
}


fn accept(&mut self, _out: &mut [u8]) -> (usize, u16) {
let tx = 0;

Expand Down Expand Up @@ -287,6 +290,7 @@ impl ApduHandler for Sign {
}
}

#[allow(static_mut_refs)]
pub fn cleanup_globals() -> Result<(), Error> {
unsafe {
if let Ok(path) = PATH.acquire(Sign) {
Expand Down
5 changes: 4 additions & 1 deletion app/rust/src/handlers/avax/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::{

pub struct Sign;

#[allow(static_mut_refs)]
impl Sign {
// For avax transactions which includes P, C, X chains,
// sha256 is used
Expand Down Expand Up @@ -159,7 +160,7 @@ impl Sign {
transaction,
};

crate::show_ui!(ui.show(flags))
crate::show_ui!(unsafe { ui.show(flags) })
}
}

Expand All @@ -183,6 +184,7 @@ pub(crate) struct SignUI {
transaction: Transaction<'static>,
}

#[allow(static_mut_refs)]
impl Viewable for SignUI {
fn num_items(&mut self) -> Result<u8, ViewError> {
self.transaction.num_items()
Expand Down Expand Up @@ -222,6 +224,7 @@ impl Viewable for SignUI {
}
}

#[allow(static_mut_refs)]
fn cleanup_globals() -> Result<(), Error> {
unsafe {
if let Ok(path) = PATH.acquire(Sign) {
Expand Down
5 changes: 4 additions & 1 deletion app/rust/src/handlers/eth/personal_msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use crate::utils::convert_der_to_rs;

pub struct Sign;

#[allow(static_mut_refs)]
impl Sign {
pub const SIGN_HASH_SIZE: usize = Keccak::<32>::DIGEST_LEN;

Expand Down Expand Up @@ -105,7 +106,7 @@ impl Sign {
tx,
};

crate::show_ui!(ui.show(flags))
crate::show_ui!(unsafe { ui.show(flags) })
}

#[inline(never)]
Expand Down Expand Up @@ -200,6 +201,7 @@ impl Sign {
}
}

#[allow(static_mut_refs)]
impl ApduHandler for Sign {
#[inline(never)]
fn handle(flags: &mut u32, tx: &mut u32, buffer: ApduBufferRead<'_>) -> Result<(), Error> {
Expand Down Expand Up @@ -357,6 +359,7 @@ impl Viewable for SignUI {
}
}

#[allow(static_mut_refs)]
fn cleanup_globals() -> Result<(), Error> {
unsafe {
if let Ok(path) = PATH.acquire(Sign) {
Expand Down
1 change: 1 addition & 0 deletions app/rust/src/handlers/eth/provide_nft_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{constants::ApduError as Error, dispatcher::ApduHandler, sys, utils::
pub struct Info;

#[cfg(feature = "erc721")]
#[allow(static_mut_refs)]
impl Info {
pub fn process(input: &[u8]) -> Result<(), Error> {
crate::zlog("NftInfo::process\x00");
Expand Down
1 change: 1 addition & 0 deletions app/rust/src/handlers/eth/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use super::utils::parse_bip32_eth;

pub struct GetPublicKey;

#[allow(static_mut_refs)]
impl GetPublicKey {
/// Retrieve the public key with the given bip32 path
#[inline(never)]
Expand Down
5 changes: 4 additions & 1 deletion app/rust/src/handlers/eth/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use crate::utils::convert_der_to_rs;

pub struct Sign;

#[allow(static_mut_refs)]
impl Sign {
pub const SIGN_HASH_SIZE: usize = Keccak::<32>::DIGEST_LEN;

Expand Down Expand Up @@ -112,7 +113,7 @@ impl Sign {
tx,
};

crate::show_ui!(ui.show(flags))
crate::show_ui!(unsafe { ui.show(flags) })
}

#[inline(never)]
Expand Down Expand Up @@ -244,6 +245,7 @@ impl Sign {
}
}

#[allow(static_mut_refs)]
impl ApduHandler for Sign {
#[inline(never)]
fn handle(flags: &mut u32, tx: &mut u32, buffer: ApduBufferRead<'_>) -> Result<(), Error> {
Expand Down Expand Up @@ -449,6 +451,7 @@ impl Viewable for SignUI {
}
}

#[allow(static_mut_refs)]
pub fn cleanup_globals() -> Result<(), Error> {
unsafe {
if let Ok(path) = PATH.acquire(Sign) {
Expand Down
2 changes: 1 addition & 1 deletion app/rust/src/handlers/eth/utils/u256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<'b> BorrowedU256<'b> {
}
}

impl<'b> Deref for BorrowedU256<'b> {
impl Deref for BorrowedU256<'_> {
type Target = [u8];

fn deref(&self) -> &Self::Target {
Expand Down
2 changes: 1 addition & 1 deletion app/rust/src/handlers/public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl ApduHandler for GetPublicKey {
let mut ui = unsafe { ui.assume_init() };

if req_confirmation {
crate::show_ui!(ui.show(flags), tx)
crate::show_ui!(unsafe { ui.show(flags) }, tx)
} else {
//we don't need to show so we execute the "accept" already
// this way the "formatting" to `buffer` is all in the ui code
Expand Down
2 changes: 2 additions & 0 deletions app/rust/src/handlers/public_key/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl From<AddrUIInitError> for Error {
}
}

#[allow(static_mut_refs)]
impl<'ui> AddrUIInitializer<'ui> {
/// Create a new `AddrUI` initialized
pub fn new(ui: &'ui mut MaybeUninit<AddrUI>) -> Self {
Expand Down Expand Up @@ -190,6 +191,7 @@ pub struct AddrUI {
hrp: [u8; ASCII_HRP_MAX_SIZE + 1], //+1 to null terminate just in case
}

#[allow(static_mut_refs)]
impl AddrUI {
//36 (32 + 4 checksum) * log(2, 256) / log(2, 58) ~ 49.1
// so we round up to 50
Expand Down
2 changes: 1 addition & 1 deletion app/rust/src/handlers/public_key/xpub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl ApduHandler for GetExtendedPublicKey {
let mut ui = unsafe { ui.assume_init() };

if req_confirmation {
crate::show_ui!(ui.show(flags), tx)
crate::show_ui!(unsafe { ui.show(flags) }, tx)
} else {
//we don't need to show so we execute the "accept" already
// this way the "formatting" to `buffer` is all in the ui code
Expand Down
2 changes: 1 addition & 1 deletion app/rust/src/handlers/wallet_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl ApduHandler for WalletId {
let mut ui = unsafe { ui.assume_init() };

if req_confirmation {
crate::show_ui!(ui.show(flags), tx)
crate::show_ui!(unsafe { ui.show(flags) }, tx)
} else {
//we don't need to show so we execute the "accept" already
// this way the "formatting" to `buffer` is all in the ui code
Expand Down
6 changes: 3 additions & 3 deletions app/rust/src/integration_tests/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ fn p_create_chain() {

let paths = (0..NUMBER_OF_SIGNERS)
.map(|_| {
let mut rng = rand::thread_rng();
let mut rng = rand::rng();

(
rng.gen_range(0..MAX_COMPONENT),
rng.gen_range(0..MAX_COMPONENT),
rng.random_range(0..MAX_COMPONENT),
rng.random_range(0..MAX_COMPONENT),
)
})
.chunks(MAX_N_SIGNERS);
Expand Down
4 changes: 2 additions & 2 deletions app/rust/src/parser/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub const MAX_ADDRESS_ENCODED_LEN: usize = bech32::estimate_size(ASCII_HRP_MAX_S
#[cfg_attr(any(test, feature = "derive-debug"), derive(Debug))]
pub struct Address<'b>(&'b [u8; ADDRESS_LEN]);

impl<'a> Address<'a> {
impl Address<'_> {
// Get the address encoding
pub fn encode_into(&self, hrp: &str, encoded: &mut [u8]) -> Result<usize, ParserError> {
if hrp.len() > ASCII_HRP_MAX_SIZE {
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<'b> FromBytes<'b> for Address<'b> {
}
}

impl<'a> DisplayableItem for Address<'a> {
impl DisplayableItem for Address<'_> {
fn num_items(&self) -> Result<u8, ViewError> {
Ok(1)
}
Expand Down
4 changes: 2 additions & 2 deletions app/rust/src/parser/asset_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub const ASSET_ID_LEN: usize = 32;
#[cfg_attr(any(test, feature = "derive-debug"), derive(Debug))]
pub struct AssetId<'b>(&'b [u8; ASSET_ID_LEN]);

impl<'b> AssetId<'b> {
impl AssetId<'_> {
pub fn id(&self) -> &[u8; ASSET_ID_LEN] {
self.0
}
Expand All @@ -55,7 +55,7 @@ impl<'b> AssetId<'b> {
}
}

impl<'a> DisplayableItem for AssetId<'a> {
impl DisplayableItem for AssetId<'_> {
fn num_items(&self) -> Result<u8, ViewError> {
Ok(1)
}
Expand Down
Loading
Loading