Commit Graph

762 Commits

Author SHA1 Message Date
Dr Maxim Orlovsky d655ff3e93
Make TapTreeIterator use LeafInfo
Previously used depth and script tuple missed information about the leaf version. 
All three comprises already existing type `LeafInfo` which was made public in 
previous commits.
2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky 79345fcd02
LeafInfo field accessor methods 2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky 5958466678
Make LeafInfo::leaf_hash public and change its name and return type 2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky c83893d497
Make taproot LeafInfo public
LeafInfo structure is a useful form of representing leaf script information (script, leaf version and merkle proof).
2022-04-19 20:31:49 +02:00
Andrew Poelstra 8ca18f75dd
Merge rust-bitcoin/rust-bitcoin#929: Fix TapTree hidden branches bug
c036b0db6f Unit test for failing TapTree on builder containing hidden nodes. (Dr Maxim Orlovsky)
77715311cf Prevent TapTree from hidden parts (Dr Maxim Orlovsky)
b0f3992db1 Rename TaprootBuilder::is_complete into is_finalized (Dr Maxim Orlovsky)
efa800fb1f Make TapTree::from_inner return a proper error type (Dr Maxim Orlovsky)
e24c6e23e3 TapTree serialization roundtrip unit test (Dr Maxim Orlovsky)
56adfa4527 TaprootBuilder::has_hidden_nodes method (Dr Maxim Orlovsky)
e69701e089 Rename taproot `*_hidden` API into `*_hidden_nodes` (Dr Maxim Orlovsky)
6add0dd9dc Track information about hidden leaves in taproot NodeInfo (Dr Maxim Orlovsky)

Pull request description:

  Closes #928

ACKs for top commit:
  sanket1729:
    ACK c036b0db6f. Reviewed the range diff
  apoelstra:
    ACK c036b0db6f

Tree-SHA512: 3a8193e6d6dd985da30a2094d1111471b5971f422525870003b77b6ac47cd4ad6e718d46a6d86bbb5e92e5253ac53804badf67edd98bbccbdc11e6383c675663
2022-04-14 17:03:14 +00:00
Dr Maxim Orlovsky c036b0db6f
Unit test for failing TapTree on builder containing hidden nodes. 2022-04-05 22:43:52 +02:00
Dr Maxim Orlovsky 77715311cf
Prevent TapTree from hidden parts 2022-04-05 22:30:34 +02:00
Dr Maxim Orlovsky b0f3992db1
Rename TaprootBuilder::is_complete into is_finalized 2022-04-05 22:29:32 +02:00
Dr Maxim Orlovsky efa800fb1f
Make TapTree::from_inner return a proper error type 2022-04-05 22:29:20 +02:00
Dr Maxim Orlovsky e24c6e23e3
TapTree serialization roundtrip unit test 2022-04-05 22:18:23 +02:00
Dr Maxim Orlovsky 56adfa4527
TaprootBuilder::has_hidden_nodes method 2022-04-05 22:18:00 +02:00
Dr Maxim Orlovsky e69701e089
Rename taproot `*_hidden` API into `*_hidden_nodes` 2022-04-05 22:16:59 +02:00
Dr Maxim Orlovsky 6add0dd9dc
Track information about hidden leaves in taproot NodeInfo 2022-04-05 22:16:27 +02:00
Tobin Harding 29843c41ef Allow deprecated function call
We have a deprecated function call because of the MSRV, tell clippy to
ignore it.
2022-04-04 18:28:09 +10:00
sanket1729 cb4d34fd40
Merge rust-bitcoin/rust-bitcoin#932: Derive Eq for PSBT types
603e75eb77 Derive Eq for PSBT types (Dr Maxim Orlovsky)

Pull request description:

  Closes #931

ACKs for top commit:
  apoelstra:
    ACK 603e75eb77
  sanket1729:
    utACK 603e75eb77.

Tree-SHA512: 8099e80aa2000b3d1284543b6bfab3edd45f8649519bd09b4d73d250bdb6cce5edf67a1e0e0cec61db23c358daca286061641da5ff5c2a8b4b030d1199707c94
2022-04-01 11:38:45 -07:00
sanket1729 7fa8ce0bd0
Merge rust-bitcoin/rust-bitcoin#926: Remove redundant code computing tap hashes
f3ebfd6f8b Remove repeated tap branch hash computing logic (Dr Maxim Orlovsky)
1b28375658 Abstract tap branch hash computing into a dedicated method (Dr Maxim Orlovsky)

