Commit Graph

3758 Commits

Author SHA1 Message Date
Martin Habovstiak 0ac9ad16ce Add `taproot::SerializedSignature`
Previously `taproot::Signature` could be only serialized into `Vec<u8>`
which forced allocation. This adds a `SerializedSignature` type which
acts like `Box<u8>` but is on stack.

Note: the code was copied from `secp256k1::ecdsa::serialized_signature`
with minimal changes.
2023-12-06 11:02:35 +01:00
Martin Habovstiak dffa51e735 Move taproot module to a subdirectory
This is in preparation for adding more submodules.
2023-12-06 11:02:35 +01:00
Tobin C. Harding b72f1d70e5
bitcoin: Add DO_FEATURE_MATRIX
Add a feature matrix section to the `bitcoin` CI script as we do in
`hashes`. This means:

- test with no default features
- test with all individual features
- test with all combinations of two features

Note, with this applied all features and optional dependencies are
included in `FEATURES` (excluding `secp-lowmemory`).

The feature matrix test gets run for stable and MSRV toolchains.
2023-12-06 10:09:05 +11:00
Tobin C. Harding 48879e7ad9
Remove no-std feature
Currently `bitcoin` cannot be built with no features enabled, it must
have either "no-std" or "std" enabled. This is an artifact from when
we depended on `core2` for "no-std", now that we have our own `io` crate
and we unconditionally depend on it we can remove the "no-std" feature.
2023-12-06 09:54:33 +11:00
Tobin C. Harding 6f1cb42d84
Remove NEXT_RELEASE from release script comment
Recently we remove the usage of `NEXT_RELEASE` in favour of `TBD` but I
missed the code comment.
2023-12-05 15:03:38 +11:00
Tobin C. Harding 801c72e056
Add deprecation comment to hash_types module
The `hash_types` module has been emptied, it now contains only
deprecated re-exports. Add a rustdoc comment stating as such.
2023-12-05 15:01:18 +11:00
Tobin C. Harding 61351c917f
Move impl_asref_push_bytes to internal_macros
We are emptying the `hash_types` module. `impl_asref_push_bytes!` is an
internal macro, as such it can live in the `internal_macros` module.

While we are at it import the macro and call it without any qualifying
path, this is typical for our usage of other internals/internal_macros
usage.
2023-12-05 15:01:17 +11:00
Tobin C. Harding 2b4b66dee3
Move impl_hashencode to internal_macros
We are emptying the `hash_types` module. `impl_hashencode!` is an
internal macro, as such it can live in the `internal_macros` module.
2023-12-05 15:01:17 +11:00
Tobin C. Harding 2a0ac1258a
Move the bip158 filter hash types
We would like all the various hash types to be defined where they
rightly live instead of in the `hash_types` module.

Move the BIP-158 filter hash types to the `bip158` module.
2023-12-05 15:01:17 +11:00
Tobin C. Harding 3107f80aac
Move transaction hash types
We would like all the various hash types to be defined where they
rightly live instead of in the `hash_types` module.

Move transaction hash types to the `transaction` module.
2023-12-05 14:57:48 +11:00
Tobin C. Harding 61c02ff202
Move block hash types
We would like all the various hash types to be defined where they
rightly live instead of in the `hash_types` module.

Move the block hash types to the `block` module. While moving, add full
stops to the rustdoc of each hash.

Re-export _all four_ types from lib.rs (previously `WitnessMerkleNode`
was not re-exported).
2023-12-05 14:57:28 +11:00
Tobin C. Harding 1ee989a3af
Remove private fmt_internal function
Just use `fmt::Display::fmt` directly since `fmt_internal` does exactly
that.

Refactor only, no logic changes.
2023-12-05 09:27:15 +11:00
Tobin C. Harding 923ce7402d
Remove Network from AddressInner
An `AddressInner` struct is created when parsing address strings however
address strings do not map 1:1 to `Network` because signet and testnet
use the same bech32 prefix "tb".

We can fix this by inlining the `Payload` variants into `AddressInner`
and adding prefix enums for legacy addresses and a `KnownHrp` for bech32
addresses.

