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
4 changes: 4 additions & 0 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ DEFINES += PRODUCTION_BUILD=$(PRODUCTION_BUILD)

# Add SDK BLAKE2b
DEFINES += HAVE_HASH HAVE_BLAKE2

# Enable blind signing toggle functionality
DEFINES += APP_BLINDSIGN_MODE_ENABLED

INCLUDES_PATH += $(BOLOS_SDK)/lib_cxng/src

INCLUDES_PATH += $(CURDIR)/src/common/
Expand Down
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=3
# Patch
APPVERSION_P=8
APPVERSION_P=9
11 changes: 11 additions & 0 deletions app/rust/include/rslib.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ uint32_t rs_eth_handle(
bool *done
);

bool rs_eth_was_streaming_mode_used(void);

bool rs_eth_get_streaming_hash(uint8_t *hash_buffer, uint16_t buffer_len);

parser_error_t _getNumItemsBlindSign(uint8_t *num_items);

parser_error_t _getItemBlindSign(int8_t displayIdx,
char *outKey, uint16_t outKeyLen,
char *outValue, uint16_t outValueLen,
uint8_t pageIdx, uint8_t *pageCount);

/****************************** others ***********************************************************/

parser_error_t _parser_init(parser_context_t *ctx, const uint8_t *buffer, size_t bufferSize, uint32_t *alloc_size);
Expand Down
77 changes: 77 additions & 0 deletions app/rust/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,70 @@ pub mod resources {
#[lazy_static]
pub static mut ETH_UI: Lock<Option<EthUi>, EthAccessors> = Lock::new(None);

/// Streaming hash resources for large EVM transactions that don't fit in buffer
/// When a transaction exceeds BUFFER_CAPACITY, it enters streaming mode
/// where the transaction is hashed incrementally across multiple APDU packets
/// Core streaming hasher - performs incremental Keccak256 hashing of transaction data
/// Used in: parse() to update hash with each packet, finalize_streaming_hash() to get final hash
#[lazy_static]
pub static mut STREAMING_HASHER: Lock<Option<bolos::hash::Keccak<32>>, StreamingAccessors> =
Lock::new(None);

/// Flag indicating if we're currently in streaming mode
/// Used in: parse() to check mode, finalize_streaming_hash() to clean up
#[lazy_static]
pub static mut STREAMING_MODE: Lock<bool, StreamingAccessors> = Lock::new(false);

/// Total bytes expected for the transaction (from RLP length parsing)
/// Used in: parse() initial packet to set total, subsequent packets to check completion
#[lazy_static]
pub static mut EXPECTED_BYTES: Lock<u64, StreamingAccessors> = Lock::new(0);

/// Total bytes received so far across all packets
/// Used in: parse() to track progress and determine when transaction is complete
#[lazy_static]
pub static mut RECEIVED_BYTES: Lock<u64, StreamingAccessors> = Lock::new(0);

/// Flag to track if streaming mode was used for the current transaction
/// Used in: rs_eth_was_streaming_mode_used() C function for external queries
#[lazy_static]
pub static mut STREAMING_MODE_USED: Lock<bool, StreamingAccessors> = Lock::new(false);

/// Stores the final computed hash from streaming mode
/// Used in: finalize_streaming_hash() to store result, rs_eth_get_streaming_hash() to retrieve for blind signing UI
#[lazy_static]
pub static mut STREAMING_HASH: Lock<Option<[u8; 32]>, StreamingAccessors> = Lock::new(None);

/// Store chain ID and transaction type for correct V calculation in streaming mode
/// Critical for EIP-155 signature compatibility between streaming and normal modes
/// Chain ID bytes extracted from transaction for V component calculation
/// Used in: parse() to store from first packet, finalize_streaming_hash() to use for V calculation
#[lazy_static]
pub static mut STREAMING_CHAIN_ID: Lock<Option<[u8; 8]>, StreamingAccessors> = Lock::new(None);

/// Transaction type flag (true = EIP-1559/EIP-2930, false = Legacy)
/// Used in: parse() to store type, finalize_streaming_hash() to determine V calculation method
#[lazy_static]
pub static mut STREAMING_TX_TYPE: Lock<bool, StreamingAccessors> = Lock::new(false);

/// Packet buffering for legacy transaction chain ID extraction
/// Legacy transactions store chain ID at the end, requiring buffering of last packets
/// Last received packet [length_byte, data...] - used for legacy chain ID extraction
/// Used in: parse() to buffer packets, finalize_streaming_hash() to extract chain ID from end
#[lazy_static]
pub static mut LAST_PACKET: Lock<Option<[u8; 255]>, StreamingAccessors> = Lock::new(None);

/// Second-to-last packet [length_byte, data...] - for multi-packet legacy chain ID extraction
/// Used in: parse() to rotate packet buffer, finalize_streaming_hash() to combine with last packet
#[lazy_static]
pub static mut SECOND_LAST_PACKET: Lock<Option<[u8; 255]>, StreamingAccessors> =
Lock::new(None);

/// Flag indicating if current transaction is legacy type (affects chain ID location)
/// Used in: parse() to set based on transaction type, packet buffering, and chain ID extraction
#[lazy_static]
pub static mut IS_LEGACY_TX: Lock<bool, StreamingAccessors> = Lock::new(false);

#[derive(Clone, Copy, PartialEq, Eq)]
pub enum BUFFERAccessors {
Sign,
Expand Down Expand Up @@ -99,6 +163,11 @@ pub mod resources {
ERC721Parser,
}

#[derive(Clone, Copy, PartialEq, Eq)]
pub enum StreamingAccessors {
EthSign,
}

impl From<super::avax::signing::Sign> for BUFFERAccessors {
fn from(_: super::avax::signing::Sign) -> Self {
Self::Sign
Expand Down Expand Up @@ -143,6 +212,14 @@ pub mod resources {
}
}

// *********************** Streaming accessor implementation ***********************

impl From<super::eth::signing::Sign> for StreamingAccessors {
fn from(_: super::eth::signing::Sign) -> Self {
Self::EthSign
}
}

// *********************** NfT accessors ***********************

#[cfg(feature = "erc721")]
Expand Down
Loading
Loading