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.
This commit is contained in:
Tobin Harding 2021-12-02 14:13:33 +11:00
parent d8e42d153e
commit 3c3cf0396b
1 changed files with 3 additions and 3 deletions

View File

@ -53,9 +53,9 @@ impl TapTweak for UntweakedPublicKey {
let tweak_value = TapTweakHash::from_key_and_tweak(self, merkle_root).into_inner();
let mut output_key = self.clone();
let parity = output_key.tweak_add_assign(&secp, &tweak_value).expect("Tap tweak failed");
if self.tweak_add_check(&secp, &output_key, parity, tweak_value) {
return TweakedPublicKey(output_key);
} else { unreachable!("Tap tweak failed") }
debug_assert!(self.tweak_add_check(&secp, &output_key, parity, tweak_value));
TweakedPublicKey(output_key)
}
fn dangerous_assume_tweaked(self) -> TweakedPublicKey {