Also enables removing the `AddressEncoding` struct as we can display the
`AddressInner` struct directly. (The `Display` impl is on `AddressInner`
and not directly on address to ignore the `NetworkValidation` wrapper,
may be able to be simplified still further.)
2023-12-05 09:27:15 +11:00
Tobin C. Harding 3490433618
Return error from wpubkey_hash
Calling `wpubkey_hash` on a key that is uncompressed is flat out an
error, really it is a programmer error at build time because a segwit
key should never be compressed, however, for historical reasons we do
not enforce this in the type system. As a step towards clarity make it
an error to call `wpubkey_hash` on a an uncompressed pubkey. This adds
documentation and potentially might assist debugging for newer devs.
2023-12-05 09:21:51 +11:00
Tobin C. Harding f7ab253ce4
Remove stale comment
This comment appears to come from before we had types for tweaked and
untweaked keys in taproot. We can remove it.
2023-12-05 09:21:51 +11:00
Tobin C. Harding 7d71fb9fdb
Re-order dependencies in manifest
Currently the feature enabling is different for "std" and "no-std",
which is again different to the order in the dependencies section. These
two things make reading the manifest harder than it needs to be.

Put the dependencies in alphabetic order in the dependencies section as
well as when enabling them.

Refactor only, no logic changes.
2023-12-04 14:21:06 +11:00
Andrew Poelstra 83cefefa45
Merge rust-bitcoin/rust-bitcoin#2235: Refactor `io` crate
b1870656c9 Combine the two Error impl blocks together (Tobin C. Harding)
82ea4ff31d Move error code to submodule (Tobin C. Harding)
67511ed03f Move no_std above comment (Tobin C. Harding)
f83d68f246 Add vertical whitespace (Tobin C. Harding)

Pull request description:

  Do various refactorings to the `io` crate. These are all trivial to review except the bigish commit: `d3d3e50f Move error code to submodule` which is code move only.

ACKs for top commit:
  Kixunil:
    ACK b1870656c9
  apoelstra:
    ACK b1870656c9

Tree-SHA512: 391347614121ea8ebe55af705e9688a9a668222cb8f1eb0a3a5275970e67ffb9dd6dfbd436080ab72592f0c86f2b8b36e0ff0322ca25dcd926d0ce80fb8b942f
2023-12-03 23:31:54 +00:00
Tobin C. Harding b1870656c9
Combine the two Error impl blocks together
We have two impl blocks for `Error`, just squash them together into a
single one.
2023-12-04 06:48:27 +11:00
Tobin C. Harding 82ea4ff31d
Move error code to submodule
Move error code to a private `error` submodule and re-export it at the
crate root.

(Puts private `sealed` module at the bottom of the file i.e., this patch
is strictly a code move but we re-order the code while moving it.)
2023-12-04 06:47:14 +11:00
Tobin C. Harding 67511ed03f
Move no_std above comment
Currently the no_std attribute is below a comment that does not relate
to it. For slightly improved clarity move the attribute above the
comment.
2023-12-04 06:37:46 +11:00
Tobin C. Harding f83d68f246
Add vertical whitespace
Make the `io` crate conform to `rust-bitcoin` code style in regards to
whitespace between functions/types etc.

Whitespace only, no other changes.
2023-12-04 06:37:43 +11:00
Andrew Poelstra 3ddf60ffd4
Merge rust-bitcoin/rust-bitcoin#2204: Add author for the format bot
6a9713a0cc Add author for the format bot (Tobin C. Harding)

Pull request description:

  The format bot defaults to using the person who triggered the workflow. We can use the `author` option to configure a dummy bot author.

ACKs for top commit:
  Kixunil:
    ACK 6a9713a0cc
  apoelstra:
    ACK 6a9713a0cc

Tree-SHA512: 8b2c419767d217ddb499032497f46588f939d92a01694b611ad44d872541871da28cfe3e9edd0c917bfdea02e86f8ed3a4fdfef60b59d0be5b7c0c2814a5db7b
2023-12-03 17:14:34 +00:00
Andrew Poelstra 69d0fc7064
Merge rust-bitcoin/rust-bitcoin#2246: Automated nightly rustfmt (2023-12-03)
b7604dd768 2023-12-03 automated rustfmt nightly (apoelstra)

Pull request description:

  Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  apoelstra:
    ACK b7604dd768

Tree-SHA512: 4790ee6088a9fe40103a3824a841a2219354a20e002715d9f21796d5943324b6b3e1f39e7f1356496718cbad1f822dfdde19f4d767473acf32dfe12ddb214ae6
2023-12-03 17:11:26 +00:00
apoelstra b7604dd768 2023-12-03 automated rustfmt nightly 2023-12-03 00:58:10 +00:00
Tobin C. Harding 6a9713a0cc
Add author for the format bot
The format bot defaults to using the person who triggered the workflow.
We can use the `author` option to configure a dummy bot author.
2023-12-02 06:23:46 +11:00
Andrew Poelstra 52366dcad3
Merge rust-bitcoin/rust-bitcoin#2243: Introduce usage of TBD instead of NEXT-RELEASE
c27f101840 Introduce usage of TBD instead of NEXT-RELEASE (Tobin C. Harding)

