eth: cover large-number formatting and fees
What changed, and why it matters
This commit only adds new automated tests for Ethereum fee calculation and large-number decimal formatting. It does not change any production code, so it cannot by itself introduce or fix a security bug. The tests are described by the author as regression tests to prepare for a future formatting and fee-calculation change that aims to reduce firmware size.
No immediate security action required. Treat as routine test coverage. Review the follow-up commit that actually changes the large-number formatting and fee calculations for potential security issues.
Security signals we found
No production code changes
Pure test addition
Future refactoring is explicitly mentioned in commit message (firmware-size reduction)
Tests target arithmetic/formatting correctness for transaction fees and large numbers
Evidence from the diff
The diff adds unit tests in two Rust files. In src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs, a new test test_parse_fee_matches_biguint_multiplication verifies that parse_fee() for both legacy and EIP-1559 Ethereum transactions equals a direct BigUint multiplication across boundary operand values. In src/rust/util/src/decimal.rs, new tests test_biguint_to_string and test_bigint_to_string compare custom decimal formatting helpers against num-bigint’s native formatting for zero, digit boundaries, large unsigned values up to 2^256, and negative values down to -2^255. No implementation logic is modified.
Changed components
src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rssrc/rust/util/src/decimal.rsInspect captured patch +73 / −0
### src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs
@@ -735,6 +735,49 @@ mod tests {
}
}
+ #[test]
+ fn test_parse_fee_matches_biguint_multiplication() {
+ let params = Params {
+ coin: Some(pb::EthCoin::Eth),
+ chain_id: 1,
+ bip44_coin: 60 + HARDENED,
+ name: "Ethereum",
+ unit: "ETH",
+ };
+ // Pair zero, one, mixed-byte values, and the largest allowed 128-bit value
+ // to exercise byte order, zero bytes, and carries in both operands.
+ let operands: &[&[u8]] = &[
+ &[],
+ &hex!("01"),
+ &hex!("010002"),
+ &hex!("0123456789abcdef0123456789abcdef"),
+ &[0xff; 16],
+ ];
+ for price in operands {
+ for limit in operands {
+ let expected = BigUint::from_bytes_be(price) * BigUint::from_bytes_be(limit);
+ let legacy = pb::EthSignRequest {
+ gas_price: price.to_vec(),
+ gas_limit: limit.to_vec(),
+ ..Default::default()
+ };
+ let eip1559 = pb::EthSignEip1559Request {
+ max_fee_per_gas: price.to_vec(),
+ max_priority_fee_per_gas: vec![1],
+ gas_limit: limit.to_vec(),
+ ..Default::default()
+ };
+ for request in [Transaction::Legacy(&legacy), Transaction::Eip1559(&eip1559)] {
+ assert_eq!(
+ parse_fee(&request, ¶ms).value,
+ expected,
+ "price={price:02x?}, limit={limit:02x?}"
+ );
+ }
+ }
+ }
+ }
+
#[test]
pub fn test_parse_recipient() {
assert_eq!(
### src/rust/util/src/decimal.rs
@@ -53,6 +53,36 @@ pub fn format_no_trim<F: Format>(value: F, decimals: usize) -> String {
mod tests {
use super::*;
+ #[test]
+ fn test_biguint_to_string() {
+ let two_to_256 = BigUint::from(1u32) << 256usize;
+ for value in [
+ BigUint::ZERO,
+ BigUint::from(1u32),
+ BigUint::from(9u32),
+ BigUint::from(10u32),
+ BigUint::from(1_020_030u32),
+ BigUint::from(u64::MAX),
+ &two_to_256 - 1u32,
+ two_to_256,
+ ] {
+ assert_eq!(biguint_to_string(&value), value.to_string());
+ }
+ }
+
+ #[test]
+ fn test_bigint_to_string() {
+ for value in [
+ BigInt::from(0),
+ BigInt::from(1),
+ BigInt::from(-1),
+ BigInt::from(i64::MIN),
+ -(BigInt::from(1u32) << 255usize),
+ ] {
+ assert_eq!(bigint_to_string(&value), value.to_string());
+ }
+ }
+
#[test]
fn test_format_int() {
assert_eq!(format(0u64, 0), "0");Why this scored 12/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.