Commit Graph

1485 Commits

Author SHA1 Message Date
Tobin Harding e503f14331 Improve docs: blockdata::transaction
Improve the rustdocs for the `blockdata::transaction` module:

- Use full sentences (capitalisation and full stop)
- Use third person tense instead of imperative
- Improve wording/grammar
- Use backticks in links
- Use 100 character column width if it improves readability

Nothing too controversial here :)
2022-03-10 07:20:40 +11:00
Tobin Harding f02b3a8472 Add code comment for emtpy input
The line of code `let mut have_witness = self.input.is_empty();` is
puzzling if one does not know _why_ we serialize in BIP141 style when
there are no inputs.

Add a code comment to save devs spending time trying to work out _why_
this is correct.
2022-03-10 07:14:06 +11:00
Tobin Harding 6a0ec1ac47 Remove redundant _eq
`assert!` already checks a boolean, it is redundant to use `assert_eq!`
and pass in `true`.

Remove redundant usage of `assert_eq!(foo, true)`.
2022-03-10 07:13:55 +11:00
Tobin Harding 3bcc146a44 Improve docs: encode_signing_data_to/signature_hash
The two methods `encode_signing_data_to` and `signature_hash` use the
same docs (one is a public helper for the other). The docs have gotten a
bit stale (refer to deprecated types).

Instead of duplicating all the text, add a statement pointing readers
from the docs of `signature_hash` to the docs on
`encode_signing_data_to`.
2022-03-10 07:13:06 +11:00
Tobin Harding aaf587d320 Use correct opcode count
Code comment contains an off-by-one error, update it to the correct
value '61'.
2022-03-10 06:42:09 +11:00
Tobin Harding 146d5e83d1 Improve docs for blockdata::block
Improve the rustdocs for the `blockdata::block` module:

- Use full sentences (capitalisation and full stop)
- Use third person tense instead of imperative
- Improve wording if needed
2022-03-10 06:39:32 +11:00
Tobin Harding f03092c380 Fix erroneous function rustdoc
The returns part of the function docs appears to be stale, remove it.
Improve wording of rustdocs while we are at it.
2022-03-10 06:39:32 +11:00
Tobin Harding 5464848f45 Refactor check_witness_commitment
Currently function contains nested `if` clauses that arguably obfuscate
the code. We can make the code easier to read by pulling out the error
paths and returning them higher up in the function.

Refactor only, no logic changes.
2022-03-10 06:39:04 +11:00
Tobin Harding f4886afa66 Add full stops to docs
Add full stops to all lines of rustdocs in the `blockdata::opcodes`
module.
2022-03-09 13:55:14 +11:00
Tobin Harding f01f047b21 Remove unnecessary newlines
Whitespace only, no code changes.
2022-03-09 13:55:14 +11:00
Tobin Harding 8a1cc2ca77 Improve docs on ClassifyContext
Improve docs on `ClassifyContext` by doing:

- Separate brief doc line from the rest
- Use uniform backticks on opcodes
2022-03-09 13:55:14 +11:00
Tobin Harding ee3b8c267d Order impl_hashencode lines
Put the calls to `impl_hashencode` in the same order, and with the same
whitespace, as the calls to `hash_newtype`. This makes groking the file
easier because its quick to glance down the types and see which ones
implement hashencode (consensus_encode/decode) and which ones do not.
2022-03-09 13:18:48 +11:00
Tobin Harding ac105903cd Flatten the policy module
The policy module contains a single `mod.rs` file, this is unnecessary,
we can simply use `policy.rs` and flatten the module.
2022-03-09 10:20:18 +11:00
Tobin Harding 7638d59fa6 Improve rusntdocs for *_hash_ty methods
Improve the docs by doing:
- Use markdown heading for `Errors` section
- Use 100 character lines
2022-03-08 09:14:20 +11:00
Andrew Ahlers 51fef76129 feat: Add Address.is_related_to_pubkey() 2022-03-06 20:30:22 +01:00
sanket1729 91c5d7192f Change the parameter for control block verification
Changes the API from TweakedPublicKey to XonlyPublicKey. I believe we
introduced TweakedPublicKey to guard against creating address API. This
is confusing because when we want to verify control block we have to
call dangerous_assume_tweak.
This is in true in most cases that the key would be tweaked, but we only
want to guard in while creating a new address. If we want to verify
blocks, we should deal with native X-only-keys regardless of how they
were created
2022-02-28 08:31:20 -08:00
sanket1729 1ec9e87255
Merge rust-bitcoin/rust-bitcoin#842: Separate out merge method into public trait
5e2449922d Separate merge logic out of Map trait (Tobin Harding)

Pull request description:

  Recently we (*cough* Tobin) made the `Map` trait private and neglected
  to add a public API for merging together two PSBTs. Doing so broke the
  `psbt` module.

  Add a public trait `Merge` and implement it for
  `PartiallySignedTransaction` using the code currently in the `merge`
  method of the now private `Map` trait.

  Motivated by https://github.com/rust-bitcoin/rust-bitcoin/pull/841

ACKs for top commit:
  JeremyRubin:
    > ACK 5e24499
  apoelstra:
    ACK 5e2449922d
  sanket1729:
    ACK 5e2449922d. Also verified that the vectors are same of that of BIP174

Tree-SHA512: 79eefe93e870b61231b388aa28a95ee5c8ac06b68910f4ff324569512a79eafe5b86239fd45f54ca7a868cf59dc6301e45d1f046c039a64b2493a8ffcea659fd
2022-02-28 08:30:31 -08:00
Rishabh Singhal fb04cabe1d
Add a method to psbt to compute find sighash type
Fixes #838: Add a utility method to psbt to compute find sighash
type of a given input.
2022-02-25 18:38:19 +05:30
Andrew Poelstra 2c1077e681
Merge rust-bitcoin/rust-bitcoin#829: Don't allow uncompressed public keys without prefix 0x04
c0d36efb8b Don't allow uncompressed public keys without prefix 0x04 (Noah Lanson)

Pull request description:

  Was following #520 and through it was a quick fix that I could do:

  #### Changes:
  - If an uncompressed public key doesn't have prefix 0x04 in `PublicKey::from_slice()`, an error is returned.

  <br>

  I was wondering if `PublicKey::from_str()` should also enforce the same rules, however I have not incuded this in the PR.

  Please let me know if any changes need to be made.

  Thanks

ACKs for top commit:
  Kixunil:
    ACK c0d36efb8b
  apoelstra:
    ACK c0d36efb8b
  sanket1729:
    utACK c0d36efb8b. Not thrilled about the error message expecting len 66, when it can be both 66/130. But can live with it

Tree-SHA512: cfbcd569691c9a7f69ee775ec530605f42e988470a2ff9c28b4c881cec6b259053bb2288818e00b6f6b20316b1fb30fecc0b9a240ebbe7618f202ef6b5efeb9b
2022-02-24 16:50:55 +00:00
Tobin Harding 5e2449922d
Separate merge logic out of Map trait
Recently we (*cough* Tobin) made the `Map` trait private and neglected
to add a public API for combining together two PSBTs. Doing so broke the
`psbt` module.

Pull the merge logic out of the `Map` trait and put it in methods on
each individual type (`Input`, `Output`, `PartiallySignedTransaction`).
Doing so allows for simplification of return types since combining
inputs/outputs never errors.

Use the term 'combine' instead of 'merge' since that is the term used in
BIP 174.
2022-02-23 09:03:16 +00:00
Andrew Poelstra 04787d4867
Merge rust-bitcoin/rust-bitcoin#835: Change Prevouts::All(&[TxOut]) to Prevouts::All(&[&TxOut])
10fedfb3b4 Change Prevouts::All(&[TxOut]) to Prevouts::All(&[Borrow<T>]) (sanket1729)

Pull request description:

  I believe this avoids some allocation of creating a vec of TxOut to
  create a slice incase the data is already available in psbt/other
  methods.

  See #834

ACKs for top commit:
  apoelstra:
    ACK 10fedfb3b4
  Kixunil:
    ACK 10fedfb3b4

Tree-SHA512: 20f69c626b38d6b3c03c8cb370cfad097bbf0bfefff9bb2379c8af3bc94e25d8cc45fc5d69488aeefad58a95470e8f30eb7b400349992a9ebd0d3a13870cba43
2022-02-17 16:56:36 +00:00
sanket1729 10fedfb3b4 Change Prevouts::All(&[TxOut]) to Prevouts::All(&[Borrow<T>])
This avoids some allocation of creating a vec of TxOut to
create a slice incase the data is already available in psbt/other
methods. Facilitates creation of Prevouts from &[TxOut] as well as
&[&TxOut]
2022-02-17 04:45:42 -08:00
sanket1729 4e19973d4e Add a breaking test
This commit can be re-ordered before the fix to see that the test fail
during psbt decoding
2022-02-17 02:48:29 -08:00
sanket1729 69c6eb6173 Bug: Change type of pbst partial sig from secp key to bitcoin key
This changes the type of secp signature from secp256k1::Signature to
bitcoin::PublicKey. Psbt allows storing signatures for both compressed
as well as uncompressed keys. This bug was introduced in #591 while
trying to change the type of BIP32 keys from bitcoin::PublicKey to
secp256k1::PublicKey.
2022-02-16 23:45:35 -08:00
Noah Lanson c0d36efb8b Don't allow uncompressed public keys without prefix 0x04 2022-02-17 08:46:20 +11:00
Andrew Ahlers 79cee4cd31 fix: Error on unsuported addresses in `is_signed_by_address`
Inspired by this comment: https://github.com/rust-bitcoin/rust-bitcoin/pull/684#issuecomment-1012136845
2022-02-09 23:06:22 +01:00
Andrew Ahlers e391ce9939 test: Add a test for incorrect message signature 2022-02-09 22:04:23 +01:00
Andrew Poelstra cb35766979
Merge rust-bitcoin/rust-bitcoin#808: Refactor logical operators
df7bb03a67 Simplify read_scriptbool (Tobin Harding)
4b6e86658d Refactor is_provably_unspendable (Tobin Harding)
e54a2d653b Put && operator at front of line (Tobin Harding)
f5512c4931 Refactor is_p2pkh (Tobin Harding)
373ea89a9a Simplify read_scriptbool (Tobin Harding)
654b2772b8 Add passing unit tests for read_scriptbool (Tobin Harding)

Pull request description:

  In an effort to make the code clearer and more explicit, do various refactorings around logical operators. Each done as a separate patch to ease review and limit scope of discussion.

  Based on review of https://github.com/rust-bitcoin/rust-bitcoin/pull/806

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

Tree-SHA512: 06460979d492eb38cefc147397338b7fd95320c66ce8e8b4f8e2b454bb35721ce308413690a0618bd19d695df56175646d4d0c619388c0268f7fd35d5a7b6a3d
2022-01-26 13:14:16 +00:00
Tobin Harding df7bb03a67 Simplify read_scriptbool
Simplify `read_scriptbool` by doing:

- Use `split_last` to get at the last element
- Mask the last byte against ^0x80 instead of using two equality
  statements
