Skip to content

Commit 3c3cf03

Browse files
committed
Remove use of unreachable in error branch
We currently run `tweak_add_check` and use the result as a conditional branch, the error path of which uses `unreachable`. This usage of `unreachable` is non-typical. An 'unreachable' statement is by definition supposed to be unreachable, it is not clear why we would need to have a conditional branch to check an unreachable statement. Use `debug_assert!` so programmer errors get caught in un-optimised builds but in optimised builds the call to `tweak_add_check` is not even done.
1 parent d8e42d1 commit 3c3cf03

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/util/schnorr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ impl TapTweak for UntweakedPublicKey {
5353
let tweak_value = TapTweakHash::from_key_and_tweak(self, merkle_root).into_inner();
5454
let mut output_key = self.clone();
5555
let parity = output_key.tweak_add_assign(&secp, &tweak_value).expect("Tap tweak failed");
56-
if self.tweak_add_check(&secp, &output_key, parity, tweak_value) {
57-
return TweakedPublicKey(output_key);
58-
} else { unreachable!("Tap tweak failed") }
56+
57+
debug_assert!(self.tweak_add_check(&secp, &output_key, parity, tweak_value));
58+
TweakedPublicKey(output_key)
5959
}
6060

6161
fn dangerous_assume_tweaked(self) -> TweakedPublicKey {

0 commit comments

Comments
 (0)