Commit Graph

1148 Commits

Author SHA1 Message Date
Andrew Poelstra b327386cc8
Merge rust-bitcoin/rust-bitcoin#799: Use 4 character indentation
8d780e8172 Use 4 character indentation (Tobin Harding)

Pull request description:

  Bizarrely the impl block for `EcdsaSigHashType` uses 5 character indentation.

  Use 4 character indentation as is typical.

ACKs for top commit:
  Kixunil:
    ACK 8d780e8172
  apoelstra:
    ACK 8d780e8172

Tree-SHA512: 4b0789b4ef6f3e817fcbe002ca0d9ee4fca4a3dc70bbeaebae745a2f0497eb072f3c3876805d97ff58eb8a9464ea4443f23cea0c95bfd052e382caa9f76b515d
2022-01-19 18:57:48 +00:00
Riccardo Casatta 1f0810ad6e
Merge rust-bitcoin/rust-bitcoin#790: Re-export psbt module from root level
b138428df7 Re-export public map types from root level (Tobin Harding)

Pull request description:

  We currently have the `map` module private but containing a bunch of types that are needed in the public API (specifically in a `PartiallySignedTransaction`).

  To give access to them re-export the `util::psbt` module at the root level.

  Found while testing `master` with `rust-miniscript`.

ACKs for top commit:
  sanket1729:
    utACK b138428df7
  Kixunil:
    ACK b138428df7
  RCasatta:
    ACK b138428df7
  dr-orlovsky:
    ACK b138428df7

Tree-SHA512: 36fc8595164c4975abdadb6c8149ef27686a2d681a1815379f91b1bd36f8a56ceaa7faed5979ba6869823684790721a16a0c41e662c6227a09cd0ba576a0a181
2022-01-19 12:18:14 +01:00
Tobin Harding 151173821b Use fn name to_ instead of into_
Rust convention is to use `to_` for conversion methods that convert from
an owned type to an owned `Copy` type. `into_` is for owned to owned
non-`Copy` types.

Re-name conversion methods that use `into_` for `Copy` types to use
`to_`, no need to deprecate these ones because they are unreleased.
2022-01-19 14:59:18 +11:00
Tobin Harding 8d780e8172 Use 4 character indentation
Bizarrely the impl block for `EcdsaSigHashType` uses 5 character
indentation.

Use 4 character indentation as is typical.
2022-01-19 14:30:36 +11:00
Andrew Poelstra 64451a2144
Merge rust-bitcoin/rust-bitcoin#794: Refactor use map_err
9f848472e4 Refactor use map_err (wim-web)

Pull request description:

  issue: https://github.com/rust-bitcoin/rust-bitcoin/issues/793

  change to using map_err

ACKs for top commit:
  Kixunil:
    ACK 9f848472e4
  apoelstra:
    ACK 9f848472e4

Tree-SHA512: 93dac16463bf84825f764f3ef81833c27722a52f56737d30f14160d070959ad13bbfdf5f3c4871b961ce05fa9f75ed36acbacaa40ff6ba3bbf449b9c9173c0c7
2022-01-18 20:55:31 +00:00
wim-web 9f848472e4 Refactor use map_err 2022-01-18 13:20:53 +09:00
Tobin Harding b138428df7 Re-export public map types from root level
We currently have the `map` module private but containing a bunch of
types that are needed in the public API (specifically in a
`PartiallySignedTransaction`).

Re-export the publicly required types to the `psbt` module and then
again at the root level of `rust-bitcoin` as we do for other types.
2022-01-18 12:56:47 +11:00
Andrew Poelstra 8acdb1ab64
Merge rust-bitcoin/rust-bitcoin#786: Fix unused arg in PSBT impl_psbt_get_pair macro
1b77e3609c Fix unused arg in PSBT impl_psbt_get_pair macro (Dr Maxim Orlovsky)

Pull request description:

  Closes #754

ACKs for top commit:
  apoelstra:
    ACK 1b77e3609c
  RCasatta:
    utACK 1b77e3609c
  Kixunil:
    ACK 1b77e3609c

Tree-SHA512: 339aae0a9b6adef34bc6bca27ea19eb89205c4b4694e3a95721590696b7eefbfded9294fd9101a66110b4bdfb69da7a7ef97a8e8321d9e05b3777c3fa9afff7c
2022-01-17 19:54:29 +00:00
Dr. Maxim Orlovsky 6cca59296e
Merge rust-bitcoin/rust-bitcoin#791: Remove trailing spaces from 'address.rs'
4284c2be3b Remove trailing spaces from 'address.rs' (Roman Zeyde)

Pull request description:

ACKs for top commit:
  dr-orlovsky:
    ACK 4284c2be3b
  Kixunil:
    ACK 4284c2be3b

Tree-SHA512: 62fb1ea934ed0e089766db84d1a9a218a922272555d89081f5e47ac3a9d236474c8218e1873251961a9562405817e16f2f1ea84731f330813b21898015c1cabd
2022-01-17 12:15:48 +02:00
Dr. Maxim Orlovsky d5686ee01d
Merge rust-bitcoin/rust-bitcoin#776: Change EcdsaSig hash type deser in psbt
abe52f681b Cleanup/Dedup psbt (De)Serialization code (sanket1729)
fbd86dcf63 Update documentation of EcdsaSig::from_slice (sanket1729)
85009a7b50 Update documentation of from_u32_consensus (sanket1729)
0fed04e2d5 Change EcdsaSig hash type deser (sanket1729)