2022-01-26 16:52:41 +11:00
Riccardo Casatta 22aeaef52b
Use write_all instead of write
write() could write only a part of the given buffer, the caller should
check the numbers of byte written (which is what write_all does)
2022-01-25 15:09:21 +01:00
Tobin Harding 4b6e86658d Refactor is_provably_unspendable
Refactor with the aim of making the code easier to read. Code path is
covered by current unit tests.

Refactor only, no logic changes.
2022-01-25 10:21:06 +11:00
Tobin Harding e54a2d653b Put && operator at front of line
In an effort to make code containing multi-line logical AND clearer to
read put the operator at the start of the line.
2022-01-25 10:21:06 +11:00
Tobin Harding f5512c4931 Refactor is_p2pkh
Refactor with the aim of simplifying `is_p2kh`. This function is covered
sufficiently by current unit tests.

Refactor only, no logic changes.
2022-01-25 10:16:56 +11:00
Tobin Harding 373ea89a9a Simplify read_scriptbool
Refactor and simplify the logical operators in `read_scriptbool`.

Refactor only, no logic changes.
2022-01-25 10:16:56 +11:00
Tobin Harding 654b2772b8 Add passing unit tests for read_scriptbool
In preparation for refactoring `read_scriptbool` add passing unit
tests.
2022-01-25 10:16:54 +11:00
sanket1729 325e0ccf51
Merge rust-bitcoin/rust-bitcoin#800: Use fn name to_ instead of into_
151173821b Use fn name to_ instead of into_ (Tobin Harding)

Pull request description:

  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.

  **Note to maintainers**

  This is similar in concept to #798 but only touches new code introduced in this release. Has been labelled 'RC fix' for that reason. Please feel free to remove the label if you disagree.

  From the docs: https://rust-lang.github.io/api-guidelines/naming.html

  <h2><a class="header" href="https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv" id="ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv">Ad-hoc conversions follow <code>as_</code>, <code>to_</code>, <code>into_</code> conventions (C-CONV)</a></h2>
  <p>Conversions should be provided as methods, with names prefixed as follows:</p>

  Prefix | Cost | Ownership
  -- | -- | --
  as_ | Free | borrowed -> borrowed
  to_ | Expensive | borrowed -> borrowed
  | | | borrowed -> owned (non-Copy types)
  | | | owned -> owned (Copy types)
  into_ | Variable | owned -> owned (non-Copy types)

ACKs for top commit:
  Kixunil:
    ACK 151173821b
  apoelstra:
    ACK 151173821b
  sanket1729:
    ACK 151173821b

Tree-SHA512: 4bb97e4fb78beda0fd1ec9482d24ef0f4ade6d3689f5c1bcf2208fa2df3195962522fa5d5ac700e6d4d5ff2096a20b2a0ad51784909a3c12405762aa08d1ced2
2022-01-21 08:00:31 +05:30
Casey Rodarmor 94dd57de12 Add subsidy halving interval constant 2022-01-20 08:52:46 -08:00
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
sanket1729 b945a5e5c6
Merge rust-bitcoin/rust-bitcoin#665: transactions: add a note about `get_vsize` and standardness rules
826fed53f2 transactions: add a note about `get_vsize` and standardness rules (Antoine Poinsot)

Pull request description:

  If they ever hit a discrepancy they must really be doing something dodgy but hey :)

ACKs for top commit:
  dr-orlovsky:
    ACK 826fed53f2

Tree-SHA512: c618a80b047797625a233939d2c1146e8b4ce44215648841813f78178577afc844f5e561e4e60b4084e315735894ecb354af8d81f4702f5354e5d5cd05b52ac4
2021-12-28 02:35:54 +05:30
Alekos Filini 2959e04ebd
Allow specifing a raw `TapLeafHash` in sighash computation
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.
2021-12-27 16:18:19 +01:00
Riccardo Casatta 9e1f256b54
Merge rust-bitcoin/rust-bitcoin#731: Improve parsing of `Denomination` string
f690b8e362 Be more liberal when parsing Denomination (Tobin Harding)
628168e493 Add missing white space character (Tobin Harding)

Pull request description:

  There is no reason to force users to use a particular format or case for `Denomination` strings. Users may wish to write any of the following and all seem reasonable
  - 100 sats
  - 100 sat
  - 100 SAT

  The same goes for various other `Denomination`s.

  - Patch 1 enables usage of "sats", "sat", "bit", "bits"
  - Patch 2 enables usage of various lower/uper case formatting

  Fixes: #729

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

Tree-SHA512: a785608e19a7ba6f689dc022cb17a709041ff56abeaa74649d0832a8bd8aac4593c7a79b46a47dd417796c588d669f50fb3c8b8a984be332ca38a1fef2dcd4ce
2021-12-27 10:17:40 +01:00
sanket1729 3eea63e42b Re-export SigHashType in lib.rs
Using the latest version of rust-bitcoin master on rust-miniscript
errors on bitcoin::SigHashType not found. In the original PR, I only
renamed the export to ECDSASigHashType, but original re-export should
also be there in lib.rs to avoid to breaking changes downstream.
2021-12-26 04:56:25 +05:30
Riccardo Casatta f9b3fc9ce8
Merge rust-bitcoin/rust-bitcoin#686: Fixed a bunch of clippy lints, added clippy.toml
779d4110c6 Fixed a bunch of clippy lints, added clippy.toml (Martin Habovstiak)

Pull request description:

  This is the initial step towards using and maybe enforcing clippy.
  It does not fix all lints as some are not applicable. They may be
  explicitly ignored later.

  Some discussion about clippy was in #685

ACKs for top commit:
  apoelstra:
    ACK 779d4110c6
  RCasatta:
    ACK 779d4110c6

Tree-SHA512: fb9192c77565a0b1b2118877c6413945d65900e4e95b3741107bf6cddef1fa65ff09fc5b7814de421382292321cca6bd860bf17b73a227d193a0a13758ee25eb
2021-12-24 09:41:03 +01:00
Riccardo Casatta 6fa8a82414
Merge rust-bitcoin/rust-bitcoin#695: BIP341 test vectors
7aacc3782a Add tests from BIP341 (sanket1729)
61629cc733 Make taproot hashes forward display (sanket1729)

Pull request description:

  Add tests for taproot.
  - ~Also fixes one bug in #677, namely, I was returning `LeafVersion::default()` instead of given version~
  - ~ Fixes a bug in #691 about taking secp context as a reference instead of consuming it. This should have not passed my review, but this is easy to miss. ~
  - Makes the display on taproot hashes forward instead of the reverse (because the BIP prints in a forward way, I think we should too and it is more natural. )

ACKs for top commit:
  RCasatta:
    ACK 7aacc3782a
  apoelstra:
    ACK 7aacc3782a

Tree-SHA512: 2e0442131fc036ffa10f88c91c8fc02d9b67ff6c16c592aa6f4e6a220c26a00fc6ca95a288f14aa40667a289fb0446219fd6c76c0196ead766252356592b9941
2021-12-23 15:32:49 +01:00
Tobin Harding f690b8e362 Be more liberal when parsing Denomination
There is no reason to force users to use one particular form when
providing a denomination string. We can be liberal in what we accept
with no loss of clarity.

Allow `Denomination` strings to use a variety of forms, in particular
lower case and uppercase.

Note, we explicitly disallow various forms of `Msat` because it is
ambiguous whether this means milli or mega sats.

Co-developed-by: Martin Habovštiak <martin.habovstiak@gmail.com>
2021-12-22 13:51:11 +11:00
Martin Habovstiak 779d4110c6 Fixed a bunch of clippy lints, added clippy.toml
This is the initial step towards using and maybe enforcing clippy.
It does not fix all lints as some are not applicable. They may be
explicitly ignored later.
2021-12-21 22:50:13 +01:00
Riccardo Casatta fe43e3c9d7
Merge rust-bitcoin/rust-bitcoin#710: Refactor bitcoin_merkle_root functions
b454cf8e15 Return None from merkle_root functions (Tobin Harding)
7a8b017ea3 Use correct spelling of merkle (Tobin Harding)

