Commit Graph

1921 Commits

Author SHA1 Message Date
Tobin C. Harding 8f45723bc6 test.sh: Remove 1.29 pinning
We no longer need to test Rust 1.29, remove the pinning from the test
script.
2022-04-22 07:41:46 +10:00
Tobin C. Harding 15bae28b6b Remove CI check for Rust 1.29
In preparation for starting to merge patches that rely on an MSRV of
1.41 update the CI pipeline.
2022-04-22 07:41:39 +10:00
Martin Habovštiak 2c28d3b448
Fix handling of empty slice in Instructions
The code would've taken one element when an empty slice was requested.

Co-authored-by: Tobin C. Harding <me@tobin.cc>
2022-04-21 19:14:30 +02:00
Tobin C. Harding 7307363c2e Use qualified path instead of alias
It is more typical in this repo to use `module::Error` instead of a type
alias when importing.

Use `hex::Error` directly instead of `use hex::Error as HexError`.
2022-04-21 12:50:22 +10:00
Tobin C. Harding 80e0fb7673 Remove unnecessary 'as' statement
We can just use `self`, no idea why the `self as io` is there.
2022-04-21 12:50:22 +10:00
Tobin C. Harding 21e1b9dbbd Use secp256k1 qualified path instead of underscore
We can use the qualified path for create type aliases, this is arguably
easier to read and reduces the number of LOC.
2022-04-21 12:50:22 +10:00
Tobin C. Harding 033a12def7 Remove unused Write as _fmtWrite
We can bring the `Write` trait into scope, no need to underscore it.
2022-04-21 12:37:56 +10:00
sanket1729 30574020ef
Merge rust-bitcoin/rust-bitcoin#954: Add Script conversion method p2wpkh_script_code
d882b68a2c Add Script conversion method p2wpkh_script_code (Tobin Harding)

Pull request description:

  In order to sign a utxo that does a p2wpkh spend we need to create the
  script that can be used to create a sighash. In the libbitcoin docs this
  is referred to as the 'script code' [0] (also described in BIP143)

  The script is the same as a p2pkh script but the pubkey_hash is found in
  the scriptPubkey.

  Add a `Script` conversion method that checks if `self` is a v0 p2wpkh
  script and if so extracts the pubkey_hash and returns the required
  script.

  Includes a link to BIP143

  [0] https://github.com/libbitcoin/libbitcoin-system/wiki/P2WPKH-Transactions#spending-a-p2wpkh-output

ACKs for top commit:
  apoelstra:
    ACK d882b68a2c
  sanket1729:
    code review ACK d882b68a2c.

Tree-SHA512: 9a3244b5aac4e2911edf4d3bb634d3d2b98006b864280a2a04b45c55c263c2541bf25f01196f2a65bf9acbdd0cf28c69c3a020a7e6c8da6fddf7c7cfbb62836d
2022-04-20 14:35:59 -07:00
sanket1729 94f8c4b530
Merge rust-bitcoin/rust-bitcoin#951: Add PSBT alias
f92854a805 Add PSBT alias (Tobin Harding)

Pull request description:

  Programmers are inherently lazy and for good reason. I'm yet to see
  anyone write `PartiallySignedTransaction` in code that uses
  `rust-bitcoin`, its too obvious to add a type alias for PSBTs, let's
  just do it ourselves to save everyone else having to do so.

  Add public type alias `Psbt` for `PartiallySignedTransaction`.

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

Tree-SHA512: 1f56ac236d34a89bbb557ada147f05d8a8ce961dad3ad921f10f26c597b91ecc8e15070f8825774745e5333ba5282962830a3cc0c53b93f147be93ab566b1b9e
2022-04-20 14:32:34 -07:00
Andrew Poelstra 954b8a9b95
Merge rust-bitcoin/rust-bitcoin#939: fix: reject message (de)serialization
548725c5fb test: reject message (de)serialization (0xb10c)
fc572aba86 fix: use var_str in 'reject' msgs (0xb10c)