Pull request description:

  There is an ecosystem-wide solution to our custom usage of `NEXT-RELEASE` in deprecation attributes - use

     `#[decprecated(since = "TBD", note = "use bar instead")]`

  Lets use it.

ACKs for top commit:
  apoelstra:
    ACK c27f101840
  Kixunil:
    ACK c27f101840

Tree-SHA512: 00cbb09f41249402f90e8b2da8c930adca9eec2e4e2684fb26eb844f738245a113788fde392b0b3bf4b5f278057e111ece7a805d0b19e93a4997873ba8051d2f
2023-12-01 17:42:00 +00:00
Tobin C. Harding c27f101840
Introduce usage of TBD instead of NEXT-RELEASE
There is an ecosystem-wide solution to our custom usage of
`NEXT-RELEASE` in deprecation attributes - use

   `#[decprecated(since = "TBD", note = "use bar instead")]`

Lets use it.
2023-12-01 13:26:12 +11:00
Andrew Poelstra a3f6f53d37
Merge rust-bitcoin/rust-bitcoin#2234: Inline io module in the io crate root
f764a607ac Use conventional import path for io crate (Tobin C. Harding)
5c0759a390 Inline io module in io crate root (Tobin C. Harding)
80fe9b99b2 Move public macros to a separate module (Tobin C. Harding)

Pull request description:

  Its not immediately obvious why we nest the whole `io` code in an `io` submodule within `lib.rs`. As far as I can tell we can inline it and re-export from `rust-bitcoin` same as we do for our other dependencies.

  This change would effect other users of the crate but since the `io` crate is unreleased this effects no-one except us.

  After doing this it might be because `crate::io::Foo` looks good when near `std::io::Foo`?

ACKs for top commit:
  apoelstra:
    ACK f764a607ac
  Kixunil:
    ACK f764a607ac

Tree-SHA512: 38888b0c23d5f2cd874f77dd332fe4fa4b9acb90e3a2dac19e62ed3d98151acd7480c719aa85434e1a3de987af2c4f565528a914a14d5fd3f0f0e410cbdf5d40
2023-11-30 19:16:17 +00:00
Tobin C. Harding f764a607ac
Use conventional import path for io crate
We have a convention in `rust-bitcoin` to use external crates directly
when importing them not via `crate::foo`.

Update all the import paths for `io` to use this form.
2023-11-29 08:48:03 +11:00
Andrew Poelstra 8d32a49ac1
Merge rust-bitcoin/rust-bitcoin#2228: Rename from_vb_const
fcc4c40a1c Rename from_vb_const (yancy)

Pull request description:

  The new function is more clear because the purpose of the function is to return a value that doesn't need to be unwrapped.  The current MSRV does not allow unwrap() in const context.

ACKs for top commit:
  apoelstra:
    ACK fcc4c40a1c
  Kixunil:
    ACK fcc4c40a1c

Tree-SHA512: 62bbd61800e9f29768d884dbe3bca14fea9b51b8f413131e0f29bfc0f0d0e20631d30489e078cc948f2dba0c5d7d9d7c229b4bb7187faef23083a88337efb6a6
2023-11-28 20:33:34 +00:00
Andrew Poelstra 2b0e85863f
Merge rust-bitcoin/rust-bitcoin#2229: Fix msrv link
5c0e288afb Fix msrv link (yancy)

Pull request description:

  Link is busted

ACKs for top commit:
  clarkmoody:
    ACK 5c0e288afb
  apoelstra:
    ACK 5c0e288afb
  tcharding:
    tACK 5c0e288afb

Tree-SHA512: 58a6074c6f154e2f83e75ab1f31778a5f7aaeb1c40db292f58d35805fee5f7e2d772fca69589a1b6ee6f3e45b462e95b1e846e7f04ddcccba9c7413699836db4
2023-11-28 14:06:05 +00:00
yancy fcc4c40a1c Rename from_vb_const
The new function is more clear because the purpose of the function is to
return a value that doesn't need to be unwrapped.  The current MSRV does
not allow unwrap() in const context.
2023-11-28 09:01:03 +01:00
Tobin C. Harding 5c0759a390
Inline io module in io crate root
Its not immediately obvious why we nest the whole `io` code in an `io`
submodule within `lib.rs`. As far as I can tell we can inline it and
re-export from `rust-bitcoin` same as we do for our other dependencies.