Pull request description:

  ~Do two minor refactorings to the `bitcoin_merkle_root[_inline] functions.~

  This PR has grown, is no longer a refactoring because the two functions have been changed to return an `Option`.

  First patch is cleanup. Here is the commit message for the second patch
  ```
  The merkle_root of an empty tree is undefined, this is the only error
  case we have for the two `bitcoin_merkle_root*` functions. We can fully
  describe this error case by returning an `Option` if args are found to
  be empty.

  While we are at it, refactor out a recursive helper function to make
  reading the code between the two functions easier.
  ```

ACKs for top commit:
  Kixunil:
    ACK b454cf8e15
  dr-orlovsky:
    ACK b454cf8e15

Tree-SHA512: 961714a8b0eb0dad493a1548317d875d64ca22d2d584c905c502369b5f6e5a9f8be1edd7345136b44964dc0bde7a4c43bfaff4287d1dbf7fd736da79818074e3
2021-12-16 09:48:29 +01:00
Riccardo Casatta e5c6d6559d
Merge rust-bitcoin/rust-bitcoin#742: add MAX_MONEY public constant to Amount
ab12410ae8 add MAX_MONEY public constant to Amount (z8674558)

Pull request description:

  Closes https://github.com/rust-bitcoin/rust-bitcoin/issues/740

ACKs for top commit:
  Kixunil:
    ACK ab12410ae8
  RCasatta:
    ACK ab12410ae8

Tree-SHA512: dfba40d8ae597d97653e13ba2ab1480822d5d75343da487e3d3e57cf6821bcc567d5a883be6fd76a3e1c7d60925fedc3a5a864789cf6370c6ebda0b1d02acdd1
2021-12-16 09:28:07 +01:00
Riccardo Casatta 970f574968
Merge rust-bitcoin/rust-bitcoin#702: Separate signature hash types
8361129518 Add SchnorrSig type (sanket1729)
94cfe79170 Rename existing SigHashType to EcdsaSigHashType (sanket1729)
648b3975a5 Add SchnorrSigHashType::from_u8 (sanket1729)
410e8bf46c Rename sighash::SigHashType::SigHashType to SchnorrSigHashType (sanket1729)
fa112a793a Add EcdsaSig (sanket1729)

Pull request description:

  Fixes #670 . Separates `SchnorrSigHashType` and `LegacySigHashType`. Also adds the following new structs:

  ```rust
  pub struct SchnorrSig {
      /// The underlying schnorr signature
      pub sig: secp256k1::schnorrsig::Signature,
      /// The corresponding hash type
      pub hash_ty: SchnorrSigHashType,
  }

  pub struct EcdsaSig {
      /// The underlying DER serialized Signature
      pub sig: secp256k1::Signature,
      /// The corresponding hash type
      pub hash_ty: LegacySigHashType,
  }
  ```

  This code is currently minimal to aid reviews. We can at a later point implement (Encodeable, psbt::Serialize, FromHex, ToHex) etc in follow-up PRs.

ACKs for top commit:
  Kixunil:
    ACK 8361129518
  RCasatta:
    ACK 8361129518

Tree-SHA512: 800ddcb3677a4f19e9d1c2a7eb7e95b0a677e9135e1e99f9e42956fc6a3fc94f639403076b4925b3adba6fdd95f56a99c2e47d0310675ad51ce5e7453c7355b6
2021-12-15 16:50:55 +01:00
sanket1729 36f3d230b8
Merge rust-bitcoin/rust-bitcoin#643: util/address: make address encoding more modular
506e03fa4d util/address: use hash functions of PublicKey/Script (Marko Bencun)
f826316c25 util/address: avoid .expect/panic (Marko Bencun)
ad83f6ae00 util/address: make address encoding more modular (Marko Bencun)

Pull request description:

  This allow library clients to plug their own encoding parameters in a
  backwards compatible manner.

Top commit has no ACKs.

Tree-SHA512: ae2ececbdfe4984fd62c975f4956686d79f6f5a6e65c34b55daa76fe785b8483ed7f35208d36b8bee545c7edd39ac878277a0fb8ea8c64a1943081e15c818bff
2021-12-15 20:17:45 +05:30
sanket1729 8361129518 Add SchnorrSig type
Export Sigs/Sigerrors
2021-12-15 20:00:52 +05:30
sanket1729 94cfe79170 Rename existing SigHashType to EcdsaSigHashType 2021-12-15 20:00:52 +05:30
sanket1729 648b3975a5 Add SchnorrSigHashType::from_u8 2021-12-15 20:00:52 +05:30
sanket1729 410e8bf46c Rename sighash::SigHashType::SigHashType to SchnorrSigHashType 2021-12-15 20:00:52 +05:30
sanket1729 fa112a793a Add EcdsaSig 2021-12-15 20:00:51 +05:30
z8674558 ab12410ae8 add MAX_MONEY public constant to Amount 2021-12-15 19:00:28 +09:00
sanket1729 b3cd308447
Merge rust-bitcoin/rust-bitcoin#743: add helpful message to division-by-zero panic
3e19983aa0 add helpful message to division-by-zero panic (z8674558)

Pull request description:

  Closes https://github.com/rust-bitcoin/rust-bitcoin/issues/739

ACKs for top commit:
  Kixunil:
    ACK 3e19983aa0
  sanket1729:
    cr ACK 3e19983aa0

Tree-SHA512: 60555da91e3c3053206b8c22c5b45f843b2f0fdfbfe46ff324c6ba49f64339447acd551991baecad2f411415f0ee7c50400df3f08465d8150bad264c50ed6c5d
2021-12-15 14:23:49 +05:30
z8674558 3e19983aa0 add helpful message to division-by-zero panic 2021-12-15 01:50:56 +09:00
Riccardo Casatta 9ca6c75b18
Bench StreamReader 2021-12-12 17:33:24 +01:00
sanket1729 7aacc3782a Add tests from BIP341 2021-12-12 21:49:36 +05:30
sanket1729 61629cc733 Make taproot hashes forward display 2021-12-12 21:38:17 +05:30
Dr. Maxim Orlovsky d0a87bea72 Add slice 'serialize' method for TweakedPublicKey 2021-12-12 16:24:31 +02:00
Dr. Maxim Orlovsky 37352d1df5 Add Display and LowerHex to TweakedPublicKey 2021-12-12 16:23:57 +02:00
Marko Bencun 506e03fa4d
util/address: use hash functions of PublicKey/Script
Simpler code, less duplication.
2021-12-12 13:11:15 +01:00
Marko Bencun f826316c25
util/address: avoid .expect/panic 2021-12-12 13:11:15 +01:00
Marko Bencun ad83f6ae00
util/address: make address encoding more modular
This allow library clients to plug their own encoding parameters in a
backwards compatible manner.
2021-12-12 13:10:48 +01:00
Dr. Maxim Orlovsky ed40f3d3a6
Merge rust-bitcoin/rust-bitcoin#728: Use un/tweaked public key types
b5bf6d7319 Improve rustdocs on schnorr module (Tobin Harding)
a6d3514f2b Return parity when doing tap_tweak (Tobin Harding)
7af0999745 Re-name TweakedPublicKey constructor (Tobin Harding)
3c3cf0396b Remove use of unreachable in error branch (Tobin Harding)
d8e42d153e Remove 'what' comments (Tobin Harding)
b60db79a3b Use un/tweaked public key types (Tobin Harding)
402bd993b2 Add standard derives to TweakedPublickKey (Tobin Harding)
9c015d9ce3 Add newline to end of file (Tobin Harding)

Pull request description:

  We have two types for tweaked/untweaked schnorr public keys to help users of the taproot API not mix these two keys up. Currently the `taproot` module uses 'raw' `schnoor::PublicKey`s.

  Use the `schnoor` module's tweak/untweaked public key types for the `taproot` API.

  Fixes: #725

  Please note, I saw this was labeled 'good-first-issue' but I ignored that and greedily implemented a solution because of two reasons
  1. We want to get taproot stuff done post haste.
  2. I'm struggling to follow what is going on with all the taproot work so this seemed like a way to get my hands dirty.

ACKs for top commit:
  dr-orlovsky:
    utACK b5bf6d7319
  sanket1729:
    ACK b5bf6d7319

Tree-SHA512: e3e0480e0d193877c33ac11d0e3a288b0393d9475b26056914e439cb3f19583c1936e70d048df8d2120a36a63b6b592d12e21ca3ab7e058dce6f8f873c3b598b
2021-12-12 08:31:50 +02:00
Dr. Maxim Orlovsky 9ae0f05d74
Merge rust-bitcoin/rust-bitcoin#701: Decrease Huffman Weights to u32
1518517374 Decrease Huffman weight type to 32 bits (Jeremy Rubin)

Pull request description:

  This builds on https://github.com/rust-bitcoin/rust-bitcoin/pull/699 but is the more bikesheddable part since it changes the API.

  > u32 of weight should be enough for any branch.
  -- Bill Gates

ACKs for top commit:
  dr-orlovsky:
    utACK 1518517374
  Kixunil:
    ACK 1518517374

Tree-SHA512: 9c507ae6129dda8dc069b0a142181a78cf89cb3ebf9d2169c46662822cb4ea9ed075bf484528f5399fe0ed383a425174a702e2d685f31c246f5a86c46ed17c3a
2021-12-11 22:41:16 +02:00
Tobin Harding b5bf6d7319 Improve rustdocs on schnorr module
Improve the docs by doing:

- Use [`Foo`] for types
- Use third person tense
- Add trailing periods
2021-12-10 11:46:20 +11:00
Tobin Harding a6d3514f2b Return parity when doing tap_tweak
Currently we calculate the parity during `tap_tweak` but do not return
it, this means others must re-do work done inside `tap_tweak` in order
to calculate the parity. We can just return the parity along with the
tweaked key.
2021-12-10 11:45:58 +11:00
Tobin Harding 7af0999745 Re-name TweakedPublicKey constructor
Keeping inline with the method on `UntweakedPublicKey` that outputs a
`TweakedPublicKey` we can use the same name, for the same reasons.

Use `dangerous_assume_tweaked` as the constructor name to highlight the
fact that this constructor should probably not be being used.
2021-12-10 11:45:06 +11:00
Tobin Harding 3c3cf0396b Remove use of unreachable in error branch
We currently run `tweak_add_check` and use the result as a conditional
branch, the error path of which uses `unreachable`. This usage of
`unreachable` is non-typical. An 'unreachable' statement is by
definition supposed to be unreachable, it is not clear why we would need
to have a conditional branch to check an unreachable statement.

Use `debug_assert!` so programmer errors get caught in un-optimised
builds but in optimised builds the call to `tweak_add_check` is not even
done.
2021-12-10 11:37:07 +11:00
Tobin Harding d8e42d153e Remove 'what' comments
When used, code comments should say _why_ we do something not _what_ we
do, the code already says what we do.

Remove 'what we do' style comments.
2021-12-10 11:37:07 +11:00
Tobin Harding b60db79a3b Use un/tweaked public key types
We have two types for tweaked/untweaked schnorr public keys to help
users of the taproot API not mix these two keys up. Currently the
`taproot` module uses 'raw' `schnoor::PublicKey`s.

Use the `schnoor` module's tweak/untweaked public key types for the
`taproot` API.
2021-12-10 11:37:07 +11:00
Tobin Harding 402bd993b2 Add standard derives to TweakedPublickKey
All new types in `rust-bitcoin` should use our standard set of derives.

Add said standard derives to `TweakedPublickKey`.
2021-12-10 11:37:07 +11:00
Tobin Harding 9c015d9ce3 Add newline to end of file
Idiomatic UNIX file handling leaves files with a newline at the end.

Add newline to end of `schnorr` module.
2021-12-10 11:37:07 +11:00
Tobin Harding b454cf8e15 Return None from merkle_root functions
The merkle_root of an empty tree is undefined, this is the only error
case we have for the two `bitcoin_merkle_root*` functions. We can fully
describe this error case by returning an `Option` if args are found to
be empty. We can do the same for the wrapper functions in `block`
module.

While we are at it, refactor out a recursive helper function to make
reading the code between the two functions easier.
2021-12-10 11:24:30 +11:00
Tobin Harding 7a8b017ea3 Use correct spelling of merkle
Fix typo in test function name to use the correct spelling of
'merkle' (not 'merkel').
2021-12-10 11:18:23 +11:00
Tobin Harding 628168e493 Add missing white space character 2021-12-10 10:03:15 +11:00
Riccardo Casatta 31f0beb8df
Merge rust-bitcoin/rust-bitcoin#733: Super-trivial: Implement `FusedIterator` for `Instructions`
04a8f89f05 Implement `FusedIterator` for `Instructions` (Martin Habovstiak)

Pull request description:

  `Instructions` guarantee to return `None` from empty iterator so we
  should signal this in type system so that the code can be optimized
  better. This also adds a test to make sure this property holds.

ACKs for top commit:
  sanket1729:
    utACK 04a8f89f05. Any special reasons for doing this?
  RCasatta:
    ACK 04a8f89f05

Tree-SHA512: 3c6284e97e3bdd28ac5e948e3e9946eb8aa285cba753a6a0bdcbf971ebceab6d93c206d284128c232531b3de5996ece91187e4369d88bdfe6c531b4b7f787dd8
2021-12-03 11:07:57 +01:00
Dr. Maxim Orlovsky 95cf9b0a44
Merge rust-bitcoin/rust-bitcoin#697: Use TapTweakHash::from_key_and_tweak() method in computing tweak for UntweakedPublicKey
5b21a9cb1f Use TapTweakHash method for computing tweak (Noah)

Pull request description:

  Quick follow up PR to #691 using a method from #677.

  ### Changes
  - Updated `UntweakedPublicKey::tap_tweak(...)` to use `TapTweakHash::from_key_and_tweak(...)`

ACKs for top commit:
  Kixunil:
    ACK 5b21a9cb1f
  dr-orlovsky:
    utACK 5b21a9cb1f

Tree-SHA512: d00455bba51981e9ec942a6cf69672666e227850d073b1fdcd92d2eb6ad553659fb2967aec2ce12d3ed109cee5fa125cdda649cddb25404f08adae2bfd3e19bb
2021-12-02 10:43:50 +02:00
Martin Habovstiak 04a8f89f05 Implement `FusedIterator` for `Instructions`
`Instructions` guarantee to return `None` from empty iterator so we
should signal this in type system so that the code can be optimized
better. This also adds a test to make sure this property holds.
2021-12-01 21:38:46 +01:00
Riccardo Casatta 51b1abdab2
Merge rust-bitcoin/rust-bitcoin#719: Use expect instead of unwrap for calls to consensus_encode
e7b84e20d3 Use expect for concensus_encode on Vec (Tobin Harding)
4031fbf4ba Use expect for concensus_encode on sinks (Tobin Harding)
fa513bb5b5 Use expect for concensus_encode on engines (Tobin Harding)
a2efafcf9a Use error instead of err (Tobin Harding)

Pull request description:

  Calls to `unwrap` outside of tests are generally unfavourable. We currently call `unwrap` in a bunch of places on calls to `consensus_encode` when passing writers that do not fail.

  Remove `unwrap` calls on all calls to `consensus_encode` that pass a writer argument for which write functions do not fail. Use `expect` with a descriptive string instead.

  Fixes: #714

ACKs for top commit:
  Kixunil:
    ACK e7b84e20d3
  RCasatta:
    ACK e7b84e20d3

Tree-SHA512: 3f84598a14ecf3dcde4f418ad1a1dc5278b3ef8b2604f4e9fc4cf4e9aed8390a4a1cf0df47edb5956cc5b667d6c8864e34621c0dae974ea75d6daf1b133165dd
2021-12-01 10:57:27 +01:00
Tobin Harding e7b84e20d3 Use expect for concensus_encode on Vec
Calls to `unwrap` outside of tests are typically unfavourable.

In memory writers (`Vec`) do not error. We can use `expect` with a
descriptive message string to indicate this.
2021-11-25 10:07:25 +11:00
Tobin Harding 4031fbf4ba Use expect for concensus_encode on sinks
Calls to `unwrap` outside of tests are typically unfavourable.

Sink writers do not error. We can use `expect` with a descriptive
message string to indicate this.
2021-11-25 10:04:21 +11:00
Tobin Harding fa513bb5b5 Use expect for concensus_encode on engines
Calls to `unwrap` outside of tests are typically unfavourable.

Hash engines do not error when calling `consensus_encode`. Instead of
the current usage of `unwrap` we can use `expect` with a descriptive
string as is done in other parts of the codebase.
2021-11-25 10:01:41 +11:00
Jeremy Rubin 1518517374 Decrease Huffman weight type to 32 bits 2021-11-24 14:55:34 -08:00
Tobin Harding a2efafcf9a Use error instead of err
In the name of uniformity use the same error message as argument to
`expect` througout the codebase.

Use "engines don't error" instead of "engines don't err".
2021-11-25 09:51:30 +11:00
Noah 5b21a9cb1f Use TapTweakHash method for computing tweak 2021-11-25 09:45:27 +11:00
Jeremy Rubin 3b968e482c Add Huffman Encoding Test 2021-11-24 12:21:55 -08:00
Dr Maxim Orlovsky 5286d0ab0c
Merge rust-bitcoin/rust-bitcoin#699: Huffman Bug Fix
f2a6827982 Fix BinaryHeap direction for Taproot Huffman Encoder (Jeremy Rubin)
cccd75d004 Fix Weighting Addition to never error on overflow + prevent overflows from ever happening with wider integers (Jeremy Rubin)

Pull request description:

  I noticed one cleanup & one bugfix while looking into the huffman algorithm:

  1) the cleanup: we can use a u128 to guarantee no overflows, and saturating_add to guarantee reasonable behavior in any case
  2) the bug: the binary heap is a max heap so the behavior ends up merging the nodes of the most likely entries repeatedly. a huffman encoder requires merging the least likely elements, so it should be reversed.

ACKs for top commit:
  sanket1729:
    ACK f2a6827982
  dr-orlovsky:
    utACK f2a6827982

Tree-SHA512: 07cadb8dd5cc2b7e6ae3ebc2c1639de054e41bcd7f3b7d338a93e77fd200c9591a89915aaae5d9f5313eff3d94032fdfe06d89fda1e2398881b711d149e9afe9
2021-11-23 19:23:03 +01:00
Dr Maxim Orlovsky d614b6c759
Merge rust-bitcoin/rust-bitcoin#704: util/address: Improve docs
822c99222d Improve constructor rustdocs for Address (Tobin Harding)
804a38cb67 Improve documentation of `WitnessVersion` (Tobin Harding)
eb8278fd2e util/address: Improve docs (Tobin Harding)

Pull request description:

  Improve documentation of the `address` module by doing:

  - Add full stops to all sentences
  - Use code ticks even inside links e.g., [`WitnessVersion`]
  - Use 100 character line length
  - Do grammar fixes
  - Use comment sections (e.g. `# Returns`)
  - Use 3rd person for function comments e.g. 'Converts foo to bar' instead of 'Convert foo to bar'
  - Use ticks for scriptPubkey

  This patch does a single file because a bunch of these changes pick an
  arbitrary stlye, if we can bikeshed on this PR then future PRs should be
  able to progress more quickly. I'll take lack of comment on any of the
  above as approval and I'll attempt to be uniform when doing the rest of
  the codebase. I plan on just chipping away at this, I can only do so
  much docs work in a day without getting bored of it :)

  Notes:

  - I didn't touch 'segwit' vs 'SegWit', seems both are widely used.
  - Using ticks inside links may be an overkill but seems more correct?
  - I'm not totally sure where the line is in the Rust ecosystem between
    readability in an editor and rendering as HTML, open to input on this.