Pull request description:

  [BIP-61 defines `response-to-msg`][bip61] (`Reject::message` in rust-bitcoin; the message that triggered the reject) to be a `var_str`. However, by using the `CommandString` it was (de)serialized as 12 byte string. A test is added that de- and serializes two reject messages received from an older Bitcoin Core peer.

  Reject message sending has been removed from Bitcoin Core, I'm still receiving them from older peers from time to time.

  [bip61]: https://github.com/bitcoin/bips/blob/master/bip-0061.mediawiki#common-payload

  gh-ref: https://github.com/rust-bitcoin/rust-bitcoin/pull/323

ACKs for top commit:
  apoelstra:
    ACK 548725c5fb

Tree-SHA512: e5cbf215a471f113b4dd7f7fada162686fc6e8c7b1e2e9e641667208a36d3db610e57e8b549756ffe597656fee5444fe95466f1b88f45366595766f7c4640eea
2022-04-20 20:51:33 +00:00
Andrew Poelstra 1e58208039
Merge rust-bitcoin/rust-bitcoin#950: Fix TapTree derserialization
c97589f8de Fix TapTree derserialization (sanket1729)

Pull request description:

  Trees should only be serialized if both of the following conditions
  hold:
  1) Tree is complete binary tree(is_finalized)
  2) Tree does not have any hidden nodes

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

Tree-SHA512: 33d16f2d532cb24acba4ab847d493e550f7b279567678f3f2cd7e4161dea8b720a0e35be32b6c506e467c3526a29042aad8f4b5f45133b9a32028d4ee6a48f8e
2022-04-20 20:47:30 +00:00
Andrew Poelstra 221e153038
Merge rust-bitcoin/rust-bitcoin#961: Add temporary warning about edition change
bd36d846f2 Add temporary warning about edition change (Martin Habovstiak)

Pull request description:

  This warns contributors about possible rebases. Changing CONTRIBUTING
  should ensure that GitHub will display special warning. This will be
  removed after migration is done.

  See also https://github.com/rust-bitcoin/rust-bitcoin/discussions/945

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

Tree-SHA512: 8fd0c9a0803933c3996340ceb46f6d72ec1896936267c5c14ac1a7c48499a24babad1e096fa3a903fb4aedff6b915fd0ba92dd53f8cc3fd1fa0dbccb9bf7732b
2022-04-20 20:42:43 +00:00
Martin Habovstiak bd36d846f2 Add temporary warning about edition change
This warns contributors about possible rebases. Changing CONTRIBUTING
should ensure that GitHub will display special warning. This will be
removed after migration is done.
2022-04-20 20:15:49 +02:00
Martin Habovštiak e6ff754b73 Fix doc of take_slice_or_kill
Co-authored-by: Dr. Maxim Orlovsky <orlovsky@pandoracore.com>
2022-04-20 19:47:24 +02:00
Martin Habovstiak 0ec6d96a7b Cleanup after `Instructions` refactoring
* Changes `Option` to `Result` to avoid repeated `.ok_or(...)`
* Renames `max` to `min_push_len`
* Removes useless variable
2022-04-20 19:47:24 +02:00
Martin Habovstiak bc763259fe Move repeated code to functions in script
This creates a few primitive functions for handling iterators and uses
them to avoid repeated code. As a result not only is the code simpler
but also fixes a forgotten bound check. Thanks to a helper function
which always does bounds check correctly this can no longer be
forgotten.
2022-04-20 19:47:24 +02:00
Andrew Poelstra 8f899c73bf
Merge rust-bitcoin/rust-bitcoin#944: Release 0.28.0
38f09d2d93 minor changelog fixes (Andrew Poelstra)
785be0e27a release 0.28.0 (Andrew Poelstra)
c9385969f9 release: do CHANGELOG for 0.28.0 (Andrew Poelstra)