Pull request description:

  Changes the parsing behavior in PSBT on non-standard sighash types to give an explicit error, rather than silently mangling the parsed value

ACKs for top commit:
  dr-orlovsky:
    ACK abe52f681b
  apoelstra:
    ACK abe52f681b
  Kixunil:
    ACK abe52f681b

Tree-SHA512: 1d5dbe3aa5885ca16649cf8ea05a7476e8dd977dd870b79358d97a3ce383bee93754d2b88163e7db3792cdc4b9cb867356409c8eea4e110877577ad196ba0786
2022-01-17 12:08:18 +02:00
Roman Zeyde 4284c2be3b Remove trailing spaces from 'address.rs' 2022-01-17 10:03:17 +02:00
Dr Maxim Orlovsky 1b77e3609c Fix unused arg in PSBT impl_psbt_get_pair macro
Closes #754
2022-01-16 11:59:29 +01:00
sanket1729 093f8b612d
Merge rust-bitcoin/rust-bitcoin#752: Make Map trait private
dfd8924398 Remove insert_pair from Map trait (Tobin Harding)
ad75d5181f Make Map trait private to psbt module (Tobin Harding)
53225c0a6e Improve docs in map module (Tobin Harding)
92059c2841 Add full stops to rustdocs (Tobin Harding)
11c046b707 Refactor match arms (Tobin Harding)
e6af569490 Move imports to top of file (Tobin Harding)

Pull request description:

  The `Map` method `insert_pair` is never called for `PartiallySignedTransaction`. Separate the method into its own trait (`Insert`) and delete dead code. The dead code contains the alleged bug in #576.

  - Patch 1: Preparatory cleanup
  - Patch 2: Preparatory refactor
  - Patch 3 and 4: Improve docs in the module that this PR touches
  - Patch 5: Make `Map` trait private to the `psbt` module
  - ~Patch 6: Make `concensus_decode_global` method into a function~
  - Patch ~7~ 6: Pull `insert_pair` method out of `Map` trait into newly create `Insert` trait

  Resolves: https://github.com/rust-bitcoin/rust-bitcoin/issues/576

  (Title of PR is `Make Map trait private` because that is the API break.)

ACKs for top commit:
  dr-orlovsky:
    ACK dfd8924398
  apoelstra:
    ACK dfd8924398

Tree-SHA512: 1a78294bc8a455552d93caf64db697f886345ba979f574abad55820415958fee1c2dd16945f4eafdbe542fa202cb7e08618aa137ec7ee22b3c9dac5df0328157
2022-01-16 08:49:27 +05:30
sanket1729 abe52f681b Cleanup/Dedup psbt (De)Serialization code 2022-01-15 06:15:54 +05:30
sanket1729 fbd86dcf63 Update documentation of EcdsaSig::from_slice 2022-01-15 06:15:14 +05:30
sanket1729 85009a7b50 Update documentation of from_u32_consensus 2022-01-15 06:15:14 +05:30
sanket1729 0fed04e2d5 Change EcdsaSig hash type deser 2022-01-15 06:15:10 +05:30
sanket1729 d1f051c95a
Merge rust-bitcoin/rust-bitcoin#757: Minimally-invasive separation of bitcoin keys from ECDSA signature types
8a993e8a58 Properly deprecate util::ecdsa key re-exports (Dr Maxim Orlovsky)
bcb8932ccf Re-org keys and ecdsa mods - pt.3 (Dr Maxim Orlovsky)
d1c2213d3b Re-org keys and ecdsa mods - pt.2 (Dr Maxim Orlovsky)
b9170162d5 Re-org keys and ecdsa mods - pt.1 (Dr Maxim Orlovsky)
2d9de78725 Re-export all key types under `util::key`. Deprecate other exports. (Dr Maxim Orlovsky)

Pull request description:

  This PR tries to do a minimally-invazive separation of signature- and key-related types, previously mixed in a single `util::ecdsa` module.

  Rationale: bitcoin key types are not specific for signature algorithm. See discussion at #588.

  This PR became possible after we moved on new `secp256k1` version exposing `XonlyPublicKey` type, since now all key types may co-exist in a single module under different names

  The PR goal is achieved through
  - Renaming ecdsa mod into private ec module such that the code is not copied and diff size is small;
  - Introducing dummy ecdsa mod back in the next commit and re-exporiting only signature types from internal `ec` mod in it;
  - Re-exporting all key types under `key` module, removing previous depreciation message for bitcoin keys.

ACKs for top commit:
  apoelstra:
    ACK 8a993e8a58
  sanket1729:
    utACK 8a993e8a58

Tree-SHA512: 9f71edaa2cf4cdab4b239cb1d57576e2ba0fc3c2ec0ea19ae232005967b9400da6ded992b33d10b190ca617a66dca9b99be430bc5058a064f0be1489723c4a3a
2022-01-15 05:52:53 +05:30
Tobin Harding dfd8924398 Remove insert_pair from Map trait
The method implementation of `insert_pair` is currently not used for
`PartiallySignedTransaction`. Having an implementation available is
deceiving.