ACKs for top commit:
  Kixunil:
    ACK 822c99222d
  dr-orlovsky:
    ACK 822c99222d

Tree-SHA512: bfbaeec74803dd0704ed3e39b9a4966db34dbb3d7ea850ed6230abf220b877687ac1479f4940b7bf39d7e8172cd62c36b232bfaa8186a92cc58b3d7e642674f6
2021-11-23 18:00:55 +01:00
Dr Maxim Orlovsky 435298c427
Merge rust-bitcoin/rust-bitcoin#707: P2tr fixes
e4774e74eb fixups to taptweaking code (sanket1729)

Pull request description:

  This was my bad for not clearly stating the expected spec #687 . Changed values to references so that we only take ownership where it is required.

  This should simplify the #697

ACKs for top commit:
  Kixunil:
    ACK e4774e74eb
  dr-orlovsky:
    utACK e4774e74eb

Tree-SHA512: adacbfa8a77f46b2c85720f3760ed12a437f40d8422731d0207662d7947c95dda79d576923f6056c77f57977a3dcd25afd270f0ee11e9c3be9d067ccdc63371a
2021-11-23 17:41:31 +01:00
Tobin Harding e04795093f Add unit test for bitcoin_merkle_root functions
We test `bitcoin_merkle_root` over in the `blockdata::block` module.
Although the `bitcoin_merkle_root` and `bitcoin_merkle_root_inline`
functions are almost identical there is enough index manipulation done
that it is not immediately obvious that the code is error free.

Add a unit test that verifies that the two functions return the same
resulting merkle root.
2021-11-22 13:03:31 +11:00
sanket1729 e4774e74eb fixups to taptweaking code 2021-11-21 11:53:55 -08:00
Tobin Harding 822c99222d Improve constructor rustdocs for Address
Improve the rustdocs for the various `Address` constructors by putting
the brief description on a separate line with further description in its
own paragraph. This is the layout best practice for function documentation
using rustdocs.

Also, favour 'creates' over 'constructs' because it is more common in
the docs of this struct.
2021-11-19 09:42:19 +11:00
Tobin Harding 804a38cb67 Improve documentation of `WitnessVersion`
Attempt to improve the rustdocs for `WitnessVersion` in line with
review comments from a previous patch.
2021-11-19 09:35:14 +11:00
Tobin Harding eb8278fd2e util/address: Improve docs
Improve documentation of the `address` module by doing:

- Add full stops to all sentences
- Use code ticks even inside links e.g., [`WitnessVersion`]
- Use 100 character line length
- Do grammar fixes
- Use comment sections (e.g. `# Returns`)
- Use 3rd person for function comments e.g. 'Converts foo to bar' instead of 'Convert foo to bar'
- Use ticks for scriptPubkey

This patch does a single file because a bunch of these changes pick an
arbitrary stlye, if we can bikeshed on this PR then future PRs should be
able to progress more quickly. I'll take lack of comment on any of the
above as approval and I'll attempt to be uniform when doing the rest of
the codebase. I plan on just chipping away at this, I can only do so
much docs work in a day without getting bored of it :)

Notes:

- I didn't touch 'segwit' vs 'SegWit', seems both are widely used.
- Using ticks inside links may be an overkill but seems more correct?
- I'm not totally sure where the line is in the Rust ecosystem between
  readability in an editor and rendering as HTML, open to input on this.
2021-11-18 09:43:08 +11:00
sanket1729 df72500465
Merge rust-bitcoin/rust-bitcoin#703: Return the correct `LeafVersion` when building a Taproot `ControlBlock`
0af5a433b6 Return the correct `LeafVersion` when building a Taproot `ControlBlock` (Alekos Filini)

Pull request description:

ACKs for top commit:
  sanket1729:
    ACK 0af5a433b6

Tree-SHA512: 6b887e86b32b070a2a42ba1a2309b094c36d5a0b0bbf7d4c49c4fd2d8d2b4a7b1d87da699f1bd5f7116926c590413609a292d900b55c27c6bdbadc408529999f
2021-11-16 14:59:39 -08:00
sanket1729 e66a94fa40
Merge rust-bitcoin/rust-bitcoin#683: tests: improve coverage for P2tr and AddressType
0d463ec19e tests: improve coverage for P2tr and AddressType (Leonardo Comandini)

Pull request description:

  The new AddressType test shows addresses that are valid but have
  no type. If in the future some of those get a type or become
  invalid (either voluntarily or due to a regression), this will
  highlight it.

ACKs for top commit:
  dr-orlovsky:
    utACK 0d463ec19e
  sanket1729:
    ACK 0d463ec19e