Pull request description:

  See discussion here https://github.com/rust-bitcoin/rust-bitcoin/discussions/941 about whether we want to cut the release now or do another slew of breaking changes between RCs.

ACKs for top commit:
  sanket1729:
    utACK 38f09d2d93. The diff from the previous ACKs is minor easy to review.

Tree-SHA512: e1ebdd637918337bb9d40f35fdcc3bf50fcab2bce095ed41026502af9446d8b27ddc1b87150205a79a4ac30baea96163219e772a757ab85649d503d97cdcb691
2022-04-20 17:45:26 +00:00
Martin Habovstiak 1f55edf718 Use iterator in `blockdata::script::Instructions`
This refactors `blockdata::script::Instructions` to use
`::core::slice::Iter<'a, u8>` instead of `&'a [u8]` to better express
the intention and to avoid some slicing mistakes. Similarly to a
previous change this uses a macro to deduplicate the common logic and
the new `read_uint_iter` internal function to automatically advance the
iterator.

Addresses:
https://github.com/rust-bitcoin/rust-bitcoin/pull/662#pullrequestreview-768320603
2022-04-20 19:45:03 +02:00
Andrew Poelstra 6b57a02b1f
Merge rust-bitcoin/rust-bitcoin#927: Trivial improvements for TapTree type
4cdff06b1e Add convenience method TapTree:to_builder (Dr Maxim Orlovsky)
a12e7c73b6 Implement From<TapTree> for TaprootBuilder (Dr Maxim Orlovsky)
410412ff01 Rename TapTree::from_builder (Dr Maxim Orlovsky)
219273788c Rename TapTree::into_builder (Dr Maxim Orlovsky)
f9d8d0d968 Make TapTree::node_info public (Dr Maxim Orlovsky)

Pull request description:

  These are trivial fixes from extracted from now closed #922

ACKs for top commit:
  Kixunil:
    ACK 4cdff06b1e
  sanket1729:
    ACK 4cdff06b1e
  apoelstra:
    ACK 4cdff06b1e

Tree-SHA512: 6132e8c214edc6f199a5550309daf4ed5035f24f545c793d6396c393bd2f55940dc418af62aed9aff25c0c90b74ee384ace986f7201db4018c6fd52710006126
2022-04-20 17:44:27 +00:00
sanket1729 9f79f8d1ce
Merge rust-bitcoin/rust-bitcoin#936: Make TaprooBuilder::finalize able to return keyspend only
7969b7a43e Make TaprooBuilder::finalize able to return keyspend only (Jeremy Rubin)

Pull request description:

ACKs for top commit:
  JeremyRubin:
    > ACK 7969b7a
  sanket1729:
    ACK 7969b7a43e
  apoelstra:
    ACK 7969b7a43e

Tree-SHA512: 26d0b730590f610a858061394faafaa74b13dd353f34ccf1c6166d0cbb62937010eed5661a887f7bea4f983ac9eab8cdca10a5fe7bd74f2dd5701a7782cbac64
2022-04-20 09:39:20 -07:00
Dr Maxim Orlovsky 4cdff06b1e
Add convenience method TapTree:to_builder 2022-04-20 10:31:28 +02:00
Dr Maxim Orlovsky a12e7c73b6
Implement From<TapTree> for TaprootBuilder 2022-04-20 10:30:45 +02:00
Dr Maxim Orlovsky 410412ff01
Rename TapTree::from_builder 2022-04-20 10:30:45 +02:00
Dr Maxim Orlovsky 219273788c
Rename TapTree::into_builder 2022-04-20 10:28:28 +02:00
Dr Maxim Orlovsky f9d8d0d968
Make TapTree::node_info public 2022-04-20 10:28:28 +02:00
Andrew Poelstra 38f09d2d93 minor changelog fixes 2022-04-20 01:36:56 +00:00
Andrew Poelstra a898797b07
Merge rust-bitcoin/rust-bitcoin#924: Improvements to taproot script iterator
3c59897598 Removed IntoIterator for TapTree implementation (Dr Maxim Orlovsky)
7a5482d23a Rename LeafInfo into ScriptLeaf (Dr Maxim Orlovsky)
2b8d96581a Rename TapTree::iter into TapTree::script_leaves (Dr Maxim Orlovsky)
6f871ba47d Add convenience LeafInfo::depth method (Dr Maxim Orlovsky)
3c502ffc2d Making all LeafInfo fields private (Dr Maxim Orlovsky)
d655ff3e93 Make TapTreeIterator use LeafInfo (Dr Maxim Orlovsky)
79345fcd02 LeafInfo field accessor methods (Dr Maxim Orlovsky)
5958466678 Make LeafInfo::leaf_hash public and change its name and return type (Dr Maxim Orlovsky)
c83893d497 Make taproot LeafInfo public (Dr Maxim Orlovsky)