Delete the unused `insert_pair` code from
`PartiallySignedTransaction` (dead code). Make the `insert_pair` methods
from `Input` and `Output` be standalone functions.
2022-01-15 10:04:15 +11:00
Tobin Harding ad75d5181f Make Map trait private to psbt module
The `Map` trait has been deemed confusing and not that useful to users
of the library, we still use it internally within the `psbt` module
though so make it visible only in `psbt` and `psbt::map`.
2022-01-15 10:03:47 +11:00
Tobin Harding 53225c0a6e Improve docs in map module
Improve the function rustdocs in the `psbt::map` module by:

- using third person tense as is idiomatic in the Rust ecosystem
- using rustdoc `///` not code comments `//` for methods
- Use `# Return` section for documenting return values

Done for this module only as part of a PR fixing code within this
module.
2022-01-15 10:03:43 +11:00
Tobin Harding 92059c2841 Add full stops to rustdocs
Mildly improve the docs by adding full stops to every rustdoc comment.
2022-01-15 10:03:38 +11:00
Tobin Harding 11c046b707 Refactor match arms
Refactor the match arms to make the code around the key used for map look
up easier read.

Refactor only, no logic changes.
2022-01-15 10:02:41 +11:00
Tobin Harding e6af569490 Move imports to top of file
These imports are unusually placed, from the code comment it seems the
reason is stale.

Move imports to top of file as is typical.
2022-01-15 10:02:38 +11:00
KaFai Choi 8fef869c15
repalce unncessary extra closure with function pointer in starts_with_uppercase closure inside Denomination from_str 2022-01-14 21:07:43 +07:00
Dr. Maxim Orlovsky b165b8da05
Merge rust-bitcoin/rust-bitcoin#768: add nano and pico BTC to Denomination enum
40f38b3edc enforce strict SI(treat capital of m, u, n, p as invalid) in parsing amount denomiation. add disallow_unknown_denomination test (KaFai Choi)
e80de8b1ee add nano and pico BTC to Donomination enum (KaFai Choi)

