eth: harmonize large data warnings for transactions and typed messages#1876
Open
Tomasvrba wants to merge 2 commits intoBitBoxSwiss:masterfrom
Open
eth: harmonize large data warnings for transactions and typed messages#1876Tomasvrba wants to merge 2 commits intoBitBoxSwiss:masterfrom
Tomasvrba wants to merge 2 commits intoBitBoxSwiss:masterfrom
Conversation
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
benma
requested changes
Mar 31, 2026
| 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}; |
Collaborator
There was a problem hiding this comment.
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.
src/rust/bitbox02/src/ui/types.rs
Outdated
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) |
Collaborator
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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