Commit Graph

36 Commits

Author SHA1 Message Date
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
Dr Maxim Orlovsky ef8a3a839e Introduce FutureLeafVersion 2022-01-08 23:40:21 +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 67b8db05a8 Converting LeafVersion into an enum 2022-01-07 20:28:36 +01:00
sanket1729 2178c7367c Update to secp256k1 0.21.2 2022-01-07 04:45:40 +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
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 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 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 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
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
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
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
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
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
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
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
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 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
Riccardo Casatta 8f27579c7f
fix documentation referencing macro var 2021-06-25 09:56:40 +02:00
Steven Roose a56712befc
Create tagged taproot hashes 2020-11-30 20:13:11 +00:00