Pull request description:

ACKs for top commit:
  apoelstra:
    ACK f3ebfd6f8b

Tree-SHA512: d66d544df324a7d25c8cc9dc48ddedf086ac87eb2ed09a8d7a568cc1488ae44e0807d53ccb7a6e61dbeef0d3d62a1cacf0d69ba7b8de9178ac5c13bae944d08b
2022-04-01 11:35:14 -07:00
Andrew Poelstra 9316c52946
Merge rust-bitcoin/rust-bitcoin#917: Rename SigHash to Sighash
46c34b3fb7 Fix code comments referring to sighash (Tobin Harding)
8f36c3979c Use sighash not sig_hash in identifiers (Tobin Harding)
c3a167b96b Rename SigHash -> Sighash (Tobin Harding)
52b711c084 Rename InvalidSigHashType -> InvalidSighashType (Tobin Harding)
b84f25584e Rename SigHashCache -> SighashCache (Tobin Harding)
e37652578b Rename PsbtSigHashType -> PsbtSighashType (Tobin Harding)
c19ec339ef Rename NonStandardSigHashType -> NonStandardSighashType (Tobin Harding)
130e27349e Rename SigHashTypeParseError -> SighashTypeParseError (Tobin Harding)
6caba2ed24 Rename SchnorrSigHashType -> SchnorrSighashType (Tobin Harding)
5522454583 Rename EcdsaSigHashType -> EcdsaSighashType (Tobin Harding)