Pull request description:

  Close [741](https://github.com/rust-bitcoin/rust-bitcoin/issues/741)

ACKs for top commit:
  Kixunil:
    ACK 40f38b3edc
  apoelstra:
    ACK 40f38b3edc
  dr-orlovsky:
    Changing review to ACK 40f38b3edc since it was my misunderstanding and not a bug

Tree-SHA512: 4cc380b8e7403e37e7993e25848b25d74c610d4e9fe274526c613d4b3e2a9f6677c7df52310fc1cab6f1d629d9529ff9f5a2efa41d9e07eab62d0989780ae3a4
2022-01-14 11:22:57 +02:00
Dr Maxim Orlovsky 8a993e8a58 Properly deprecate util::ecdsa key re-exports 2022-01-14 09:45:22 +01:00
Dr Maxim Orlovsky bcb8932ccf Re-org keys and ecdsa mods - pt.3 2022-01-14 01:35:48 +01:00
Dr Maxim Orlovsky d1c2213d3b Re-org keys and ecdsa mods - pt.2 2022-01-14 01:35:48 +01:00
Dr Maxim Orlovsky b9170162d5 Re-org keys and ecdsa mods - pt.1
This commit tries to achieve separation of signature- and key-related types, previously mixed in a single ECDSA module.

Rationale: bitcoin key types are not specific for signature algorithm.

This is achieved through
- Remove key mod with its content moved to ecdsa mod
- Re-export keys under key module in util mod - to make git generate diff for the rename of ecdsa mod in the next commit correctly.
2022-01-14 01:35:48 +01:00
Dr Maxim Orlovsky 2d9de78725 Re-export all key types under `util::key`. Deprecate other exports. 2022-01-14 01:35:48 +01:00
sanket1729 ebdeed086e Cleanup imports
We do not want to imports from within the lib and external of lib in the
same line
2022-01-14 05:39:17 +05:30
sanket1729 382c8f9e4f Introduce PsbtSigHashType 2022-01-14 05:39:17 +05:30
Dr Maxim Orlovsky 62a27a51e2 Document that serde impl of LeafVersion uses u8 in consensus encoding
Closes #764
2022-01-13 17:53:50 +01:00
Dr Maxim Orlovsky 73e6ce4e53 Re-export Witness at crate level. Closes #770 2022-01-13 17:51:01 +01:00
Dr Maxim Orlovsky 6364ebd927 Code style fixups to taproot key functions 2022-01-13 17:48:13 +01:00
Dr Maxim Orlovsky 7514f2ca18 Tweaked -> untweaked keys conversions 2022-01-13 17:40:27 +01:00
Andrew Poelstra 907b3a7a6a
Merge rust-bitcoin/rust-bitcoin#775: Issue #394 - Refactor Block::merkle_root()
cd2435c807 Change deprecated version to 0.28. Remove redundant Block::merkle_root() logic. (Nils Loewen)
05788285f5 Issue #394 - Refactor Block::merkle_root() to Block::compute_merkle_root() and deprecate Block::merkle_root(). (Nils Loewen)

Pull request description:

  Refactor `Block::merkle_root()` to `Block::compute_merkle_root()` and deprecate `Block::merkle_root()`.

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

Tree-SHA512: 820d85d5a25b7316046d5df8e3ab1e8cd57f72c7fa63f0d6826b965c5da3ef1bfacd4704180810aa8c0a7a224dcd62f398a2cf93fc344e2b0d52d9d7024c6c27
2022-01-13 14:32:30 +00:00
KaFai Choi 40f38b3edc
enforce strict SI(treat capital of m, u, n, p as invalid) in parsing amount denomiation. add disallow_unknown_denomination test 2022-01-13 20:27:41 +07:00
sanket1729 7d62277f83
Merge rust-bitcoin/rust-bitcoin#696: Taproot tweaks generalization & KeyPair support
7405836411 Fix warning about deprecated method use (Dr Maxim Orlovsky)
f39b1300fa CI: do not fail fast (Dr Maxim Orlovsky)
f77c57195a Making Script method new_* names more consistent (Dr Maxim Orlovsky)
91b68a468d Taproot-related methods for Script type (Dr Maxim Orlovsky)
599c5f9488 Generalizing taproot key tweaking for KeyPairs (Dr Maxim Orlovsky)

Pull request description:

  * Adds taproot-related methods to `Script`
  * Fixes API for existing taproot methods
  * Generalizes `TapTweak` trait to work with both public keys and key pairs

  ~~UPD: PR is pending https://github.com/rust-bitcoin/rust-secp256k1/pull/342~~

ACKs for top commit:
  sanket1729:
    ACK 7405836411
  apoelstra:
    ACK 7405836411

Tree-SHA512: 4a76dfffa1452baadc15e19812831ef9d2e66794c090a8fc123388d7119b2c8a1f0420ce723ad22e01683c8198711fe62e0cdf00c9ad2d2974606383baaf1cb0
2022-01-13 10:06:30 +05:30
Nils Loewen cd2435c807
Change deprecated version to 0.28. Remove redundant Block::merkle_root() logic. 2022-01-12 16:23:35 -08:00
Nils Loewen 05788285f5
Issue #394 - Refactor Block::merkle_root() to
Block::compute_merkle_root() and deprecate Block::merkle_root().
2022-01-12 13:37:23 -08:00
Andrew Poelstra bc9388e24a
Merge rust-bitcoin/rust-bitcoin#774: Change type of final script witness to Witness from Vec<Vec<u8>>
9a8ab3f3ff Change type of final script witness to Witness from Vec<Vec<u8>> (sanket1729)

Pull request description:

  Doing this would certainly help APIs downstream that operate on &Witness because they would not conversion from &Vec<Vec<u8>> to &Witness.

ACKs for top commit:
  Kixunil:
    ACK 9a8ab3f3ff
  RCasatta:
    ACK 9a8ab3f3ff
  dr-orlovsky:
    ACK 9a8ab3f3ff
  apoelstra:
    ACK 9a8ab3f3ff

Tree-SHA512: 647e18d254a51d6216a0122407146e8bc1d39504e76c1e0e746f740cec7cda587455b61d4cdadc3c59b1cf03eba87000de35fbde645a30fb166a84847ba101b2
2022-01-11 16:05:59 +00:00
sanket1729 9a8ab3f3ff Change type of final script witness to Witness from Vec<Vec<u8>> 2022-01-11 21:11:18 +05:30
Dr Maxim Orlovsky 7405836411 Fix warning about deprecated method use 2022-01-11 16:10:29 +01:00
Dr Maxim Orlovsky f77c57195a Making Script method new_* names more consistent 2022-01-11 16:10:29 +01:00
Dr Maxim Orlovsky 91b68a468d Taproot-related methods for Script type 2022-01-11 16:10:29 +01:00
Dr Maxim Orlovsky 599c5f9488 Generalizing taproot key tweaking for KeyPairs 2022-01-11 16:09:32 +01:00
Andrew Poelstra d9bc48f12f
Merge rust-bitcoin/rust-bitcoin#771: Add Witness::new()
5d27c15717 Add Witness::new() (sanket1729)

Pull request description:

  Rebasing rust-miniscript on rust-bitcoin master. Expect more trivial PRs :)

ACKs for top commit:
  dr-orlovsky:
    ACK 5d27c15717
  apoelstra:
    ACK 5d27c15717

Tree-SHA512: f1b6b1bba1ba6f153416be514b53d64bb6ba0c1cc1f182857f5010a048004f884d5c36ef96f6e27837bf682d781e3a4375bf2303e1f53685019406e88e192a03
2022-01-11 14:49:14 +00:00
KaFai Choi e80de8b1ee
add nano and pico BTC to Donomination enum 2022-01-11 19:23:45 +07:00
Dr Maxim Orlovsky eb09019720 Rename inner key field in PrivateKey and PublicKey
Closes #532
2022-01-11 08:39:52 +01:00
sanket1729 e4d5039a86
Merge rust-bitcoin/rust-bitcoin#591: PSBT BIP32 keys using to Secp256k1 keys instead of bitcoin ECDSA
a6e8f581db PSBT BIP32 keys moved to Secp256k1 from bitcoin ECDSA (Dr Maxim Orlovsky)

Pull request description:

  Fourth step in implementation of Schnorr key support after #588. This PR is a follow-up to non-API breaking #589 and API-breaking #590, which must be reviewed and merged first. ~~(The current PR includes all commits from #589 and #590, which should be reviewed there. The only commit specific to this PR is b8105e95dc8651626b783403ca060f7d32d21144)~~

  UPDATE: All related PRs are merged now and this PR is ready for the review

  PR description:
  While PSBT BIP174 does not specify whether uncompressed keys are supported in BIP32-related fields, from BIP32 it follows that it is impossible to use uncompressed keys within the extended keys.  This PR fixes this situation and is a companion to BIP174 PR clarifying key serialization: https://github.com/bitcoin/bips/pull/1100