This change would effect other users of the crate but since the `io`
crate is unreleased this effects no-one except us.
2023-11-28 14:17:14 +11:00
Tobin C. Harding 80fe9b99b2
Move public macros to a separate module
In preparation for inlining the `io` molule, move the public macros to a
private `macros` module.

Includes removal of the public re-export of `std` as `_std` - flaggin
this because I do not understand why it is here in the first place, we
can use `std::io::Write` in code that is feature gated on "std".
2023-11-28 11:43:35 +11:00
Andrew Poelstra 64bd34cffb
Merge rust-bitcoin/rust-bitcoin#2227: add conversions from TXIDs to merkle nodes
32eb461523 add conversions from TXIDs to merkle nodes (conduition)

Pull request description:

  Fixes https://github.com/rust-bitcoin/rust-bitcoin/issues/2220.

  Also adds the equivalent conversion trait from `Wtxid` -> `WitnessMerkleNode`.

ACKs for top commit:
  Kixunil:
    ACK 32eb461523
  apoelstra:
    ACK 32eb461523

Tree-SHA512: 61cf5548874388dd927feaa50f3c7c7e9f3ac4f7498f6335835499dec93916b5f7ed2bdf91ec27edc977fb5e811f946364d477d4aa25d0aa51b0c618f727d3d2
2023-11-27 18:36:20 +00:00
yancy 5c0e288afb Fix msrv link 2023-11-27 11:45:22 +01:00
conduition 32eb461523 add conversions from TXIDs to merkle nodes 2023-11-27 00:12:16 +00:00
Andrew Poelstra cfa6768e79
Merge rust-bitcoin/rust-bitcoin#2221: Implement LowerHex and UpperHex for CompactTarget
58710dfb91 Implement LowerHex and UpperHex for CompactTarget (Vojtěch Toman)

Pull request description:

  closes #2219

ACKs for top commit:
  Kixunil:
    ACK 58710dfb91
  apoelstra:
    ACK 58710dfb91

Tree-SHA512: 38d8bd6573f0f033f5f0948062174f7a49db02d788a5176375a869633984451651bc738cd0588d5c6e4515f521257899bdf9f61fd4be350d80a26a96f16b19b1
2023-11-26 14:32:47 +00:00
Andrew Poelstra 65050db725
Merge rust-bitcoin/rust-bitcoin#2222: Remove nightly rustfmt check from pre-commit githook
5a3f1a6180 Remove nightly rustfmt check from pre-commit githook  See #2135 (Vojtěch Toman)

Pull request description:

  See #2135 and discussion [#2219#issuecomment-1826437013](https://github.com/rust-bitcoin/rust-bitcoin/issues/2219#issuecomment-1826437013)

ACKs for top commit:
  Kixunil:
    ACK 5a3f1a6180
  apoelstra:
    ACK 5a3f1a6180

Tree-SHA512: 3fabadcbc4f80fb133318138aad8e1baccbeffad57d09fe86ed12f1156e8c9505911f8fc3a785896832fad02e20a366e9d95d37602bdd5fc02d9c715a867cb72
2023-11-26 14:17:27 +00:00
Andrew Poelstra b137649e3d
Merge rust-bitcoin/rust-bitcoin#2223: Automated nightly rustfmt (2023-11-26)
1c89e07537 2023-11-26 automated rustfmt nightly (apoelstra)

Pull request description:

  Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  Kixunil:
    ACK 1c89e07537
  apoelstra:
    ACK 1c89e07537

Tree-SHA512: 89f39fb936b3f3c94bd57a05fa98e4f49a4af62cb9bdbc0046a79aef3cc37371d4e7b71b38744621669238d503793992c72a9a7aa5428e0f20b8d884f1731be3
2023-11-26 14:16:56 +00:00
Andrew Poelstra 4806461c75
Merge rust-bitcoin/rust-bitcoin#2188: Bump MSRV to Rust version 1.56.1
761de886be Remove imports of TryFrom and TryInto (Tobin C. Harding)
4d5415f835 Add rust-version to the workspace manifests (Tobin C. Harding)
a41e978855 Update to edition 2021 (Tobin C. Harding)
d9cc724187 Bump MSRV to Rust version 1.56.1 (Tobin C. Harding)

