Skip to content

Commit f733dc0

Browse files
committed
Merge rust-bitcoin/rust-bitcoin#845: Change the parameter for control block verification
91c5d71 Change the parameter for control block verification (sanket1729) Pull request description: - Changes the API from TweakedPublicKey to XonlyPublicKey. I believe we introduced TweakedPublicKey to guard against creating address API. This is confusing because when we want to verify control block we have to call dangerous_assume_tweak. - This is in true in most cases that the key would be tweaked, but we only want to guard in while creating a new address. If we want to verify blocks, we should deal with native X-only-keys regardless of how they were created - Also removes the & from a 32 Copy byte as discussed elsewhere. ACKs for top commit: Kixunil: ACK 91c5d71 apoelstra: ACK 91c5d71 Tree-SHA512: d7da403435afbd1c1650b6e62055b1b0e6811d6ec30fff198315523035a56b493d510e8a560b08552684417886687c8a8daa57b5eef4f3699dfff7e2ee6a7447
2 parents 1ec9e87 + 91c5d71 commit f733dc0

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/util/taproot.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use std::error;
2727

2828
use hashes::{sha256, sha256t, Hash, HashEngine};
2929
use schnorr::{TweakedPublicKey, UntweakedPublicKey, TapTweak};
30+
use util::key::XOnlyPublicKey;
3031
use Script;
3132

3233
use consensus::Encodable;
@@ -726,7 +727,7 @@ impl ControlBlock {
726727
pub fn verify_taproot_commitment<C: secp256k1::Verification>(
727728
&self,
728729
secp: &Secp256k1<C>,
729-
output_key: &TweakedPublicKey,
730+
output_key: XOnlyPublicKey,
730731
script: &Script,
731732
) -> bool {
732733
// compute the script hash
@@ -750,7 +751,7 @@ impl ControlBlock {
750751
let tweak = TapTweakHash::from_key_and_tweak(self.internal_key, Some(curr_hash));
751752
self.internal_key.tweak_add_check(
752753
secp,
753-
output_key.as_inner(),
754+
&output_key,
754755
self.output_key_parity,
755756
tweak.into_inner(),
756757
)
@@ -1106,7 +1107,7 @@ mod test {
11061107
let script = Script::from_hex(script_hex).unwrap();
11071108
let control_block = ControlBlock::from_slice(&Vec::<u8>::from_hex(control_block_hex).unwrap()).unwrap();
11081109
assert_eq!(control_block_hex, control_block.serialize().to_hex());
1109-
assert!(control_block.verify_taproot_commitment(secp, &out_pk, &script));
1110+
assert!(control_block.verify_taproot_commitment(secp, out_pk.to_inner(), &script));
11101111
}
11111112

11121113
#[test]
@@ -1187,7 +1188,7 @@ mod test {
11871188
for (_weights, script) in script_weights {
11881189
let ver_script = (script, LeafVersion::TapScript);
11891190
let ctrl_block = tree_info.control_block(&ver_script).unwrap();
1190-
assert!(ctrl_block.verify_taproot_commitment(&secp, &output_key, &ver_script.0))
1191+
assert!(ctrl_block.verify_taproot_commitment(&secp, output_key.to_inner(), &ver_script.0))
11911192
}
11921193
}
11931194

@@ -1223,7 +1224,7 @@ mod test {
12231224
for script in vec![a, b, c, d, e] {
12241225
let ver_script = (script, LeafVersion::TapScript);
12251226
let ctrl_block = tree_info.control_block(&ver_script).unwrap();
1226-
assert!(ctrl_block.verify_taproot_commitment(&secp, &output_key, &ver_script.0))
1227+
assert!(ctrl_block.verify_taproot_commitment(&secp, output_key.to_inner(), &ver_script.0))
12271228
}
12281229
}
12291230

0 commit comments

Comments
 (0)