ACKs for top commit:
  apoelstra:
    ACK a6e8f581db
  sanket1729:
    ACK a6e8f581db. Not sure which order to merge since there are many ready PRs which that would break each other.

Tree-SHA512: 198ba646bbce1949b255a54a97957d952acdad8b7f9580be123116c0f44d773e6d90e0cac0d5993ec9a6b3328aa43aced0908522817861585877c50008fec835
2022-01-11 12:42:53 +05:30
sanket1729 5d27c15717 Add Witness::new()
I think it is more natural to write Wintess::new() followed by Witness::push()
then Witness::default(). In any case, there is no harm in having additional constructors.
2022-01-11 07:37:20 +05:30
Dr Maxim Orlovsky a6e8f581db PSBT BIP32 keys moved to Secp256k1 from bitcoin ECDSA
Fourth step in implementation of Schnorr key support after #588.

While PSBT BIP174 does not specify whether uncompressed keys are supported in BIP32-related fields, from BIP32 it follows that it is impossible to use uncompressed keys within the extended keys.  This PR fixes this situation and is a companion to BIP174 PR clarifying key serialization: https://github.com/bitcoin/bips/pull/1100
2022-01-10 10:16:57 +01:00
KaFai Choi 9835736ef5
wrap u8 and LeafVersion in backticks and square bracket in doc 2022-01-10 15:09:44 +07:00
sanket1729 d82afc6ef5
Merge rust-bitcoin/rust-bitcoin#761: Taproot trivial post-merge fixups
7f06e91a93 LowerHex and UpperHex implementations for LeafVersion (Dr Maxim Orlovsky)
6a3f3aabaf Inverse alternative formatting for LeafVersion type (Dr Maxim Orlovsky)
bec6694233 Fix docs on error conditions in LeafVersion::from_consensus (Dr Maxim Orlovsky)
7c28b47451 LowerHex and UpperHex implementations for FutureLeafVersion (Dr Maxim Orlovsky)

Pull request description:

  Trivial post-merge fixups from review comments in #718

ACKs for top commit:
  Kixunil:
    ACK 7f06e91a93
  sanket1729:
    ACK 7f06e91a93

Tree-SHA512: d94c4bd3d0b466287c8965103f74ecaba185d14c13b6c3f37d9fbe194343b3fc902fd2c7716554ad01fe28ff89cda933df199b7e8388a3fa6097028caf62522b
2022-01-10 04:18:48 +05:30
sanket1729 476eed7f2f
Merge rust-bitcoin/rust-bitcoin#590: Taproot: BIP32 extended keys using Scep256k1 keys instead of bitcoin ECDSA
cf0c48cc86 Improve Debug for PrivateKey (Dr Maxim Orlovsky)
b65a6ae49b Test for extended private key keypair generation  f5875a (Dr Maxim Orlovsky)
e6a3d603c9 BIP32 extended key `to_ecdsa()` and `to_schnorr()` methods (Dr Maxim Orlovsky)
b72f56c4ae BIP32 extended keys are using Scep256k1 keys instead of bitcoin ECDSA (Dr Maxim Orlovsky)

Pull request description:

  This is third step required to introduce Schnorr key support according to #588. This PR starts API-breaking changes and is follow-up to non-API breaking #589, which is already merged.

  PR rationale: BIP32 does not support uncompressed keys and using type with compression flag was a mistake

ACKs for top commit:
  apoelstra:
    ACK cf0c48cc86
  sanket1729:
    ACK cf0c48cc86. #757 might need rework after this

Tree-SHA512: 6356a65004e7517256bacbf9aaeb69a22fd8536b341e567c5c4e819288e1105d083fe12ac0641404c407c97acf039bdc525f8e02b1b594a6cdda90106f3b1bdc
2022-01-10 03:46:05 +05:30
Dr Maxim Orlovsky 7f06e91a93 LowerHex and UpperHex implementations for LeafVersion 2022-01-09 20:52:38 +01:00
Dr Maxim Orlovsky 6a3f3aabaf Inverse alternative formatting for LeafVersion type 2022-01-09 20:50:22 +01:00
Dr Maxim Orlovsky bec6694233 Fix docs on error conditions in LeafVersion::from_consensus 2022-01-09 20:48:00 +01:00
Dr Maxim Orlovsky 7c28b47451 LowerHex and UpperHex implementations for FutureLeafVersion 2022-01-09 20:46:51 +01:00
Andrew Poelstra 8e9f99b620
Merge rust-bitcoin/rust-bitcoin#718: Converting LeafVersion into an enum
ef8a3a839e Introduce FutureLeafVersion (Dr Maxim Orlovsky)
b028385a72 Improve docs in LeafVersion (Dr Maxim Orlovsky)
839c022f29 Make serde for LeafVersion to have byte representation (Dr Maxim Orlovsky)
67b8db05a8 Converting LeafVersion into an enum (Dr Maxim Orlovsky)
2405417432 Use TAPROOT_ANNEX_PREFIX in sighash module (Dr Maxim Orlovsky)

Pull request description:

  The original `LeafVersion` implementation was just a newtype around `u8`. I think that having enum explicitly listing consensus script implementation rules may be more beneficial in terms of both code readibility and future use of multiple script types, where `LeafVersion` may operate as a context object provided to `Script` to specify interpretation rules for particular op codes.