Pull request description:

  This PR makes existing taproot script iterator to iterate `LeafScript` values instead of constructed `(u8, &Script)`. First, this is more idiomatic (iterator should not construct value but iterate through real internal representation); second information about merkle path of the scripts is required for me downstream to implement OP_RETURN taproot commitments.

  The PR also removes unnecessary iterator type, replacing it with a slice iterator type from the core rust library.

  I am asking to include this PR into RC fix scope, since it is required downstream.

ACKs for top commit:
  sanket1729:
    ACK 3c59897598. Reviewed the range-diff with the post that I previously ACKed

Tree-SHA512: 99e341443987204a8aba20869c750bd80a725f3d49d1b5731d554dff7377181b02a4517f8b390101afb2957135dbb255c6e360f90cadd6ee07b17eb14fd30af5
2022-04-20 01:33:37 +00:00
Dr Maxim Orlovsky 3c59897598
Removed IntoIterator for TapTree implementation
In the future, TapTree may iterate over different node types, and that's why it does not have `iter()` function; using instead `script_leafs`. Thus, we should not have IntoIterator implementation as well
2022-04-19 20:32:13 +02:00
Dr Maxim Orlovsky 7a5482d23a
Rename LeafInfo into ScriptLeaf 2022-04-19 20:32:13 +02:00
Dr Maxim Orlovsky 2b8d96581a
Rename TapTree::iter into TapTree::script_leaves 2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky 6f871ba47d
Add convenience LeafInfo::depth method
Without this method computation of the leaf depth requires cloning due
to the requirements of merkle_branch.into_inner()
2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky 3c502ffc2d
Making all LeafInfo fields private 2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky d655ff3e93
Make TapTreeIterator use LeafInfo
Previously used depth and script tuple missed information about the leaf version. 
All three comprises already existing type `LeafInfo` which was made public in 
previous commits.
2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky 79345fcd02
LeafInfo field accessor methods 2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky 5958466678
Make LeafInfo::leaf_hash public and change its name and return type 2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky c83893d497
Make taproot LeafInfo public
LeafInfo structure is a useful form of representing leaf script information (script, leaf version and merkle proof).
2022-04-19 20:31:49 +02:00
Tobin Harding d882b68a2c Add Script conversion method p2wpkh_script_code
In order to sign a utxo that does a p2wpkh spend we need to create the
script that can be used to create a sighash. In the libbitcoin docs this
is referred to as the 'script code' [0].

The script is the same as a p2pkh script but the pubkey_hash is found in
the scriptPubkey.

Add a `Script` conversion method that checks if `self` is a v0 p2wpkh
script and if so extracts the pubkey_hash and returns the required
script.

[0] https://github.com/libbitcoin/libbitcoin-system/wiki/P2WPKH-Transactions#spending-a-p2wpkh-output
2022-04-18 10:32:05 +10:00
Tobin Harding f92854a805 Add PSBT alias
Programmers are inherently lazy and for good reason. I'm yet to see
anyone write `PartiallySignedTransaction` in code that uses
`rust-bitcoin`, its too obvious to add a type alias for PSBTs, let's
just do it ourselves to save everyone else having to do so.

