Skip to content

Commit faf3199

Browse files
committed
fixup! eth: add confirmation screen for known networks
1 parent 500314d commit faf3199

File tree

2 files changed

+6
-49
lines changed

2 files changed

+6
-49
lines changed

src/rust/bitbox02-rust/src/hww/api/ethereum/params.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,6 @@ const PARAMS: &[Params] = &[
100100
},
101101
];
102102

103-
/// Check if the chain_id corresponds to a known network (to show an additional confirmations for).
104-
pub fn is_known_network(chain_id: u64) -> bool {
105-
PARAMS.iter().any(|p| p.chain_id == chain_id)
106-
}
107-
108103
/// Get the chain parameters by `coin` or `chain_id`. If `chain_id` is non-zero, `coin` is ignored.
109104
fn get(coin: Option<EthCoin>, chain_id: u64) -> Option<&'static Params> {
110105
PARAMS.iter().find(|p| {
@@ -118,6 +113,11 @@ fn get(coin: Option<EthCoin>, chain_id: u64) -> Option<&'static Params> {
118113
})
119114
}
120115

116+
/// Check if the chain_id corresponds to a known network (to show an additional confirmations for).
117+
pub fn is_known_network(coin: Option<EthCoin>, chain_id: u64) -> bool {
118+
get(coin, chain_id).is_some()
119+
}
120+
121121
/// Get the chain parameters by `coin` or `chain_id`. If `chain_id` is non-zero, `coin` is
122122
/// ignored. If `coin` is None. `chain_id` alone is used.
123123
///

src/rust/bitbox02-rust/src/hww/api/ethereum/sign.rs

+1-44
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ pub async fn process(request: &Transaction<'_>) -> Result<Response, Error> {
300300
super::keypath::warn_unusual_keypath(&params, params.name, request.keypath()).await?;
301301

302302
// Show chain confirmation only for known networks
303-
if super::params::is_known_network(params.chain_id) {
303+
if super::params::is_known_network(request.coin()?, request.chain_id()) {
304304
confirm::confirm(&confirm::Params {
305305
body: &format!("Sign transaction on\n\n{}", params.name),
306306
accept_is_nextarrow: true,
@@ -1335,47 +1335,4 @@ mod tests {
13351335
.unwrap();
13361336
assert_eq!(unsafe { CONFIRM_COUNTER }, 1);
13371337
}
1338-
1339-
/// Test that unknown networks do NOT get the chain confirmation screen
1340-
#[test]
1341-
pub fn test_no_chain_confirmation_for_unknown_networks() {
1342-
const KEYPATH: &[u32] = &[44 + HARDENED, 60 + HARDENED, 0 + HARDENED, 0, 0];
1343-
static mut CONFIRM_COUNTER: u32 = 0;
1344-
1345-
// Test with an unknown network (chain_id 999999)
1346-
mock(Data {
1347-
ui_confirm_create: Some(Box::new(|params| {
1348-
unsafe {
1349-
// Only the warning confirmations should appear, not chain confirmation
1350-
if params.body.starts_with("Sign transaction on") {
1351-
CONFIRM_COUNTER += 1;
1352-
}
1353-
}
1354-
true
1355-
})),
1356-
ui_transaction_address_create: Some(Box::new(|_, _| true)),
1357-
ui_transaction_fee_create: Some(Box::new(|_, _, _| true)),
1358-
..Default::default()
1359-
});
1360-
mock_unlocked();
1361-
1362-
block_on(process(&Transaction::Legacy(&pb::EthSignRequest {
1363-
coin: pb::EthCoin::Eth as _,
1364-
keypath: KEYPATH.to_vec(),
1365-
nonce: b"\x1f\xdc".to_vec(),
1366-
gas_price: b"\x01\x65\xa0\xbc\x00".to_vec(),
1367-
gas_limit: b"\x52\x08".to_vec(),
1368-
recipient:
1369-
b"\x04\xf2\x64\xcf\x34\x44\x03\x13\xb4\xa0\x19\x2a\x35\x28\x14\xfb\xe9\x27\xb8\x85"
1370-
.to_vec(),
1371-
value: b"\x07\x5c\xf1\x25\x9e\x9c\x40\x00".to_vec(),
1372-
data: b"".to_vec(),
1373-
host_nonce_commitment: None,
1374-
chain_id: 999999,
1375-
address_case: pb::EthAddressCase::Mixed as _,
1376-
})))
1377-
.unwrap();
1378-
1379-
assert_eq!(unsafe { CONFIRM_COUNTER }, 0);
1380-
}
13811338
}

0 commit comments

Comments
 (0)