ACKs for top commit:
  Kixunil:
    ACK ef8a3a839e
  sanket1729:
    crACK ef8a3a839e. Waiting a day to let others complete review before merging.
  apoelstra:
    ACK ef8a3a839e

Tree-SHA512: 3356d2b9b00cf904edfece26d26ffbc646ba74446cc23ec4b2b4026ed50861285802f077226e30ba8fed466f68f8e8556c729ce48cb38581b1d95a02a6fde9cf
2022-01-09 15:26:05 +00:00
Dr Maxim Orlovsky cf0c48cc86 Improve Debug for PrivateKey 2022-01-09 07:17:10 +01:00
Dr Maxim Orlovsky b65a6ae49b Test for extended private key keypair generation f5875a 2022-01-09 07:17:06 +01:00
Dr Maxim Orlovsky e6a3d603c9 BIP32 extended key `to_ecdsa()` and `to_schnorr()` methods 2022-01-09 07:17:02 +01:00
Dr Maxim Orlovsky b72f56c4ae BIP32 extended keys are using Scep256k1 keys instead of bitcoin ECDSA
According to #588, BIP32 does not support uncompressed keys and using type with compression flag is a mistake
2022-01-09 07:16:49 +01:00
Dr Maxim Orlovsky ef8a3a839e Introduce FutureLeafVersion 2022-01-08 23:40:21 +01:00
Dr Maxim Orlovsky 14ace92666 Fix SchnorrSig type references in PSBT serialization macros 2022-01-08 16:29:45 +01:00
Dr Maxim Orlovsky b028385a72 Improve docs in LeafVersion 2022-01-07 22:06:17 +01:00
Dr Maxim Orlovsky 839c022f29 Make serde for LeafVersion to have byte representation 2022-01-07 22:04:41 +01:00
Dr Maxim Orlovsky 2b530000d3 Use EcdsaSig in PSBT partial signatures instead of Vec<u8> 2022-01-07 21:57:42 +01:00
Dr Maxim Orlovsky 141dbbd1b9 Add serde impl for EcdsaSig 2022-01-07 21:57:42 +01:00
Dr Maxim Orlovsky c92057d98f PSBT serialize/deserialize impl for EcdsaSig type 2022-01-07 21:57:42 +01:00
Dr Maxim Orlovsky 0af1c3f320 Add Display and FromStr for EcdsaSig 2022-01-07 21:57:11 +01:00
Dr Maxim Orlovsky daf0eacf3d Improve NonStandardSigHashType 2022-01-07 21:49:05 +01:00
Dr Maxim Orlovsky c36a3da6f0 Add EcdsaSig::sighash_all convenience constructor 2022-01-07 21:49:05 +01:00
Andrew Poelstra f332a1967e
Merge rust-bitcoin/rust-bitcoin#750: Use `test_data` for big objects, add big block for benchmarking
247a14f4c3 Use test big block for bench_stream_reader instead of making one (Riccardo Casatta)
b92dfbb63f exclude test_data when publishing the crate (Riccardo Casatta)
f5a9681a2a include a big block in test_data, use it for ser/de benchmark (Riccardo Casatta)
09dada55d6 Move bip158 test vectors to test_data (Riccardo Casatta)
06d1a820c3 Remove testnet block hex from tests, use test_data with include_bytes! (Riccardo Casatta)

