rust-bitcoin-unsafe-fast/bitcoin/src
Martin Habovstiak 492073f288 Strengthen the type of `taproot_control_block()`
The type returned by `Witness::taproot_control_block()` was just `&[u8]`
which wasn't very nice since users then had to manually decode it which
so far also required allocation. Thanks to previous improvements to
`ControlBlock` it is now possible to return a `ControlBlock` type
directly.

To avoid expensive checks, this change adds a new type
`SerializedXOnlyPublicKey` which is a wrapper around `[u8; 32]` that is
used in `ControlBlock` if complete checking is undesirable. It is then
used in the `ControlBlock` returned from
`Witness::taproot_control_block`. Users can still conveniently validate
the key using `to_validated` method.

It then uses this type in the recently-added `P2TrSpend` type. As a side
effect this checks more properties of `Witness` when calling unrelated
methods on `Witness`. From correctness perspective this should be OK: a
witness obtained from a verified source will be correct anyway and, if
these checks were done by the caller, they can be removed.

From performance perspective, if the `Witness` was obtained from a
verified source (e.g. using Bitcoin Core RPC) these checks are wasted
CPU time. But they shouldn't be too expensive, we already avoid
`secp256k1` overhead and, given that they always succeed in such case,
they should be easy to branch-predict.
2025-03-27 20:15:53 +01:00
..
address Unify/reduce usage of `unsafe` 2025-03-27 20:15:37 +01:00
blockdata Strengthen the type of `taproot_control_block()` 2025-03-27 20:15:53 +01:00
consensus fix typos 2025-03-10 09:04:59 +08:00
crypto Strengthen the type of `taproot_control_block()` 2025-03-27 20:15:53 +01:00
merkle_tree 2025-01-12 automated rustfmt nightly 2025-01-12 01:23:13 +00:00
network Update CompactTarget::from_next_work_required to take timespan as i64 2024-11-27 11:27:22 -06:00
p2p Remove From<hash> for not-general-hash types 2025-03-21 09:12:25 +11:00
psbt Remove a bunch of `try_into().expect()` 2025-03-20 20:19:50 +01:00
taproot Strengthen the type of `taproot_control_block()` 2025-03-27 20:15:53 +01:00
bip32.rs Add official BIP32 test vectors for invalid keys 2025-03-20 20:19:51 +01:00
bip152.rs Remove a bunch of `try_into().expect()` 2025-03-20 20:19:50 +01:00
bip158.rs Remove a bunch of `try_into().expect()` 2025-03-20 20:19:50 +01:00
consensus_validation.rs Stop using FQP on Amount type 2025-01-24 08:54:24 +11:00
hash_types.rs bitcoin: Remove hash type re-exports 2025-03-04 08:15:04 +11:00
internal_macros.rs Set avoid-breaking-exported-api to false 2024-12-11 10:11:50 +11:00
lib.rs Remove a bunch of `try_into().expect()` 2025-03-20 20:19:50 +01:00
policy.rs Policy: Relax MIN_STANDARD_TX_NONWITNESS_SIZE to 65 2025-02-27 00:20:08 +07:00
pow.rs chore: spellchecker 2025-03-16 07:23:18 +00:00
serde_utils.rs Elide more lifetimes 2024-10-28 15:22:13 +11:00
sign_message.rs update secp256k1 to 0.30.0 2025-03-02 23:31:48 +08:00