Tree-SHA512: 9e062a1807173638cb62a61a2e8ea5be8324449a8944c356073e8bd9f53941dea369c65a35dfa0019bd8323eaa5dd26a9907c1823522fef9a524e919728973a6
2021-11-16 08:49:13 -08:00
Martin Habovštiak ab97d2db1a
Merge pull request #689 from tcharding/module-rustdocs
Clean up module level rustdocs
2021-11-16 13:21:20 +01:00
Alekos Filini 0af5a433b6
Return the correct `LeafVersion` when building a Taproot `ControlBlock` 2021-11-16 11:45:23 +01:00
Tobin Harding dbb3edd482 Add deprecation comment
Module `contracthash` is deprecated, add this info to the module
rustdoc.
2021-11-16 13:01:51 +11:00
Leonardo Comandini 0d463ec19e
tests: improve coverage for P2tr and AddressType
The new AddressType test shows addresses that are valid but have
no type. If in the future some of those get a type or become
invalid (either voluntarily or due to a regression), this will
highlight it.
2021-11-15 21:36:13 +01:00
Jeremy Rubin f2a6827982 Fix BinaryHeap direction for Taproot Huffman Encoder 2021-11-15 09:38:44 -08:00
Jeremy Rubin cccd75d004 Fix Weighting Addition to never error on overflow + prevent overflows from ever happening with wider integers 2021-11-15 09:38:44 -08:00
Marko Bencun 8b1dbf5c9f
util/address: remove unused generic type 2021-11-14 13:10:40 +01:00
sanket1729 abc242dfe1
Merge rust-bitcoin/rust-bitcoin#654: Making globals part of PSBT struct. Closes #652
55c627715f Moving globals into PSBT struct (Dr Maxim Orlovsky)

Pull request description:

  I took the most non-invasive approach to reduce diff size. Many parts of the code can be improved in style or further refactored (like some functions are not necessary and can be just moved to be part of other functions), but I'd prefer to do that as a separate PR once this will be merged.

  My approach with this PR:
  1. Remove `Global` struct by moving its fields right into `PartiallySignedTransaction` - but keep the `util/psbt/map/global.rs` file with all its logic
  2. Keep existing `Map for Global` implementation in the same file, but just change it to `Map for PartiallySignedTransaction`
  3. With serialization, convert `Global` deserialization into crate-private function and use it from `PartiallySignedTransaction` deserialization
  4. Refactor the tests and imports as required to get the thing compile and pass tests

  The refactoring will be followed by PR(s) adding support for Taproot

ACKs for top commit:
  apoelstra:
    ACK 55c627715f
  sanket1729:
    ACK 55c627715f . Reviewed range diff with ac0c908 that I previously ACKed

Tree-SHA512: 79b329b6e4e60af905e4e00507d6abc558261d921bcf8f5d4ee34dd685322d7a529b18015423da50a388ba6732b7b662a92bc95ad078228cc809254ad010d467
2021-11-12 11:50:51 -08:00
Dr. Maxim Orlovsky 5631ec521e
Merge pull request #691 from nlanson/p2tr_address
P2TR address from untweaked key
2021-11-12 20:33:19 +01:00
sanket1729 fa8c3f6e44 Add tests for taproot utilities
Add tests for taproot Builder
Add tests for taproot huffman tree encoding
Add tests for merkle proof verification
2021-11-12 05:56:51 -08:00
sanket1729 1490ff36ee Add support for verifying merkle proofs 2021-11-12 05:56:51 -08:00
sanket1729 15f99df4ba Add huffman tree encoding 2021-11-12 05:56:51 -08:00
Noah Lanson 803b5fed8a P2TR address from untweaked public key
Ambiguous TweakedPublicKey and UntweakedPublicKey type aliases and methods to convert

Use structs for Untweaked and Tweaked key type

swap dangerous api to work on tweaked keys

remove unecessary allocations and rename methods

Use type alias for UntweakedPublicKey

TweakedPublicKey::new(...) method added

minor naming and doc changes
2021-11-11 14:36:56 +11:00
sanket1729 03f01b9965 Add taproot builder 2021-11-10 07:33:31 -08:00
sanket1729 e387cd1f7f Add taprootSpendInfo 2021-11-10 07:01:46 -08:00
sanket1729 b8e5909e04 Update sighash code to use LeafVersion instead of bare u8 2021-11-10 07:01:46 -08:00
sanket1729 ce887d373e Add taproot structures for Merkle Branch and ControlBlock 2021-11-10 07:01:45 -08:00
Tobin Harding 3f5caa501f Clean up module level rustdocs
Docs can always do with a bit of love.

Clean up the module level (`//!`) rustdocs for all public modules.

I claim uniform is better than any specific method/style. I tried to fit
in with what ever was either most sane of most prevalent, therefore
attaining uniformity without unnecessary code churn (one exception being
the changes to headings described below).

Notes:

* Headings - use heading as a regular sentence for all modules e.g.,

```
//! Bitcoin network messages.
```

as opposed to
```
//! # Bitcoin Network Messages
```

It was not clear which style to use so I picked a 'random' mature
project and copied their style.

* Added 'This module' in _most_ places as the start of the module
description, however I was not religious about this one.

* Fixed line length if necessary since most of our code seems to follow
short (80 char) line lengths for comments anyways.

* Added periods and fixed obvious (and sometimes not so obvious)
grammatically errors.

* Added a trailing `//!` to every block since this was almost universal
already. I don't really like this one but I'm guessing it is Andrew's
preferred style since its on the copyright notices as well.
2021-11-06 10:59:53 +11:00
Martin Habovstiak 49bd3af449 Refactor Script::bytes_to_asm_fmt to use iterator
This refactors `Script::bytes_to_asm_fmt`` function to use an iterator
instead of index. Such change makes it easier to reason about overflows
or out-of-bounds accesses. As a result this also fixes three unlikely
overflows and happens to improve formatting to not output space at the
beginning in some weird cases.

To improve robustness even better it also moves `read_uint`
implementation to internal function which returns a more specific error
type which can be exhaustively matched on to guarantee correct error
handling. Probably because of lack of this the code was previously
checking the same condition twice, the second time being unreachable and
attempting to behave differently than the first one.

Finally this uses macro to deduplicate code which differs only in single
number, ensuring the code stays in sync across all branches.
2021-09-30 14:33:10 +02:00
Andrew Poelstra 454379cdfa
Merge rust-bitcoin/rust-bitcoin#612: Fix `Uint256::increment` panics
5d71a9dd89 Correct input length check for uin128 fuzzer (Matt Corallo)
9c256cc88e Add a fuzz check for `Uint128::increment` (Matt Corallo)
a15f263c4e Move the `increment` fn into the uint macro to add it to Uint128 (Matt Corallo)
d52b88b525 Fix increment of Uint256 with carry (carolcapps)

Pull request description:

  This is #578 with review feedback addressed.

ACKs for top commit:
  apoelstra:
    ACK 5d71a9dd89
  sanket1729:
    ACK 5d71a9d

Tree-SHA512: 32e5ea6387943ecad8f190a0de336a545fda72b6ff7388d3479037a5f880434276a7d0607f5cf61710d45e984c01954f4e3199a60c542be48b397717afb3d406
2021-09-27 17:45:53 +00:00
Dr. Maxim Orlovsky e49cdbd8e2
Merge pull request #563 from LNP-BP/taproot/address 2021-09-25 22:56:33 +02:00
Andrew Poelstra 9fe840c20e
Merge pull request #644 from sanket1729/tap_opcodes
Add OP_CHECKSIGADD and OP_SUCCESSxxx
2021-09-24 22:47:48 +00:00
Antoine Poinsot 826fed53f2
transactions: add a note about `get_vsize` and standardness rules
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-09-24 19:48:36 +02:00
Dr Maxim Orlovsky c1991d748f
Improving error information for address parser 2021-09-21 12:45:17 +02:00
Clark Moody eeeb722155
Bump bech32 to 0.8.0 and use BIP-0350 Bech32m checksum
Replace BIP-0173 test vectors with those in BIP-0350.
2021-09-21 12:45:17 +02:00
Dr Maxim Orlovsky 5573a546ca
Taproot P2TR address 2021-09-21 12:45:17 +02:00
Martin Habovstiak 083f5f3138 Document lack of support for 16-bit pointers
This clearly states lack of support for 16-bit architectures as well as
adds readable `compile_error!()` call. It also fixes a few stylistic
mistakes - headings (top-level should not be repeated) and missing
newlines.

Closes #660
2021-09-20 21:31:46 +02:00
Andrew Poelstra 29549ccc73
Merge rust-bitcoin/rust-bitcoin#658: Check for overflow in Script::bytes_to_asm_fmt()
76cf74fa9b Added test for the overflow bug and few others (Martin Habovstiak)
a0e1d2e706 Check for overflow in Script::bytes_to_asm_fmt() (Martin Habovstiak)

Pull request description:

  This adds an overflow check in `Script::bytes_to_asm_fmt()` motivated by
  `electrs` issue. While it was not tested yet, I'm very confident that
  overflow is the cause of panic there and even if not it can cause panic
  becuase the public function takes unvalidated byte array and reads
  `data_len` from it.

  The `electrs` issue: https://github.com/romanz/electrs/issues/490

  ~~Strangely, this breaks a test case and I can't see why. I'm publishing in case someone wants to help.~~

  Edit: One damn character. :D Should be OK now.

ACKs for top commit:
  apoelstra:
    ACK 76cf74fa9b

Tree-SHA512: 4ffeca442a71b10c132f055f056128ae64e66cbdc1891662c3a4e743b82fa5d27075a44513e844be37888b33068eef3bbf6bcced5def70c17c9c5bd5b9d870cc
2021-09-20 14:22:44 +00:00
Martin Habovstiak 76cf74fa9b Added test for the overflow bug and few others
This adds a test case for script formatting which caused overflow in the
past and a few others from the same "interesting" transaction. Note that
to trigger the bug one has to run the test on 32 bit architecture.
2021-09-19 15:45:17 +02:00
Martin Habovstiak a0e1d2e706 Check for overflow in Script::bytes_to_asm_fmt()
This adds an overflow check in `Script::bytes_to_asm_fmt()` motivated by
`electrs` issue. While it was not tested yet, I'm very confident that
overflow is the cause of panic there and even if not it can cause panic
becuase the public function takes unvalidated byte array and reads
`data_len` from it.

The `electrs` issue: https://github.com/romanz/electrs/issues/490
2021-09-19 13:33:37 +02:00
Dr Maxim Orlovsky 55c627715f
Moving globals into PSBT struct 2021-09-16 12:34:04 +02:00
Dr. Maxim Orlovsky b7f984972a
Merge pull request #655 from vss96/Limit-Script-Size 2021-09-16 10:42:08 +02:00
Andrew Poelstra b6b60fc4aa
Merge rust-bitcoin/rust-bitcoin#628: Adds Taproot BIP341 signature message and create a unified sighash cache for legacy, segwit and taproot inputs
c704ee7ffe [docs-only] Use backtick in addition to square parentheses for types references, clarify legacy, non_exhaustive comment, remove std:: (Riccardo Casatta)
f223be618f Rename access_witness to witness_mut and return Option (Riccardo Casatta)
c9bc0b928a [fmt-only] autoformatting with `rustfmt src/util/sighash.rs` (Riccardo Casatta)
07774917c2 Use get_or_insert_with in segwit_cache (Martin Habovstiak)
497dbfb7c3 Use get_or_insert_with in common_cache() (Martin Habovstiak)
ca80a5a030 Use get_or_insert_with in taproot_cache (Martin Habovstiak)
6e06a32ccc Wrap ErrorKind in Io enum variant, fix doc comment for the IO variant (Riccardo Casatta)
1a2b54ff23 introduce constant KEY_VERSION_0 (Riccardo Casatta)
417cfe31e3 Derive common traits for structs and enum, make internal struct not pub (Riccardo Casatta)
55ce3dd6ae Fix validation error if SINGLE with missing corresponding output, remove check_index and check with get().ok_or(), more details in errors (Riccardo Casatta)
2b3b22f559 impl Encodable for Annex to avoid allocation (Riccardo Casatta)
1a7afed068 Add Reserved variant to SigHashType for future use (ie SIGHASH_ANYPREVOUT) (Riccardo Casatta)
53d0e176d3 Deprecate bip143::SigHashCache in favor of sighash::SigHashCache (Riccardo Casatta)
15e3caf62d [test] Test also sighash legacy API with legacy tests (Riccardo Casatta)
24acfe3672 Implement Bip341 signature hash, create unified SigHashCache for taproot, segwit and legacy inputs (Riccardo Casatta)
683b9c14ff add [En|De]codable trait for sha256::Hash (Riccardo Casatta)

Pull request description:

  Adds https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki message signature algorithm

  The base is taken from `bip143::SigHashCache`, some code results duplicated but I think it's more clear to keep things separated

  Would mark some bullet point on https://github.com/rust-bitcoin/rust-bitcoin/issues/503

  Test vectors are taken by running d1e4c56309/test/functional/feature_taproot.py with a modified `TaprootSignatureHash` function to print intermediate values that I cannot found in the bip341 [test vector json](https://raw.githubusercontent.com/bitcoin-core/qa-assets/main/unit_test_data/script_assets_test.json)

  UPDATE: Latest version includes the suggestion from @sanket1729 to create a unified tool for signature message hash for legacy, segwit, and taproot inputs. In particular, makes sense for mixed segwit v0 and taproot v1 inputs because cached values could be shared

ACKs for top commit:
  sanket1729:
    ACK c704ee7ffe. Reviewed the diff from a37de1ade475e0c31c932121abaa7aec701b9987 which I previously ACKed
  dr-orlovsky:
    utACK c704ee7ffe by diffing it to 6e06a32ccc having my ACK before.
  apoelstra:
    ACK c704ee7ffe

Tree-SHA512: 35530995fe9d078acd0178cfca654ca980109f4502c91d578c1a0d5c6cafacab7db1ffd6216288eac99f6a763776cbc0298cfbdff00b5a83e98ec4b15aa764e8
2021-09-15 17:47:17 +00:00
Vikas S Shetty 48c732e934 Changes for checking script size and returning Error appropriately 2021-09-15 16:16:20 +05:30
Dr Maxim Orlovsky c75f3ef4a8
Handling CHECKMULTISIG(VERIFY) ops in TapScript context; refactoring classifier 2021-09-14 13:58:16 +02:00
Martin Habovstiak 95fb4e01f9 Document cargo features
This documents cargo features in two ways: explictly in text and in code
using `#[doc(cfg(...))]` attribute where possible. Notably, this is
impossible for `serde` derives. The attribute is contitional and only
activated for docs.rs or explicit local builds.