Add public type alias `Psbt` for `PartiallySignedTransaction`.
2022-04-18 07:21:19 +10:00
sanket1729 c97589f8de Fix TapTree derserialization
Trees should only be serialized if both of the following conditions
hold:
1) Tree is complete binary tree(is_finalized)
2) Tree does not have any hidden nodes
2022-04-14 10:04:46 -07:00
Andrew Poelstra 8ca18f75dd
Merge rust-bitcoin/rust-bitcoin#929: Fix TapTree hidden branches bug
c036b0db6f Unit test for failing TapTree on builder containing hidden nodes. (Dr Maxim Orlovsky)
77715311cf Prevent TapTree from hidden parts (Dr Maxim Orlovsky)
b0f3992db1 Rename TaprootBuilder::is_complete into is_finalized (Dr Maxim Orlovsky)
efa800fb1f Make TapTree::from_inner return a proper error type (Dr Maxim Orlovsky)
e24c6e23e3 TapTree serialization roundtrip unit test (Dr Maxim Orlovsky)
56adfa4527 TaprootBuilder::has_hidden_nodes method (Dr Maxim Orlovsky)
e69701e089 Rename taproot `*_hidden` API into `*_hidden_nodes` (Dr Maxim Orlovsky)
6add0dd9dc Track information about hidden leaves in taproot NodeInfo (Dr Maxim Orlovsky)

Pull request description:

  Closes #928

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

Tree-SHA512: 3a8193e6d6dd985da30a2094d1111471b5971f422525870003b77b6ac47cd4ad6e718d46a6d86bbb5e92e5253ac53804badf67edd98bbccbdc11e6383c675663
2022-04-14 17:03:14 +00:00
sanket1729 96edd94535
Merge rust-bitcoin/rust-bitcoin#938: Allow deprecated function call
29843c41ef Allow deprecated function call (Tobin Harding)

Pull request description:

  We have a deprecated function call because of the MSRV, tell clippy to ignore it.

ACKs for top commit:
  Kixunil:
    ACK 29843c41ef conditioned on adding this to MSRV bump TODO list.
  sanket1729:
    ACK 29843c41ef.

Tree-SHA512: 3e2bf95d05c3baff4f01c447717dde4e78d686cbc6f720591f6656ce1e5d8cf3a276a0c3dc0016dea357b61350091778d4500a59427ea9863eb5bb9344b822e4
2022-04-11 09:20:24 -07:00
Dr Maxim Orlovsky c036b0db6f
Unit test for failing TapTree on builder containing hidden nodes. 2022-04-05 22:43:52 +02:00
Andrew Poelstra 785be0e27a release 0.28.0 2022-04-05 20:39:13 +00:00
Andrew Poelstra c9385969f9 release: do CHANGELOG for 0.28.0 2022-04-05 20:38:23 +00:00
Dr Maxim Orlovsky 77715311cf
Prevent TapTree from hidden parts 2022-04-05 22:30:34 +02:00
Dr Maxim Orlovsky b0f3992db1
Rename TaprootBuilder::is_complete into is_finalized 2022-04-05 22:29:32 +02:00
Dr Maxim Orlovsky efa800fb1f
Make TapTree::from_inner return a proper error type 2022-04-05 22:29:20 +02:00
Dr Maxim Orlovsky e24c6e23e3
TapTree serialization roundtrip unit test 2022-04-05 22:18:23 +02:00
Dr Maxim Orlovsky 56adfa4527
TaprootBuilder::has_hidden_nodes method 2022-04-05 22:18:00 +02:00
Dr Maxim Orlovsky e69701e089
Rename taproot `*_hidden` API into `*_hidden_nodes` 2022-04-05 22:16:59 +02:00