Pull request description:

  Rust version 1.56.0 introduced edition 2021. Shortly afterwards, on October 21 2021 Rust version 1.56.1 was released.

  Debian stable is currently shipping `rustc 1.63.0`. Our stated MSRV policy is: In Debian stable and at least 2 years old. Therefore our MSRV policy is met by Rust version 1.56.1 and we can strat to bump our MSRV org wide. Start by bumping the `rust-bitcoin` and `hashes` MSRV to Rust 1.56.1

  Start by bumping the `rust-bitcoin` and `hashes` MSRV to Rust 1.56.1, includes:

  - Update docs.
  - Update CI and remove pinning.
  - Update the build files and remove now stale cfg attributes rust_v_1_x for values less than the new MSRV.
  - Use new `IntoIterator` for arrays so we no longer need to allocate a vector to iterate.

  Links:

  - https://blog.rust-lang.org/2021/11/01/Rust-1.56.1.html
  - https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html
  - https://packages.debian.org/stable/rust/rustc

ACKs for top commit:
  Kixunil:
    ACK 761de886be
  apoelstra:
    ACK 761de886be

Tree-SHA512: 3a81c8bfa37d8cec0ec794f516f014da67ae8e437decf149c9681aa547885acac0ee07ea2c0f42e4f6bfd6f7ed1695fcf4747f53cc50e5f4e70ce3fe7bcba4e9
2023-11-26 13:48:23 +00:00
apoelstra 1c89e07537 2023-11-26 automated rustfmt nightly 2023-11-26 00:57:53 +00:00
Vojtěch Toman 5a3f1a6180
Remove nightly rustfmt check from pre-commit githook See #2135 2023-11-25 23:45:19 +01:00
Vojtěch Toman 58710dfb91
Implement LowerHex and UpperHex for CompactTarget 2023-11-25 23:26:57 +01:00
Tobin C. Harding 761de886be
Remove imports of TryFrom and TryInto
Now that MSRV is Rust 1.56.1 we no longer need to explicitly import
`TryFrom` and `TryInto`.

No clue why clippy didn't find these for us.
2023-11-24 03:52:05 +11:00
Andrew Poelstra 71d92bdbb9
Merge rust-bitcoin/rust-bitcoin#2095: bitcoin: Add signing examples
fa104aefa5 bitcoin: Add signing examples (Tobin C. Harding)

Pull request description:

  Add two signing examples to showcase signing a simple one input two output transaction using both segwit v0 outputs and taproot outputs.

  This patch is the result of the recent rust-bitcoin TABConf workshop, with bug fix by Sanket, updated to use APIs from tip of master branch.

  This code, depending on v0.30.0 is what was added to the cookbook.

ACKs for top commit:
  realeinherjar:
    ACK fa104aefa5
  apoelstra:
    ACK fa104aefa5

Tree-SHA512: ce0d5b8291c94387c68b5e1cf740d3267fc00c997af5b96f5be525f348140d9a9af17ab66d556990f09bf081a5a812374cb633ea276100c7c21f218b85eae3fd
2023-11-22 22:08:32 +00:00
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
Tobin C. Harding 4d5415f835
Add rust-version to the workspace manifests
Add `rust-version = 1.56.1` to all crates in the workspace i.e.,
including `fuzz` but excluding the various test crates.
2023-11-23 06:20:04 +11:00
Tobin C. Harding a41e978855
Update to edition 2021
We just bumped the MSRV to Rust 1.56.1 which includes edition 2021.

Update all crates in this repo to use edition 2021 and build/lint
warnings.
2023-11-23 06:20:03 +11:00
Tobin C. Harding d9cc724187
Bump MSRV to Rust version 1.56.1
Rust version 1.56.0 introduced edition 2021. Shortly afterwards, on
October 21 2021 Rust version 1.56.1 was released.

Debian stable is currently shipping `rustc 1.63.0`.

Our stated MSRV policy is: In Debian stable and at least 2 years old.

Therefore our MSRV policy is met by Rust version 1.56.1 and we can strat
to bump our MSRV org wide.

Start by bumping the `rust-bitcoin` and `hashes` MSRV to Rust 1.56.1,
includes:

- Update docs.
- Update CI and remove pinning.
- Update the build files and remove now stale cfg attributes rust_v_1_x
  for values less than the new MSRV.
- Use new `IntoIterator` for arrays so we no longer need to allocate a
  vector to iterate.

Links:

- https://blog.rust-lang.org/2021/11/01/Rust-1.56.1.html
- https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html
- https://packages.debian.org/stable/rust/rustc
2023-11-23 06:20:02 +11:00