This change also adds `package.metadata.docs.rs` field to `Cargo.toml`
which instructs docs.rs to build with relevant features and with
`docsrs` config activated enabling `#[doc(cfg(...))] attributes.

I also took the opportunity to fix a few missing spaces in nearby code.
2021-09-14 12:24:57 +02:00
Ben Carman 894f0f09b6
Add Bloom filter network messages
Co-authored-by: jrawsthorne <jake@jakerawsthorne.co.uk>
2021-09-13 15:08:38 -05:00
sanket1729 b0ad6748e4 Add tests for opcode classification 2021-09-13 07:45:15 -07:00
sanket1729 c252b36786 Add CHECKSIGADD and update classify API 2021-09-13 07:45:00 -07:00
Dr Maxim Orlovsky d20669522e
Fixing no_std for Amount sum iterator 2021-09-13 10:36:07 +02:00
Dr. Maxim Orlovsky b2c8a7ebc1
Merge pull request #615 from sgeisler/2021-06-sum-amounts
Implement `Sum` for amount types
2021-09-11 00:11:15 +02:00
Dr. Maxim Orlovsky 697e8f5194
Merge pull request #626 from visvirial/impl-vsize
Implement `Block.get_strippedsize()` and `Transaction.get_vsize()`
2021-09-11 00:09:22 +02:00
Andrew Poelstra 13a6c3b4d6
Merge rust-bitcoin/rust-bitcoin#625: Improvements to Error types (part 4)
994079b099 Refactoring error variants: removing unused; better names & inner types (Dr Maxim Orlovsky)

Pull request description:

  Removes controversial aspects from #560 (all `io::Error`-related changes) and leaves the rest

ACKs for top commit:
  sanket1729:
    ACK 994079b099
  apoelstra:
    ACK 994079b099

Tree-SHA512: 020e49193c885e862f45e5f7baabf1d22a3ec09e78fd7f573b2f3d327beb4f91683951ba080b3d804e8337a188dcad0f38ba70ee8059aef0681a0b2bba0a2140
2021-09-08 21:22:32 +00:00
Andrew Poelstra 2a655f4b58
Merge pull request #617 from LNP-BP/feat/witness-version
WitnessVersion type
2021-09-08 20:58:57 +00:00
Riccardo Casatta c704ee7ffe
[docs-only] Use backtick in addition to square parentheses for types references, clarify legacy, non_exhaustive comment, remove std:: 2021-08-31 13:58:48 +02:00
Riccardo Casatta f223be618f
Rename access_witness to witness_mut and return Option
fix the example in sighash to refer to sighash::SigHashCache instead of bip143::SigHashCache
2021-08-31 13:55:52 +02:00
Riccardo Casatta c9bc0b928a
[fmt-only] autoformatting with `rustfmt src/util/sighash.rs` 2021-08-31 13:54:41 +02:00
Sanket Kanjalkar bd5d875e8a
Merge pull request #623 from RCasatta/fixdoc
Fix documentation referencing macro var
2021-08-12 18:38:07 -07:00
Martin Habovstiak 07774917c2 Use get_or_insert_with in segwit_cache
This refactors the code to make it possible to use `get_or_insert_with`
instead of unwrapping in `segwit_cache()`. To achieve it `common_cache`
is refactored into two functions: one taking only the required borrows
and the original calling the new one. `segwit_cache` then calls the new
function so that borrows are OK.

Apart from removing unwrap, this avoids calling `common_cache` multiple
times.
2021-08-10 10:36:51 +02:00
Dr Maxim Orlovsky ecc400826c
Updating Script::is_witness_program to use new WitnessVersion 2021-08-10 10:34:15 +02:00
Dr Maxim Orlovsky 64c1ec0b76
WitnessVersion type 2021-08-10 10:34:15 +02:00
Martin Habovstiak 497dbfb7c3 Use get_or_insert_with in common_cache()
There was a question whether this is equally performant. There are
multiple good reasons why it should be:

1. `get_or_insert_with` is marked `#[inline]`
2. Any good optimizer will inline a function that is used exactly once
3. 1 and 2 conclude that the closure will get inlined
4. Computing self.tx can then be moved to the only branch where it is
   required.
