Skip to content

Commit 326b5bc

Browse files
committed
Merge remote-tracking branch 'benma/ada-high-fee'
2 parents 940c05f + 0e0e735 commit 326b5bc

File tree

2 files changed

+93
-2
lines changed

2 files changed

+93
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ customers cannot upgrade their bootloader, its changes are recorded separately.
77
## Firmware
88

99
### [Unreleased]
10-
- Bitcoin, Ethereum: warn if the transaction fee is higher than 10% of the coins sent
10+
- Warn if the transaction fee is higher than 10% of the coins sent
1111
- ETH Testnets: add Goerli and remove deprecated Rinkeby and Ropsten
1212

1313
### 9.13.1

src/rust/bitbox02-rust/src/hww/api/cardano/sign_transaction.rs

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,11 @@ async fn _process(request: &pb::CardanoSignTransactionRequest) -> Result<Respons
257257
})
258258
.await?;
259259
} else {
260+
let fee_percentage: f64 = 100. * (request.fee as f64) / (total as f64);
260261
transaction::verify_total_fee(
261262
&format_value(params, total + request.fee),
262263
&format_value(params, request.fee),
263-
None,
264+
Some(fee_percentage),
264265
)
265266
.await?;
266267
}
@@ -566,6 +567,10 @@ mod tests {
566567
assert_eq!(params.body, "Fee\n0.191681 ADA");
567568
true
568569
}
570+
5 => {
571+
assert_eq!(params.title, "High fee");
572+
true
573+
}
569574
_ => panic!("too many user confirmations"),
570575
}
571576
})),
@@ -898,6 +903,10 @@ mod tests {
898903
assert_eq!(params.body, "Transaction\ncannot be\nmined");
899904
true
900905
}
906+
2 => {
907+
assert_eq!(params.title, "High fee");
908+
true
909+
}
901910
_ => panic!("too many user confirmations"),
902911
}
903912
})),
@@ -969,6 +978,10 @@ mod tests {
969978
assert_eq!(params.body, "Can be mined from\nslot 335011 in\nepoch 292");
970979
true
971980
}
981+
2 => {
982+
assert_eq!(params.title, "High fee");
983+
true
984+
}
972985
_ => panic!("too many user confirmations"),
973986
}
974987
})),
@@ -1030,6 +1043,10 @@ mod tests {
10301043
assert_eq!(params.body, "Transaction\ncannot be\nmined");
10311044
true
10321045
}
1046+
2 => {
1047+
assert_eq!(params.title, "High fee");
1048+
true
1049+
}
10331050
_ => panic!("too many user confirmations"),
10341051
}
10351052
})),
@@ -1143,6 +1160,10 @@ mod tests {
11431160
);
11441161
true
11451162
}
1163+
5 => {
1164+
assert_eq!(params.title, "High fee");
1165+
true
1166+
}
11461167
_ => panic!("unexpected user confirmation"),
11471168
}
11481169
})),
@@ -1176,6 +1197,76 @@ mod tests {
11761197
);
11771198
}
11781199

1200+
// Test a transaction with an unusually high fee.
1201+
#[test]
1202+
fn test_high_fee_warning() {
1203+
let tx = pb::CardanoSignTransactionRequest {
1204+
network: CardanoNetwork::CardanoMainnet as _,
1205+
inputs: vec![pb::cardano_sign_transaction_request::Input {
1206+
keypath: vec![1852 + HARDENED, 1815 + HARDENED, HARDENED, 0, 0],
1207+
prev_out_hash: b"\x59\x86\x4e\xe7\x3c\xa5\xd9\x10\x98\xa3\x2b\x3c\xe9\x81\x1b\xac\x19\x96\xdc\xba\xef\xa6\xb6\x24\x7d\xca\xaf\xb5\x77\x9c\x25\x38".to_vec(),
1208+
prev_out_index: 0,
1209+
}],
1210+
outputs: vec![
1211+
pb::cardano_sign_transaction_request::Output {
1212+
encoded_address: "addr1q9qfllpxg2vu4lq6rnpel4pvpp5xnv3kvvgtxk6k6wp4ff89xrhu8jnu3p33vnctc9eklee5dtykzyag5penc6dcmakqsqqgpt".into(),
1213+
value: 1000000,
1214+
script_config: None,
1215+
asset_groups: vec![],
1216+
},
1217+
// change
1218+
pb::cardano_sign_transaction_request::Output {
1219+
encoded_address: "addr1q90tlskd4mh5kncmul7vx887j30tjtfgvap5n0g0rf9qqc7znmndrdhe7rwvqkw5c7mqnp4a3yflnvu6kff7l5dungvqmvu6hs".into(),
1220+
value: 4829501,
1221+
script_config: Some(CardanoScriptConfig{
1222+
config: Some(pb::cardano_script_config::Config::PkhSkh(pb::cardano_script_config::PkhSkh {
1223+
keypath_payment: vec![1852 + HARDENED, 1815 + HARDENED, HARDENED, 0, 0],
1224+
keypath_stake: vec![1852 + HARDENED, 1815 + HARDENED, HARDENED, 2, 0],
1225+
}))
1226+
}),
1227+
asset_groups: vec![],
1228+
},
1229+
],
1230+
fee: 170499,
1231+
ttl: 0,
1232+
allow_zero_ttl: false,
1233+
certificates: vec![],
1234+
withdrawals: vec![],
1235+
validity_interval_start: 0,
1236+
};
1237+
1238+
static mut CONFIRM_COUNTER: u32 = 0;
1239+
mock(Data {
1240+
ui_confirm_create: Some(Box::new(|params| {
1241+
match unsafe {
1242+
CONFIRM_COUNTER += 1;
1243+
CONFIRM_COUNTER
1244+
} {
1245+
1 => {
1246+
assert_eq!(params.title, "High fee");
1247+
assert_eq!(params.body, "The fee rate\nis 17.0%.\nProceed?");
1248+
assert!(params.longtouch);
1249+
true
1250+
}
1251+
_ => panic!("unexpected user confirmations"),
1252+
}
1253+
})),
1254+
1255+
ui_transaction_address_create: Some(Box::new(|_amount, _address| true)),
1256+
ui_transaction_fee_create: Some(Box::new(|total, fee, longtouch| {
1257+
assert_eq!(total, "1.170499 ADA");
1258+
assert_eq!(fee, "0.170499 ADA");
1259+
assert!(!longtouch);
1260+
true
1261+
})),
1262+
..Default::default()
1263+
});
1264+
mock_unlocked();
1265+
1266+
assert!(block_on(process(&tx)).is_ok());
1267+
assert_eq!(unsafe { CONFIRM_COUNTER }, 1);
1268+
}
1269+
11791270
#[test]
11801271
fn test_validate_asset_groups() {
11811272
assert!(validate_asset_groups(&[]).is_ok());

0 commit comments

Comments
 (0)