Pull request description:

  Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash' is a well known word in the Bitcoin ecosystem it should appear in identifiers as `Sighash`.

  Change various types, variants, and code comments to use sighash as a single word.

  - Patches 1-8 are code changes `s/SigHash/Sighash/g`
  - Patch 9 is code changes `s/sig_hash/sighash/g`
  - Patch 11 is docs fixes

  Fixes: #911

  ## Note to reviewers

  I've been particularly pedantic with the patch separation because we are so close to release.

  Done as separate patches to make review easier if review is to be done by reading the diffs. Perhaps at least one person could verify this PR programmatically by doing
  - Reset the last 2 patches (those are easy to do manually)
  - Check out master
  - Do `s/SigHash/Sighash/g` on all source files (bash function below)
  - Use `git diff branchA..branchB` to verify

  The difference between the two branches should only include comment lines (last three patches) and these seven instances of `SigHash:

  ```
  CHANGELOG.md:82:- [Add FromStr/Display implementation for SigHashType](a4a7035a94)
  CHANGELOG.md:93:- [Introduce `SigHashCache` structure](https://github.com/rust-bitcoin/rust-bitcoin/pull/390) to replace `SighashComponents` and support all sighash modes
  CHANGELOG.md:121:    - `SigHash`
  src/blockdata/transaction.rs:1190:            "SigHash_None",
  src/blockdata/transaction.rs:1191:            "SigHash_NONE",
  src/util/sighash.rs:1175:            "SigHash_None",
  src/util/sighash.rs:1176:            "SigHash_NONE",
  ```

  In case its useful, the shell function I used to do these changes is:
  ```bash
  function search-and-replace() {
      if (($# != 2))
      then
          echo "Usage: $0 <this> <that>"
          return
      fi

      local this="$1"
      local that="$2"

      # For all files containing $this, replace $this with $that.
      for file in $(git grep -l "$this")
      do
          perl -pi -e "s/$this/$that/g" "$file"
      done
  }
  ```

ACKs for top commit:
  dr-orlovsky:
    ACK 46c34b3fb7
  apoelstra:
    ACK 46c34b3fb7

Tree-SHA512: fe7e25e9cfb5155e4921de5ac185dbf9f4ca0770846d7892f6968b44fc5431f3f1a183380107449e90f7ea662094c60b118dc0468230384e8f9a8ef98d5ee0a0
2022-04-01 17:30:42 +00:00
sanket1729 efbe1417fe
Merge rust-bitcoin/rust-bitcoin#923: Taproot docs nits
da731c4825 Add further description to the NodeInfo struct (Tobin Harding)
492ccebd99 Use links for error types (Tobin Harding)
3e05887579 Use 'the' to improve sentence (Tobin Harding)

Pull request description:

  See to nits from review of https://github.com/rust-bitcoin/rust-bitcoin/pull/912

  Three minor patches to the `taproot` module docs.

  CC @dr-orlovsky

ACKs for top commit:
  dr-orlovsky:
    ACK da731c4825
  sanket1729:
    ACK da731c4825

Tree-SHA512: 17a27a19c88f9baa8127023b2ee30fc2259cb0058a92dc9d8ae595e9e02ccb047fefcba7548ff7900fffa7bc6853447183e80660b8756d90d055ab8aa96ae938
2022-04-01 08:55:57 -07:00
Dr Maxim Orlovsky 603e75eb77 Derive Eq for PSBT types 2022-04-01 11:45:32 +02:00
Dr Maxim Orlovsky f3ebfd6f8b
Remove repeated tap branch hash computing logic 2022-03-31 15:21:36 +02:00
Dr Maxim Orlovsky 1b28375658
Abstract tap branch hash computing into a dedicated method 2022-03-31 15:16:39 +02:00
Dr Maxim Orlovsky e3f173e521
Require taproot tree depth argument always to be u8 2022-03-31 15:12:05 +02:00
Tobin Harding da731c4825 Add further description to the NodeInfo struct
Further assist devs in understanding the `NodeInfo` struct by adding
docs about when/why the struct is used.
2022-03-31 10:57:37 +11:00
Tobin Harding 492ccebd99 Use links for error types
We can help the users by linking them to errors when mentioning them in
the docs.
2022-03-31 10:57:05 +11:00
Tobin Harding 3e05887579 Use 'the' to improve sentence
Adding a 'the' makes this sentence a little better.
2022-03-31 10:56:36 +11:00
Tobin Harding 46c34b3fb7 Fix code comments referring to sighash
Recently we added a bunch of additional sighash types, some of the code
comments became stale. Use the non-specific term 'sighash type' instead
of a particular sighash identifier in comments to make the comments more
applicable.
2022-03-31 09:44:22 +11:00
Tobin Harding 8f36c3979c Use sighash not sig_hash in identifiers
Recently we update all types and docs to use `Sighash` instead of
`SigHash` because 'sighash' is a single word. We should apply the same
logic to functions and variable names.

Do not use an underscore in the identifier 'sighash'.
2022-03-31 09:42:52 +11:00
Tobin Harding c3a167b96b Rename SigHash -> Sighash
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename the `SigHash` type to `Sighash`.
2022-03-31 09:42:52 +11:00
Tobin Harding 52b711c084 Rename InvalidSigHashType -> InvalidSighashType
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename the `InvalidSigHashType` variant to `InvalidSighashType`.
2022-03-31 09:42:52 +11:00
Tobin Harding b84f25584e Rename SigHashCache -> SighashCache
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename `SigHashCache` to `SighashCache`.
2022-03-31 09:42:52 +11:00
Tobin Harding e37652578b Rename PsbtSigHashType -> PsbtSighashType
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename `PsbtSigHashType` to `PsbtSighashType`.
2022-03-31 09:42:18 +11:00
Tobin Harding c19ec339ef Rename NonStandardSigHashType -> NonStandardSighashType
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename the `NonStandardSigHashType` type and error variant to
`NonStandardSighashType`.
2022-03-31 09:42:18 +11:00
Tobin Harding 130e27349e Rename SigHashTypeParseError -> SighashTypeParseError
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename `SigHashTypeParseError` to `SighashTypeParseError`.
2022-03-31 09:42:18 +11:00
Tobin Harding 6caba2ed24 Rename SchnorrSigHashType -> SchnorrSighashType
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename `SchnorrSigHashType` to `SchnorrSighashType`.
2022-03-31 09:42:18 +11:00
Tobin Harding 5522454583 Rename EcdsaSigHashType -> EcdsaSighashType
Our usage of `SigHash` implies that 'sighash' is _two_ words; 'sighash'
is a well known word in the Bitcoin ecosystem it should appear in
identifiers as `Sighash`.

Rename `EcdsaSigHashType` to `EcdsaSighashType`.
2022-03-31 09:42:18 +11:00
Dr. Maxim Orlovsky 58a958e3f7
Merge rust-bitcoin/rust-bitcoin#912: Improve docs in taproot module
c25eddd187 Remove unnecessary documentation (Tobin Harding)
8631474f08 Improve docs in taproot module (Tobin Harding)

Pull request description:

  I should have done this PR a month ago, my bad. This one is kind of important IMO because we are going to have so many people looking at this part of the code soon as we release.

  As has been done in other places in the codebase; improve the docs in the `taproot` module by doing:

  - Use full sentences (capital letters + full stops)
  - Use back ticks and links for types where appropriate
  - Fix grammar
  - Fix stale docs
  - Use third person for describing functions
  - Use 100 character line width
  - Use markdown sections (`# Examples`, `# Returns`) where appropriate
  - Separate brief heading from extended description when appropriate
  - Use `///` for all functions/types (both private and public)

  I also did:

  - Build the docs and check all the links
  - Read all the built docs, check for sanity and pretty-ness

  Its all in one patch, I couldn't really tease it apart. I can try a bit harder if it proves too annoying to review.

ACKs for top commit:
  sanket1729:
    ACK c25eddd187
  dr-orlovsky:
    ACK c25eddd187
  apoelstra:
    ACK c25eddd187

Tree-SHA512: 72f35bf8779392060388db985df5abc42a89796eaad1eafd08ea50b635d469fbd07a53ff253cdf27ad4d4baed7d37cec6ea1da1aece3672b9447f87181e218f8
2022-03-30 19:30:14 +03:00
Tobin Harding 8d602b8778 Fix deprecated since version
We deprecated the `bip143::SigHashCache` in

```
commit 53d0e176d3
Author: <elided>
Date:   Fri Jul 16 10:44:18 2021 +0200

    Deprecate bip143::SigHashCache in favor of sighash::SigHashCache

    ...
```

This means these changes are unreleased so the deprecated since version
should be the upcoming 0.28 release.
2022-03-29 10:59:17 +11:00
Tobin Harding c25eddd187 Remove unnecessary documentation
We have some text quoted directly from BIP341, this text is on the net
if folk wish to read it, we don't need it in the source code.
2022-03-29 10:28:29 +11:00
Tobin Harding 8631474f08 Improve docs in taproot module
As has been done in other places in the codebase; improve the docs in
the `taproot` module by doing:

- Use full sentences (capital letters + full stops)
- Use back ticks and links for types where appropriate
- Fix grammar
- Fix stale docs
- Use third person for describing functions
- Use 100 character line width
- Use markdown sections (`# Examples`, `# Returns`) where appropriate
- Separate brief heading from extended description when appropriate
- Use `///` for all functions/types (both private and public)

I also did:

- Build the docs and check all the links
- Read all the built docs, check for sanity and pretty-ness
2022-03-29 10:27:45 +11:00
Dr Maxim Orlovsky 174a99cd06
Implement serde for TweakedKeyPair 2022-03-28 21:29:04 +02:00
Dr Maxim Orlovsky df3297c34e
Implement derives for TweakedKeyPair 2022-03-28 21:28:43 +02:00
Andrew Poelstra b32d40390c
Merge rust-bitcoin/rust-bitcoin#898: Make PsbtSigHashType use the same formatting as other *SigHashTypes
992857ad0a PsbtSighashType unit tests (Dr Maxim Orlovsky)
5be1cdb8c7 PsbtSigHashType Display and FromStr implementation (Dr Maxim Orlovsky)
7cdcdaad6c Support SIGHASH_RESERVED in SchnorrSigHashType::from_u8 (Dr Maxim Orlovsky)

Pull request description:

  The newly introduced `PsbtSigHashType` uses very different serde formatting from previously used `EcdsaSigHashType`; for instance it does not output human-readable sighash. This is especially obvious when printing out PSBT as JSON/YAML object and is a breaking change from the `0.27`. Serde human-readable implementation requires `Display/FromStr`, which were also absent.

ACKs for top commit:
  sanket1729:
    ACK 992857ad0a. This is much better
  apoelstra:
    ACK 992857ad0a

Tree-SHA512: 71a46471f34b5481e4c1273a66846f59d61bfd98fcb65e7823ca216ff0dd419d81ca86d99c7aaf674fcfe2b1c010e899c8e74328f60a1e809015c663c453cc89
2022-03-28 17:34:20 +00:00
Andrew Poelstra 0d5565e131
Merge rust-bitcoin/rust-bitcoin#839: feat: Add Address.is_related_to_*_key()
51fef76129 feat: Add Address.is_related_to_pubkey() (Andrew Ahlers)

Pull request description:

  ## Motivation

  This is addressing the second half of this comment: https://github.com/rust-bitcoin/rust-bitcoin/pull/684#issuecomment-1012136845

  > but would accept a PR (or two PRs) that returns Result<bool, UnsupportedAddress> and a method to check if a PublicKey is associated with an address.

  (The first half was addressed [here](https://github.com/rust-bitcoin/rust-bitcoin/pull/819))

  These changes will help build out and improve message signature verification. We don't necessarily need to add it to this crate but it allows for easy verification with something such as:
  1. recovering a pubkey
  2. checking if that pubkey relates to the given address

  ## Possible Improvements

  - There is likely a better name than `is_related_to_secp256k1_key()`
  - This could drop the `secp256k1` part of the name and take in a Pubkey enum that also supports Schnorr pubkeys and then this could be used for taproot addresses as well. This felt like a much larger change that will likely get turned down. Verifying taproot is simple enough and if absolutely desired, similar functions can be added for schnorr keys (tweaked and untweaked)

ACKs for top commit:
  Kixunil:
    ACK 51fef76129 for merging after TR
  apoelstra:
    ACK 51fef76129

Tree-SHA512: c9ab8c0f101fb4c647713e7f500656617025d8741676e8eb8a3132009dde9937d50cf9ac3d8055feb14452324a292397e46639cbaca71cac77af4b06dc42d09d
2022-03-28 17:29:48 +00:00
Dr Maxim Orlovsky 8dabe3ed64
Taproot Huffman tree builder u64->u32 fixes 2022-03-28 17:15:28 +02:00
Andrew Poelstra 7f53c2cdc1
Merge rust-bitcoin/rust-bitcoin#909: Make TaprootBuilder able to generate Huffman Tree
ec17ec356d Move with_huffman_tree logic to TaprootBuilder (Jeremy Rubin)

Pull request description:

  .

ACKs for top commit:
  apoelstra:
    ACK ec17ec356d
  dr-orlovsky:
    utACK ec17ec356d

Tree-SHA512: 67a013124267f64bfae0b2007418ad59a42ae64d8b95e23c1d86cc7d96b0dd3b48deb255ce7bb839ef9a4d4f2e3a42d691d2d2430eb7791e01f992635773cc96
2022-03-28 15:08:21 +00:00
Dr Maxim Orlovsky 992857ad0a
PsbtSighashType unit tests 2022-03-28 17:03:44 +02:00
Dr Maxim Orlovsky 5be1cdb8c7
PsbtSigHashType Display and FromStr implementation 2022-03-28 17:03:34 +02:00
Dr Maxim Orlovsky 7cdcdaad6c
Support SIGHASH_RESERVED in SchnorrSigHashType::from_u8 2022-03-28 16:53:31 +02:00
Andrew Poelstra 10949b7177
Merge rust-bitcoin/rust-bitcoin#910: Make NodeInfo API public
208eb65f1b Make NodeInfo API public (sanket1729)

Pull request description:

  Reported by @shesek. Users might find it convenient to manually construct the tree using `NodeInfo` API

  ```rust
  let leaf1 = NodeInfo::from_leaf_with_ver();
  let leaf2 = NodeInfo::from_leaf_with_ver();

  let root = NodeInfo::combine(leaf1, leaf2);
  let spend_info = TaprootSpendInfo::from_node_info(&secp, internal_key, root);
  ```

ACKs for top commit:
  dr-orlovsky:
    ACK 208eb65f1b
  apoelstra:
    ACK 208eb65f1b

Tree-SHA512: b5a6b26e0d4a637f7ad6e987976b31b00d3567feca85f1a0bf63aa03603aded0ddae6578b1cabc1056870a596b8cb1a83e4ef3f45802e03da80c3d58d9bab1f1
2022-03-28 14:02:26 +00:00
Andrew Poelstra 388897bf93
Merge rust-bitcoin/rust-bitcoin#901: TapTree iterator
e27f8ff594 TapTree iterator implementation (Dr Maxim Orlovsky)

Pull request description:

  Implemented after @sanket1729 suggestion in https://github.com/rust-bitcoin/rust-bitcoin/issues/895#issuecomment-1074366108

  Iterates all scripts present in TapTree in DFS order returning `(depth, script)` pairs.

  I propose to have it as an RC fix since this functionality is really lacking and may be required for many wallets working with Taproot PSBT even outside of the scope where I originally needed it (OP_RETURN tweaks for TapTree described in #895)

ACKs for top commit:
  sanket1729:
    utACK e27f8ff594.
  apoelstra:
    ACK e27f8ff594

Tree-SHA512: b398e468a10534561297f22dba47e340391069734a41999edd85d726890752035053690a22014402879ea40b948160f00310f78771443d382c0bbaf0201dfbe5
2022-03-28 13:45:34 +00:00