5. Even if get_or_insert_with didn't get optimized, which is extremely
   unlikely, the `tx` field is at the beginning of the struct and it
   probably has pointer alignment (`Deref` suggests it's a pointer).
   Alignment larger than pointer is not used, so we can expect the
   fields to be ordered as-defined. (This is not guaranteed by Rust but
   there's not good reason to change the order in this case.) We can
   assume that offset to tx is zero in most cases which means no
   computation is actually needed so the expression before closure is
   no-op short of passing it into the closure as an argument.

At the time of writing `#[inline]` can be seen at
https://doc.rust-lang.org/src/core/option.rs.html#933
2021-08-10 10:20:41 +02:00
Martin Habovstiak ca80a5a030 Use get_or_insert_with in taproot_cache 2021-08-10 10:02:33 +02:00
Dr. Maxim Orlovsky 4e3c2c32fc
Merge pull request #632 from tcharding/prefixes 2021-08-09 23:26:15 +02:00
Dr. Maxim Orlovsky 8ae030b951
Merge pull request #618 from elsirion/possible_networks 2021-08-09 23:25:06 +02:00
Dr. Maxim Orlovsky 33393e0bf4
Merge pull request #621 from RCasatta/verify_with_amount 2021-08-09 23:23:09 +02:00
Dr. Maxim Orlovsky 808e1708c3
Merge pull request #596 from RCasatta/script_ser 2021-08-09 23:22:06 +02:00
Dr Maxim Orlovsky 994079b099
Refactoring error variants: removing unused; better names & inner types 2021-08-01 21:08:39 +02:00
Tobin Harding adc1543e7c
Use consts for address prefix values
Instead of using magic numbers we can define constants for the address
prefix bytes. This makes it easier for future readers of the code to see
what these values are if they don't know them and/or see that they are
correct if they do know them.
2021-07-22 10:31:14 +10:00
Riccardo Casatta 6e06a32ccc
Wrap ErrorKind in Io enum variant, fix doc comment for the IO variant 2021-07-21 12:07:12 +02:00
Riccardo Casatta 1a2b54ff23
introduce constant KEY_VERSION_0 2021-07-21 12:07:10 +02:00
Riccardo Casatta 417cfe31e3
Derive common traits for structs and enum, make internal struct not pub 2021-07-21 12:07:08 +02:00
Riccardo Casatta 55ce3dd6ae
Fix validation error if SINGLE with missing corresponding output, remove check_index and check with get().ok_or(), more details in errors 2021-07-21 12:07:05 +02:00
Riccardo Casatta 2b3b22f559
impl Encodable for Annex to avoid allocation 2021-07-21 12:07:00 +02:00
Riccardo Casatta 1a7afed068
Add Reserved variant to SigHashType for future use (ie SIGHASH_ANYPREVOUT) 2021-07-21 12:05:42 +02:00
Riccardo Casatta 53d0e176d3
Deprecate bip143::SigHashCache in favor of sighash::SigHashCache 2021-07-21 12:05:40 +02:00
Riccardo Casatta 15e3caf62d
[test] Test also sighash legacy API with legacy tests 2021-07-21 12:05:37 +02:00
Riccardo Casatta 24acfe3672
Implement Bip341 signature hash, create unified SigHashCache for taproot, segwit and legacy inputs 2021-07-21 12:05:18 +02:00
Riccardo Casatta 683b9c14ff
add [En|De]codable trait for sha256::Hash 2021-07-21 10:36:06 +02:00
Andrew Poelstra df4d70a37e
Merge pull request #627 from RCasatta/bigendian
Bigendian fixes and CI test
2021-07-20 20:56:16 +00:00
Devrandom 4826d0c6cc no_std support
Based on the original work by Justin Moon.

*MSRV unchanged from 1.29.0.*

When `std` is off, `no-std` must be on, and we use the [`alloc`](https://doc.rust-lang.org/alloc/) and core2 crates. The `alloc` crate requires the user define a global allocator.

* Import from `core` and `alloc` instead of `std`
* `alloc` only used if `no-std` is on
* Create `std` feature
* Create `no-std` feature which adds a core2 dependency to polyfill `std::io` features. This is an experimental feature and should be
used with caution.
* CI runs tests `no-std`
* MSRV for `no-std` is 1.51 or so
2021-07-15 09:04:49 +02:00
Riccardo Casatta 11d5a30f86
comment only: explain reason for swap bytes 2021-07-02 12:05:09 +02:00
Riccardo Casatta 0f4d2cfcaa
swap bytes in network code instead of swapping only in little-endian 2021-06-29 16:01:34 +02:00
Riccardo Casatta 8996249f2d
remove {to/from}_le from impl_int_encodable
they are a noop on little-endian and the following {to/from}_array_le are sufficient to deal with big-endian
2021-06-29 15:57:31 +02:00
Vis Virial cdf7be4765
Add extra checks for `test_segwit_transaction()`. 2021-06-29 07:59:22 +09:00
Vis Virial 2bda871628
Remove `#[inline]` from `Transaction.get_strippedsize()`. 2021-06-29 07:40:13 +09:00
Vis Virial c9dead410a
Implement `Transaction.get_strippedsize()`.
`Block.get_strippedsize()` is also simplified and optimized.
2021-06-29 07:34:37 +09:00
Vis Virial 1bf9147a6e
Optimize `Transaction.get_vsize()` (thanks @TheBlueMatt). 2021-06-29 07:14:01 +09:00
Vis Virial 2085dc32a7
Refactoring: define `Block.get_base_size()`. 2021-06-28 20:07:07 +09:00
Vis Virial 4ac9cef9e9
Implement `Block.get_strippedsize()` and `Transaction.get_vsize()`. 2021-06-28 20:03:42 +09:00
elsirion 94229ae964 Implement is_valid_for_network function for Address 2021-06-26 19:34:33 +02:00
Riccardo Casatta 8f27579c7f
fix documentation referencing macro var 2021-06-25 09:56:40 +02:00
Sebastian Geisler 4dae56908b Seal `CheckedSum` 2021-06-23 15:14:24 +02:00
Riccardo Casatta a86bced568
use Amount type in verify 2021-06-21 14:43:09 +02:00
Andrew Poelstra abff973e83
Merge pull request #601 from LNP-BP/feat/bech32m-1
Bech32m adoption
2021-06-18 21:14:12 +00:00
Sebastian e334c9deea
Merge pull request #616 from sgeisler/2021-06-dust-value-amount
Use `Amount` type for dust value calculation
2021-06-16 20:51:23 +02:00
Riccardo Casatta 4a4460b1a3
Add test for script serialize/deserialize 2021-06-16 10:17:56 +02:00
Riccardo Casatta fadd368911
use different ser/de for Script in case of non human readable format 2021-06-16 10:17:40 +02:00
Dr Maxim Orlovsky aa5c36df12
Covering all BIP-173 and BIP-350 test vectors 2021-06-16 08:43:18 +02:00
Sebastian b0ae2a6842
Merge pull request #521 from RCasatta/errors_enum
Errors enum improvements
2021-06-15 14:01:56 +02:00
Riccardo Casatta 88c186e436
nits on display implementation 2021-06-14 12:24:31 +02:00
Riccardo Casatta c26b3b9679
remove unused RngError, saving 24 bytes 2021-06-13 22:40:55 +02:00
Riccardo Casatta 9613181601
Split invalid version for address and extended key, saving also 16 bytes on the stack 2021-06-13 22:39:32 +02:00
Riccardo Casatta bace07d8f8
Remove base58::Error::Other variant in favor of specific variant 2021-06-13 22:33:54 +02:00
Riccardo Casatta 0eaf45ca81
Use boxed sliced instead of Vec in InvalidPreimageHashPair variant 2021-06-13 22:33:52 +02:00
Riccardo Casatta 781b0e014a
Box big Transaction type in psbt error 2021-06-13 22:33:48 +02:00
Sebastian Geisler 9981da2ec8 Use `Amount` type for dust value calculation 2021-06-12 21:15:13 +02:00
Sebastian Geisler 6f7da5f2ef Implement `CheckedSum` for amount types
It's just `Sum` with checked arithmetic.
2021-06-12 17:23:30 +02:00
Sebastian Geisler f28110b31c implement `Sum` for amount types
To be able to sum up iterators of amounts it is
not sufficient that these implement `Add`, they
also need to implement `Sum`.
2021-06-12 17:23:27 +02:00
Devrandom 95aa3bf153 std -> core 2021-06-11 17:28:04 +02:00
Matt Corallo a15f263c4e Move the `increment` fn into the uint macro to add it to Uint128 2021-06-08 22:20:36 +00:00
Sebastian Geisler 091ac89440 Fix semver breaking Display change of ChildNumber
Fixes #608. In #567 the Display impl for ChildNumber was
consciously changed, assuming the semver break would not
affect any correctly implemented downstream projects. We
were wrong.
2021-06-08 15:33:02 +02:00
Dr Maxim Orlovsky c1fae03686
Non-API breaking Bech32m adoption 2021-06-08 08:43:39 +02:00
Dr. Maxim Orlovsky 73f1ed7d4c
Merge pull request #606 from romanz/fix-bip158-format
Fix bip158 example formatting
2021-06-06 20:11:22 +02:00
Sebastian d7eb15c6f1
Merge pull request #584 from darosior/max_tx_weight_const
Introduce some policy constants from Bitcoin Core
2021-05-29 02:49:46 +02:00
Roman Zeyde 60e51ada36 Fix bip158 example formatting 2021-05-28 16:01:49 +03:00
Andrew Poelstra 052aaf1d80
Merge pull request #559 from LNP-BP/fix/error-derives-2
Fix/error derives 2
2021-05-19 15:02:10 +00:00
Antoine Poinsot 7345aa60d9 policy: add a function to get the virtual transaction size
It's very useful to Bitcoin applications, and especially "L2" ones, to
effectively compute feerates. Currently (and this is very unlikely to
change) bitcoind nodes compute the virtual size as a rounded-up division
of the size in witness units by 4, with a penalty for transactions that
are essentially >5% full of sigops.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-05-18 14:53:45 +02:00
Antoine Poinsot 2e9d62a9c7 blockdata/script: use policy's constant in dust computation
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-05-18 14:52:58 +02:00
Antoine Poinsot 2b777485fa policy: introduce p2p constants from the reference implementation
This introduces some constants defined by Bitcoin Core which as a
consequence define some network rules in a new 'policy' module.

Only some were picked, which are very unlikely to change. Nonetheless a
Warning has been put in the module documentation.

Script-level constants are left into rust-miniscript where they are
already defined (src/miniscript/limits.rs).
2021-05-18 14:52:56 +02:00
Matt Corallo 05046b58d3
Merge pull request #602 from LNP-BP/fix/core
Fixing hashes core dependency and fuzz feature
2021-05-07 19:49:43 +00:00
Andrew Poelstra e5f37b817d
Merge pull request #581 from RCasatta/qr_string
Address to optimized QR string
2021-05-06 17:12:17 +00:00
Andrew Poelstra 4620c640a9
Merge pull request #579 from TheBlueMatt/master
Fix Script::dust_value()'s calculation for non-P2*PKH script_pubkeys
2021-05-06 16:01:36 +00:00
Andrew Poelstra d0fb626baf
Merge pull request #592 from LNP-BP/feat/ecdsa-key-creation
Constructors for compressed and uncompressed ECDSA keys
2021-05-06 15:50:06 +00:00
Andrew Poelstra 3fd88d317f
Merge pull request #598 from RCasatta/verify_flags
Add verify_with_flags to Script and Transaction
2021-05-05 22:33:47 +00:00
Matt Corallo fc6f23fb9b Drop not-very-useful output dust threshold constants
It doesn't really make sense to have a constant for every common
script type's dust limit, instead we should just use the
`Script::dust_value()` function to have users calculate it.
2021-05-05 14:53:26 +00:00
Dr Maxim Orlovsky c0b7defc86
More non-API breaking error derives depending on upstream PRs 2021-05-04 03:58:56 +02:00
Dr Maxim Orlovsky 122450b102
Fixing hashes core dependency and fuzz feature 2021-05-04 03:47:34 +02:00
Riccardo Casatta c96f7ec71c
use markdown autolink syntax for urls with no text 2021-05-03 13:46:10 +02:00
Riccardo Casatta c58446f9c1
Deny broken doc intra-links and build docs in CI 2021-05-03 12:07:28 +02:00
Riccardo Casatta ef471ccca7
Fix documentation, in particular link to code elements 2021-05-03 11:43:11 +02:00
Matt Corallo 15981c945a Fix Script::dust_value()'s calculation for non-P2*PKH script_pubkeys
The dust calculations added were only valid for P2WPKH and P2PKH
outputs, and somehow this fact was missed in review, despite the
upstream Core code being linked to and looked at by two reviewers
and the author (me).

Someday I will grow eyeballs, but that day is not today.
2021-05-01 17:47:45 +00:00
Dr. Maxim Orlovsky 68096242d3
Merge pull request #594 from RCasatta/capped
Count bytes read in encoding
2021-05-01 16:28:57 +02:00
Dr Maxim Orlovsky 187eae8a13
Streamlining private key construction API in BIP32 2021-05-01 13:40:21 +02:00
Dr Maxim Orlovsky 18b6bd0d15
Adopting new ECDSA key constructors throughout the library 2021-05-01 13:34:31 +02:00
Dr Maxim Orlovsky ceacc7d85f
Constructors for compressed and uncompressed ECDSA keys 2021-05-01 13:34:04 +02:00
Riccardo Casatta 69117a1f63
Use Amount for verify_with_flags 2021-05-01 10:22:35 +02:00
Riccardo Casatta d1f4c0a5c8
Remove Copy for flags parameter 2021-05-01 10:19:54 +02:00
Riccardo Casatta 3aaa5d6846
Add verify with flags 2021-04-30 18:56:35 +02:00
Andrew Poelstra 4db4e604cb
Merge pull request #589 from LNP-BP/taproot/key-1
Non-API breaking introduction of Schnorr keys
2021-04-29 20:30:54 +00:00
Riccardo Casatta f692c4a938
Limit bytes read with Take 2021-04-28 09:33:37 +02:00
Andrew Poelstra 8231e25292
Merge pull request #586 from sanket1729/warn
fix warnings for sighashtype
2021-04-21 15:52:44 +00:00
Andrew Poelstra da477f1041
Merge pull request #558 from LNP-BP/fix/error-derives-1
Non-API breaking derives for error & transaction types
2021-04-21 14:24:27 +00:00
Riccardo Casatta 0a91496570
rename to_qr_string into to_qr_uri returning also the schema 2021-04-15 10:40:57 +02:00
Dr Maxim Orlovsky 230813b578
Making old ECDSA key type paths depeicated 2021-04-12 14:18:15 +02:00
Dr Maxim Orlovsky 664b09cdfd
Re-export Scep256k1 Schnorr keys under `util::schnorr`
This is second step in introducing Schnorr key support as per #588
2021-04-12 14:18:00 +02:00
Dr Maxim Orlovsky b17d7fc31c
Moving keys under `util::ecdsa`, re-exporting them at `util::key`
This is the first step in introducing Schnorr key support as per #588
2021-04-12 14:17:42 +02:00
Riccardo Casatta 3158cedea0
document alternate formatting 2021-04-11 18:14:28 +02:00
Martin Habovstiak bc406bfdd6 Use &mut dyn fmt::Write instead of bool
This replaces manually-written dynamic dispatch with `&mut dyn
fmt::Write` which is hopefully more readable.
2021-04-09 17:58:35 +02:00
Riccardo Casatta 85ae82febb
use the char trick to avoid allocation 2021-04-07 16:56:54 +02:00
Riccardo Casatta 104836a042
implements alternate formatting for address 2021-04-07 15:49:58 +02:00
sanket1729 3545580bd9 fix warnings for sighashtype 2021-04-06 11:52:14 -07:00
Dr Maxim Orlovsky 7fe3c4a605
Non-API breaking derives for error types 2021-04-06 14:44:50 +02:00
Collins Muriuki c4cfdbbd6a
doc: correct Transaction struct encode_signing_data_to doc comment 2021-04-03 23:52:09 +03:00
Sebastian 1326f7d2a8
Merge pull request #569 from stevenroose/static-asm
Make Script::fmt_asm a static method and add Script::str_asm
2021-03-31 23:45:03 +02:00
Riccardo Casatta cac3f460a2
improve to_qr_string doc 2021-03-23 09:42:58 +01:00
Riccardo Casatta d18554e756
Address to string conversion optimized for qr codes 2021-03-22 13:58:59 +01:00
Riccardo Casatta b9d5200448
Access Display and Formatter with fmt:: like in other places 2021-03-22 13:42:32 +01:00
Andrew Poelstra 20f1543f79
Merge pull request #552 from JeremyRubin/fix-amount-serde
Fix Optional Amount Serialization
2021-03-15 15:48:20 +00:00
Steven Roose 7df0d14f1a
Merge pull request #577 from RCasatta/proprietary_key
Include proprietary key in deserialized PSBT
2021-03-15 12:16:30 +00:00
Steven Roose 851a3a15c0
Make Script::fmt_asm a static method and add Script::str_asm
This makes it convenient to print/construct the script assembly on
byte slices withoout having to clone them to copy them to create a
Script struct.
2021-03-13 22:16:20 +00:00
Steven Roose 96fa4b7d9b
Implement AsRef<[u8]> for Script 2021-03-13 22:13:39 +00:00
Steven Roose 6a0f68df85
Merge pull request #557 from LNP-BP/psbt/display_from_str
PSBT base64 (de)serialization with Display & FromStr
2021-03-13 19:39:58 +00:00
carolcapps d52b88b525 Fix increment of Uint256 with carry 2021-03-13 15:19:43 +00:00
Riccardo Casatta 7e25c133d8
Include proprietary keys in deserialized fields 2021-03-13 15:41:07 +01:00
Riccardo Casatta fcd7200efe
Proprietary key test failing rtt 2021-03-13 15:19:21 +01:00
Andrew Poelstra bee5e8a090
Merge pull request #567 from LNP-BP/bip32/child-number-display
Improving bip32 ChildNumber display implementation
2021-03-12 21:01:56 +00:00
Jeremy Rubin a0c7f530ba Localize breaking changes of fixing the Amount serialization to only the
broken Option<SerdeAmount> serializer.
2021-02-28 09:13:52 -08:00
Dr Maxim Orlovsky 7b7b73f6d2
Improving PSBT FromStr error type 2021-02-22 12:46:22 +01:00
Dr Maxim Orlovsky 79f2729b20
Improving PSBT error tests 2021-02-22 12:46:22 +01:00
Dr Maxim Orlovsky 94102fa597
PSBT Base64 serialization test cases 2021-02-22 12:46:22 +01:00
Dr Maxim Orlovsky 072e1d1b86
PSBT Display & FromStr using Base64 serialization 2021-02-22 12:46:22 +01:00
Andrew Poelstra 2414c5b0a9
Merge pull request #573 from darosior/standard_sighash
SigHashType: add a method to error on non-standard hashtypes
2021-02-21 15:34:58 +00:00
Andrew Poelstra 81c56dec60
Merge pull request #551 from LNP-BP/feat/key-error-derives
More derives for key::Error
2021-02-21 14:14:54 +00:00
Sebastian 3ecab20c17
Merge pull request #414 from stevenroose/amount-debug
Change Amount Debug impl to BTC with 8 decimals
2021-02-21 15:14:40 +01:00
Antoine Poinsot e36f3a38e4
transaction: deprecate SigHashType::from_u32 in favor of from_u32_consensus
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-02-19 11:36:44 +01:00
Antoine Poinsot bf98d9fd60
transaction: add a method to err on non-standard types to SigHashType
Right now, any sighash type could be parsed without error, which matches
consensus rules. However most of them would be invalid by standardness,
so it's a bit footgun-y (even more so for pre-signed transactions
protocols for which standardness is critical).

This adds `from_u32_standard()`, which takes care to error if we are
passed an invalid-by-current-policy-rules SIGHASH type.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-02-19 11:12:02 +01:00
Antoine Poinsot 466f161e0b
transaction: document why we mask sighash types with 0x9f
Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
Co-Authored-by: sanket1729 <sanket1729@gmail.com>
2021-02-19 00:27:02 +01:00
Antoine Poinsot 7f73d5f7db
doc: correct SigHashType doc comment
Super nit, but a hashtype is not specific to a transaction but a
signature.

Signed-off-by: Antoine Poinsot <darosior@protonmail.com>
2021-02-18 19:48:39 +01:00
Jeffrey Czyz ade2bcee8e
Return BlockHash from BlockHeader::validate_pow
Validating a block's proof-of-work involves computing the block hash.
Returning it from BlockHeader::validate_pow avoids having callers
recompute the block hash if it is needed.
2021-02-17 17:40:17 -08:00
Dr Maxim Orlovsky 017cd71ca7
Improving bip32 ChildNumber display implementation 2021-02-11 23:06:24 +01:00
Sebastian 5bd61967b2
Merge pull request #566 from TheBlueMatt/2021-02-dust-value
Add Script:dust_value() to get minimum output value for a spk
2021-02-07 11:45:17 +01:00
Sebastian 80b47f1f5b
Merge pull request #565 from sgeisler/2021-02-rbf
Add function to check RBF-ness of transactions
2021-02-06 16:39:53 +01:00
Matt Corallo 6622de4041 Add Script:dust_value() to get minimum output value for a spk 2021-02-05 15:26:56 -05:00
Sebastian Geisler e98f14387d Add function to check RBF-ness of transactions 2021-02-04 22:15:26 +01:00
Nadav Ivgi a1e98a6796
Implement Ord for ParseLengthError 2021-01-22 00:27:28 +02:00
Nadav Ivgi 55657cbffb
Implement Error and Eq for ParseLengthError 2021-01-16 13:02:22 +02:00
Nadav Ivgi 0df86b4426
Switch to a single-variant error type, implement standard derives 2021-01-14 22:17:18 +02:00
Jeremy Rubin da21294ac5 Fix Optional Amount Serialization 2021-01-14 10:46:20 -08:00
Nadav Ivgi 4a7cf34eeb
Use efficient serialization for non-human-readable formats 2021-01-14 19:36:36 +02:00
Nadav Ivgi b70361370b
Make uint types (un)serializable 2021-01-14 19:36:35 +02:00
Nadav Ivgi 67ae602e2a
Implement Uint::from_be_slice()
Needed because Rust 1.29 does not easily allow converting from a slice
into an array.
2021-01-14 19:36:30 +02:00
Nadav Ivgi 3761b0d808 Implement Uint::to_be_bytes() 2021-01-14 19:28:02 +02:00
Dr Maxim Orlovsky 246713821d
More derives for key error 2021-01-14 16:03:53 +01:00
Steven Roose 61918dfe81
Change the signature of consensus_encode to return io::Error's
This is instead of encode::Errors because the encoders should
not be allowed to return errors that don't originate in the writer
they are writing into.

This is a part of the method definition that has been relied upon for a
while already.
2021-01-12 17:39:41 +00:00
Andrew Poelstra b48f374c2c
Merge pull request #542 from apoelstra/2021-01--keyread
PublicKey: add read_from method to be symmetric with write_into
2021-01-11 19:50:04 +00:00
Andrew Poelstra f1664db374
Merge pull request #538 from sanket1729/fix_warning
Fix service flags warning
2021-01-11 19:26:08 +00:00
Andrew Poelstra 4b58a254c5 encode: add some more generic impls (more tuples, references) 2021-01-08 23:21:55 +00:00
Andrew Poelstra ffe452ac0b script: add FromHex and FromStr implementations 2021-01-05 18:45:14 +01:00
Andrew Poelstra 92000bf51b PublicKey: add read_from method to be symmetric with write_into 2021-01-04 19:07:27 +00:00
Max Giraldo 21b2f929c5 refactor(blockdata/transaction): use nested paths
Instead of using a wildcard path for the `hash_types` module,
be explicit about what types we're using by using nested paths.

There are many benefits to this, including not polluting the namespace
and clearly demarcating the types' location.
2021-01-04 00:01:59 +01:00
Max Giraldo 06dc0041c2 docs: fix quotes in Transaction#ntxid description
Insert double quotes instead of a combination of single quote
and backtick.
2021-01-01 05:52:23 -08:00
Steven Roose a8f2faf96d serde_utils: Only use special serialization for human-readable
Non-human-readable serialization (binary) doesn't need hexification.
2020-12-30 16:32:52 +01:00
Steven Roose 5fd92d1c09 psbt: Serialize maps with byte values using hex 2020-12-30 16:32:52 +01:00
Steven Roose a05f8feec6 serde_util: Rename the btreemap module to btreemap_as_seq
So that we can later distinguish other modules over maps.
2020-12-30 16:32:52 +01:00
Steven Roose a9c13272a0 psbt: Fix serde for maps with non-string keys and binary values 2020-12-30 16:32:52 +01:00
Steven Roose e5f3bca2b4 Add serde_utils module to fix JSON serialization 2020-12-30 16:32:52 +01:00
Steven Roose cdedb0a9d5 psbt::raw: Use hex::format_hex to format the raw key bytes 2020-12-30 16:32:52 +01:00
Steven Roose 94b7371424 Replace serde_struct_impl with derive-based impls 2020-12-30 16:32:52 +01:00
Steven Roose d527a2c2cf Remove the impl_array_newtype_show macro
Instead, implement Debug in impl_bytes_newtype.
2020-12-30 16:32:52 +01:00
Andrew Poelstra 0ab8823984
Merge pull request #536 from 0xB10C/2020-12-add-blockheader-tests
Add BlockHeader tests
2020-12-28 16:56:56 +00:00