Pull request description:

  In the first two commits I moved some data from source files to the newly introduced `test_data` dir, including it with `include_[str|bytes]!` macro.

  The second-to-last commit introduces a big block in test_data which is very handy in ser/de benchmark (I used it for #672) because with smaller blocks you may not notice performance improvements.

  Since I don't want to pollute the package the last commit excludes the `test_data` dir from the published package. I think it's fine to do it because dependent packages don't run dependencies tests.

ACKs for top commit:
  apoelstra:
    ACK 247a14f4c3
  Kixunil:
    tACK 247a14f4c3

Tree-SHA512: a2beb635b0a358737d0b57d3e7205b1ddf87652b9a8c889ce63e2867659a8eaf7e43a5b87a453345d56d953745913f40b58596f449e5fbc87340e0dd2aef0727
2022-01-07 20:22:02 +00:00
Dr Maxim Orlovsky 67b8db05a8 Converting LeafVersion into an enum 2022-01-07 20:28:36 +01:00
Dr Maxim Orlovsky 2405417432 Use TAPROOT_ANNEX_PREFIX in sighash module 2022-01-07 20:27:34 +01:00
sanket1729 91470f56c8 Uncomment sighash test
We can check tweak add priv key with latest secp
2022-01-07 04:45:40 +05:30
sanket1729 2178c7367c Update to secp256k1 0.21.2 2022-01-07 04:45:40 +05:30
Riccardo Casatta 9e7bb0967c
Merge rust-bitcoin/rust-bitcoin#753: Put rustdocs above attributes
533120899e Put rustdocs above attributes (Tobin Harding)

Pull request description:

  (Trivial / Very low priority PR)

  Rust idiomatic style is to put the rustdoc _above_ any attributes on types, functions, etc.

  Audit the codebase and move comments/attributes to the correct place. Add a trailing full stop at times to neaten things up a little extra.

  Done after discussion [here](https://github.com/rust-bitcoin/rust-secp256k1/pull/353#discussion_r778393138)

ACKs for top commit:
  Kixunil:
    ACK 533120899e
  RCasatta:
    ACK 533120899e

Tree-SHA512: 7cd00dc46de813cbe3f96417bb4b13980064e10110b421224496c8b64bbe87b61b6c757cc621fde1d05754be6ecdc08acdb51fd8978e3f820d2d93f7104062d1
2022-01-06 14:09:23 +01:00
Riccardo Casatta 247a14f4c3
Use test big block for bench_stream_reader instead of making one 2022-01-06 13:55:50 +01:00
Riccardo Casatta f5a9681a2a
include a big block in test_data, use it for ser/de benchmark 2022-01-06 13:48:02 +01:00
Riccardo Casatta 09dada55d6
Move bip158 test vectors to test_data 2022-01-06 13:47:58 +01:00
Riccardo Casatta 06d1a820c3
Remove testnet block hex from tests, use test_data with include_bytes! 2022-01-06 13:47:51 +01:00
Riccardo Casatta 9c3a27a326
Merge rust-bitcoin/rust-bitcoin#680: Deprecate `StreamReader`
e860333bf3 Fix typos (Riccardo Casatta)
9189539715 Use BufReader internally in StreamReader to avoid performance regression on existing callers (Riccardo Casatta)
5dfb93df71 Deprecate StreamReader (Riccardo Casatta)
9ca6c75b18 Bench StreamReader (Riccardo Casatta)

Pull request description:

  `StreamReader` performance is extremely poor in case the object decoded is "big enough" for example a full Block.

  In the common case, the buffer is 64k, so to successfully parse a 1MB block 16 decode attempts are made.
  Even if a user increases the buffer size, `read` is not going to necessarily fill the buffer, as stated in the doc https://doc.rust-lang.org/stable/std/io/trait.Read.html#tymethod.read. In my tests, the reads are 64kB even with a 1MB buffer.

  I think this is the root issue of the performance issue found in electrs in https://github.com/romanz/electrs/issues/547 and they now have decided to decode the TCP stream with their own code in cd0531b8b7 and 05e0221b8e.

  Using directly `consensus_encode` seems to make more sense (taking care of using `BufRead` if necessary) so the `StreamReader` is deprecated

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

Tree-SHA512: a15a14f3f087be36271da5008d8dfb63866c9ddeb5ceb0e328b4a6d870131132a8b05103f7a3fed231f5bca099865efd07856b4766834d56ce2384b1bcdb889b
2022-01-06 13:28:32 +01:00
Tobin Harding 533120899e Put rustdocs above attributes
Rust idiomatic style is to put the rustdoc _above_ any attributes on
types, functions, etc.

Audit the codebase and move comments/attributes to the correct place.
Add a trailing full stop at times to neaten things up a little extra.
2022-01-06 13:04:47 +11:00
Riccardo Casatta e860333bf3
Fix typos 2022-01-05 09:39:57 +01:00
Riccardo Casatta 9189539715
Use BufReader internally in StreamReader to avoid performance regression on existing callers 2022-01-04 10:31:45 +01:00
sanket1729 92ee5a7e5f Test BIP341 sighash code 2022-01-01 04:12:46 +05:30
Riccardo Casatta 5dfb93df71
Deprecate StreamReader
StreamReader before this commit is trying to repeatedly parse big object like
blocks at every read, causing useless overhead.
consensus_encode deal with partial data by simply blocking.

After this changes it doesn't look what remain of the StreamReader is really giving
value, so it's deprecated
2021-12-31 10:44:14 +01:00
Dr. Maxim Orlovsky 670e808c17
Merge rust-bitcoin/rust-bitcoin#681: Add support for taproot psbt fields BIP 371
7d982fa9a2 Add all tests from BIP 371 (sanket1729)
d22e0149ad Taproot psbt impl BIP 371 (sanket1729)
108fc3d4db Impl encodable traits for TapLeafhash (sanket1729)
c7478d8fd0 Derive serde for taproot stuctures (sanket1729)

Pull request description:

  Built on top of #677 . Will rebase and mark ready for review after #677 is merged.

ACKs for top commit:
  apoelstra:
    ACK 7d982fa9a2
  dr-orlovsky:
    re-tACK 7d982fa9a2 basing on `git range-diff`. The original PR before last re-base was tested commit-by-commit.

Tree-SHA512: feb30e4b38d13110a9c0fabf6466d8f0fb7df09a82f4e01d70b8371b34ab0187004a6c63f9796c6585ee30841e8ee765ae9becae139d2e1e3d839553d64c3d1e
2021-12-30 02:12:03 +02:00
Dr. Maxim Orlovsky 86055d9df5
Merge rust-bitcoin/rust-bitcoin#672: New Witness struct to improve ser/de perfomance
106acdc3ac Add fuzzing for Witness struct (Riccardo Casatta)
2fd0125bfa Introduce Witness struct mainly to improve ser/de performance while keeping most usability. (Riccardo Casatta)

Pull request description:

  At the moment the Witness struct is  `Vec<Vec<u8>>`, the vec inside a vec cause a lot of allocations, specifically:

  - empty witness -> 1 allocation, while an empty vec doesn't allocate, the outer vec is not empty
  - witness with n elements -> n+1 allocations

  The proposed Witness struct contains the serialized format of the witness. This reduces the allocations to:

  - empty witness -> 0 allocations
  - witness with n elements -> 1 allocation for most common cases (you don't know how many bytes is long the entire witness beforehand, thus you need to estimate a good value, not too big to avoid wasting space and not too low to avoid vector reallocation, I used 128 since it covers about 80% of cases on mainnet)

  The inconvenience is having slightly less comfortable access to the witness, but the iterator is efficient (no allocations) and you can always collect the iteration to have a Vec of slices. If you collect the iteration you end up doing allocation anyway, but the rationale is that it is an operation you need to do rarely while ser/de is done much more often.

  I had to add a bigger block to better see the improvement (ae860247e191e2136d7c87382f78c96e0908d700), these are the results of the benches on my machine:

  ```
  RCasatta/master_with_block
  test blockdata::block::benches::bench_block_deserialize                 ... bench:   5,496,821 ns/iter (+/- 298,859)
  test blockdata::block::benches::bench_block_serialize                   ... bench:     437,389 ns/iter (+/- 31,576)
  test blockdata::block::benches::bench_block_serialize_logic             ... bench:     108,759 ns/iter (+/- 5,807)
  test blockdata::transaction::benches::bench_transaction_deserialize     ... bench:         670 ns/iter (+/- 49)
  test blockdata::transaction::benches::bench_transaction_get_size        ... bench:           7 ns/iter (+/- 0)
  test blockdata::transaction::benches::bench_transaction_serialize       ... bench:          51 ns/iter (+/- 5)
  test blockdata::transaction::benches::bench_transaction_serialize_logic ... bench:          13 ns/iter (+/- 0)

  branch witness_with_block (this one)
  test blockdata::block::benches::bench_block_deserialize                 ... bench:   4,302,788 ns/iter (+/- 424,806)
  test blockdata::block::benches::bench_block_serialize                   ... bench:     366,493 ns/iter (+/- 42,216)
  test blockdata::block::benches::bench_block_serialize_logic             ... bench:      84,646 ns/iter (+/- 7,366)
  test blockdata::transaction::benches::bench_transaction_deserialize     ... bench:         648 ns/iter (+/- 77)
  test blockdata::transaction::benches::bench_transaction_get_size        ... bench:           7 ns/iter (+/- 0)
  test blockdata::transaction::benches::bench_transaction_serialize       ... bench:          50 ns/iter (+/- 5)
  test blockdata::transaction::benches::bench_transaction_serialize_logic ... bench:          14 ns/iter (+/- 0)
  ```

  With an increased performance to deserialize a block of about 21% and to serialize a block of about 16% (seems even higher than expected, need to do more tests to confirm, I'll appreciate tests results from reviewers)

ACKs for top commit:
  apoelstra:
    ACK 106acdc3ac
  sanket1729:
    ACK 106acdc3ac
  dr-orlovsky:
    utACK 106acdc3ac

Tree-SHA512: e4f23bdd55075c7ea788bc55846fd9e30f9cb76d5847cb259bddbf72523857715b0d4dbac505be3dfb9d4b1bcae289384ab39885b4887e188f8f1c06caf4049a
2021-12-30 01:55:44 +02:00
Riccardo Casatta e511670e43
Merge rust-bitcoin/rust-bitcoin#722: Allow specifing a raw `TapLeafHash` in sighash computation
2959e04ebd Allow specifing a raw `TapLeafHash` in sighash computation (Alekos Filini)

Pull request description:

  Still need to add some tests but the code should be ready for review. Please let me know if you have better ideas for the enum naming.

  ---

  Instead of always requiring the full raw script and leaf version, allow
  just specifying a raw leaf hash to the sighash computation functions.

  This is very useful when dealing with PSBTs, because the
  `PSBT_IN_TAP_BIP32_DERIVATION` field only maps a public key to a leaf
  hash, so a signer could just take it and produce a signature with it
  rathern than having to jump through hoops to recover the full raw
  script.

ACKs for top commit:
  sanket1729:
    Tested locally. ACK 2959e04. Reviewed range-diff with 5aa1d02
  apoelstra:
    ACK 2959e04ebd

Tree-SHA512: 830be0b8382ac59b73e6481f61ec1effdcd32859c04382e6cd5a43ac689d6e528f9a8b27c026ee81f5d5b59d2e3c397f9c271145e001ff2dc4815764fc21a2c6
2021-12-29 18:08:45 +01:00
sanket1729 7d982fa9a2 Add all tests from BIP 371 2021-12-28 20:40:58 +05:30
sanket1729 d22e0149ad Taproot psbt impl BIP 371 2021-12-28 20:40:58 +05:30
sanket1729 108fc3d4db Impl encodable traits for TapLeafhash 2021-12-28 20:40:58 +05:30
sanket1729 c7478d8fd0 Derive serde for taproot stuctures 2021-12-28 20:40:58 +05:30
Riccardo Casatta 2fd0125bfa
Introduce Witness struct mainly to improve ser/de performance while keeping most usability.
Witness struct is in place of the Vec<Vec<u8>> we have before this commit.

from_vec() and to_vec() methods are provided to switch between this type and Vec<Vec<u8>>

Moreover, implementation of Default, Iterator and others allows to have similar behaviour but
using a single Vec prevent many allocations during deserialization which in turns results in
better performance, even 20% better perfomance on recent block.

last() and second_to_last() allows to access respective element without going through costly Vec
transformation
2021-12-28 09:56:38 +01:00