Skip to content

eth: harmonize large data warnings for transactions and typed messages#1876

Open
Tomasvrba wants to merge 2 commits intoBitBoxSwiss:masterfrom
Tomasvrba:eth-stream
Open

eth: harmonize large data warnings for transactions and typed messages#1876
Tomasvrba wants to merge 2 commits intoBitBoxSwiss:masterfrom
Tomasvrba:eth-stream

Conversation

@Tomasvrba
Copy link
Copy Markdown
Collaborator

Adjust wording in transaction signing so warnings and truncating logic match the newly implemented approach in sign_typed_msg.rs

Move the truncating logic and constant into a shared crate to avoid duplication

@Tomasvrba Tomasvrba requested a review from benma March 26, 2026 15:52
Adjust wording in transaction signing so warnings and truncating logic
match the newly implemented approach in sign_typed_msg.rs

Move the truncating logic and constant into a shared crate to avoid
duplication
use alloc::boxed::Box;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
use bitbox02::ui::{MAX_CONFIRM_BODY_SIZE, truncating_hex_preview_byte_cap};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not allowed to use any bitbox02 functions in bitbox02_rust. I thought we had this in our AGENTS 😛

bitbox02_rust is gonna be renamed bitbox_core and be there for all version of bitbox, while bitbox02 only implements bitbox02 specific things. So the constant duplication before was actually okay.

Comment on lines +13 to +24
/// Returns how many bytes of hex-encoded data to include in a preview body.
///
/// The preview body is rendered as `<prefix><hex>`. If the full value is longer than what fits,
/// one additional byte is included so the body exceeds `MAX_CONFIRM_BODY_SIZE` and the UI appends
/// `...`.
pub fn truncating_hex_preview_byte_cap(prefix_len: usize, data_length: usize) -> usize {
let hex_chars_budget = MAX_CONFIRM_BODY_SIZE.saturating_sub(prefix_len);
let bytes_that_fit = hex_chars_budget / 2;
let needs_ellipsis = data_length > bytes_that_fit;
let preview_bytes = bytes_that_fit + usize::from(needs_ellipsis);

preview_bytes.min(data_length)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite a specific function, I'd move it to bitbox02_rust::api::eth. Since we can't use the bitbox02 crate in bitbox02_rust anyway, that's necessary anyway.

@Tomasvrba Tomasvrba requested a review from benma April 2, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants