rust-bitcoin-unsafe-fast/bitcoin/src
Andrew Poelstra 2664f978f3
Merge rust-bitcoin/rust-bitcoin#2213: Fix InputWeightPrediction::P2WPKH_MAX constant DER sig length
f41ebc2149 Add test for input weight predictions (conduition)
4514a80a23 Fix the InputWeightPrediction constants for DER signatures (conduition)
b5ce219c62 add weight method to InputWeightPrediction (conduition)

Pull request description:

  The `P2WPKH_MAX` constant assumed DER signatures in the witness have a max length of 73. In practice, their maximum length is 72, because [BIP62](https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki) forbids nodes from relaying transactions which contain non-canonical ECDSA signatures (i.e. TX sigs must have an $s$ value of less than $\frac{n}{2}$).

  This means $s$ is never encoded with a leading zero byte, and the signature as a whole never exceeds 72 bytes in total encoded length. The `ground_p2wpkh` function was already correct; only the constant needed to be corrected.

  Technically 73 bytes *is* the upper limit for signatures, as nothing forbids miners from including such non-standard transaction signatures in blocks, but for the purposes of fee estimation and input weight prediction, 72 is the number which 99.9% of implementations should use as their ceiling. We already use it as the ceiling for the `ground_p2wpkh` function - `ground_p2wpkh(0)` returns a prediction which uses a witness signature of length 72.

  Reference:
  - https://bitcoin.stackexchange.com/questions/77191/what-is-the-maximum-size-of-a-der-encoded-ecdsa-signature
  - https://bitcoin.stackexchange.com/questions/106435/are-high-s-ecdsa-signatures-forbidden-in-segwit-witnesses
  - https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki

  To enable testing, I added a `weight()` method to `InputWeightPrediction` and made it public but i'm not sure whether it has a use-case. Let me know if I should make it private instead.

ACKs for top commit:
  tcharding:
    ACK f41ebc2149
  apoelstra:
    ACK f41ebc2149

Tree-SHA512: 10e837bad9881c0efebb0598eaefd4ab039f2a6ececead75a68e253d84f5e85cb30496a6069eee8dfe9714773f3aa23cfe373f5d88d1c5609e1b1be1ff142e37
2023-11-22 20:36:11 +00:00
..
address Merge rust-bitcoin/rust-bitcoin#2120: Improve public re-exports 2023-11-15 13:51:51 +00:00
blockdata Merge rust-bitcoin/rust-bitcoin#2213: Fix InputWeightPrediction::P2WPKH_MAX constant DER sig length 2023-11-22 20:36:11 +00:00
consensus Merge rust-bitcoin/rust-bitcoin#2093: Manually implement `JsonSchema` 2023-11-22 18:55:41 +00:00
crypto Merge rust-bitcoin/rust-bitcoin#2066: Add a `bitcoin-io` crate 2023-11-19 14:26:19 +00:00
merkle_tree Improve public re-exports 2023-10-31 15:16:47 +11:00
p2p Merge rust-bitcoin/rust-bitcoin#2066: Add a `bitcoin-io` crate 2023-11-19 14:26:19 +00:00
psbt Merge rust-bitcoin/rust-bitcoin#2066: Add a `bitcoin-io` crate 2023-11-19 14:26:19 +00:00
amount.rs Remove code deprecated since v0.31.0 2023-11-04 12:14:54 +11:00
base58.rs Merge rust-bitcoin/rust-bitcoin#1986: Remove private hex test macro 2023-10-06 22:14:12 +00:00
bip32.rs Remove deprecated since NEXT-RELEASE 2023-11-04 09:52:52 +11:00
bip152.rs Make error types uniform 2023-10-04 15:15:52 +11:00
bip158.rs Stop relying on blanket Read impl for all &mut Read 2023-11-07 05:51:36 +00:00
error.rs Improve public re-exports 2023-10-31 15:16:47 +11:00
hash_types.rs Improve public re-exports 2023-10-31 15:16:47 +11:00
internal_macros.rs [IO] Move to custom `Read` trait mirroring `std::io::Read` 2023-11-07 05:51:39 +00:00
lib.rs Merge rust-bitcoin/rust-bitcoin#2066: Add a `bitcoin-io` crate 2023-11-19 14:26:19 +00:00
network.rs Add `params` method to `Network` 2023-11-05 19:57:47 +01:00
parse.rs Make error types uniform 2023-10-04 15:15:52 +11:00
policy.rs bitcoin: Remove attribution from all files 2023-05-01 09:22:48 +10:00
pow.rs Merge rust-bitcoin/rust-bitcoin#2168: Use network when calculating difficulty 2023-11-06 14:38:00 +00:00
serde_utils.rs Depend on hex-conservative 2023-07-21 10:59:46 +10:00
sign_message.rs Improve public re-exports 2023-10-31 15:16:47 +11:00
string.rs Make error types uniform 2023-10-04 15:15:52 +11:00
taproot.rs Merge rust-bitcoin/rust-bitcoin#2066: Add a `bitcoin-io` crate 2023-11-19 14:26:19 +00:00
test_macros.rs bitcoin: Remove attribution from all files 2023-05-01 09:22:48 +10:00