Commit Graph

4221 Commits

Author SHA1 Message Date
Andrew Poelstra 154e91af8c
hashes: constify a bunch of constructors 2024-06-22 15:08:15 +00:00
Andrew Poelstra c155cbf8b2
hashes: use workaround to get constfns on tagged hashes with MSRV
As you can see from the - lines in the API diff, there is no reduction
in API surface (we just remove the T:Tag bound from the sha256t::Tag
type, which is not strictly necessary but maybe we would prefer to keep).
2024-06-22 15:08:15 +00:00
Andrew Poelstra 9ba29b384e
Merge rust-bitcoin/rust-bitcoin#2893: CI: Pin cargo-public-api version
7e3b2ebb74 CI: Pin cargo-public-api version (Tobin C. Harding)

Pull request description:

  So that updates don't break our CI setup used a specific version of `cargo-public-api`, this means we will have to update it manually periodically though.

  For now, since the latest release just broke us, use the release from a month ago.

ACKs for top commit:
  Kixunil:
    ACK 7e3b2ebb74
  apoelstra:
    ACK 7e3b2ebb74

Tree-SHA512: 9266f1c193395e25b1fc7945b2ed10fa7418c73f483ee3c6ad6c713b41a9eb9a01e1e23a58df5720e53811d470ac7465cffc235471236447f9c985dea5af21bb
2024-06-21 16:59:49 +00:00
Andrew Poelstra 817e54fb83
Merge rust-bitcoin/rust-bitcoin#2885: Remove usage of blockdata from paths
a42bcdc22e Remove usage of blockdata from paths (Tobin C. Harding)

Pull request description:

  the `blockdata` directory is code organisation thing, all the types/modules are re-exported from other places. In preparation for, and to make easier, the `primitives` crate smashing work - remove all explicit usage of `blockdata`.

  Note that the few instances remain as they seem required e.g.,

    `pub(in crate::blockdata::script)`

  Refactor only, no logic changes.

  Done as part of #2883

ACKs for top commit:
  apoelstra:
    ACK a42bcdc22e lgtm! I consider this "trivial" and will one-ACK merge it

Tree-SHA512: 310605e5203cf04aaeb91fe5512677b8f1438b183916686ba2cdc41ffdc18af7a0676206724e8a14c50ce6ed8faa9d48c69a2d5149eb1f56ae9c5f276fc5200f
2024-06-20 23:25:21 +00:00
Tobin C. Harding 7e3b2ebb74
CI: Pin cargo-public-api version
So that updates don't break our CI setup used a specific version of
`cargo-public-api`, this means we will have to update it manually
periodically though.

For now, since the latest release just broke us, use the release from a
month ago.
2024-06-21 08:47:12 +10:00
Andrew Poelstra 6908d45417
Merge rust-bitcoin/rust-bitcoin#2858: clarify the meaning of `Height` & `Time` based locktime.
16e4d22693 clarify the meaning of Height & Time based locktime. (Divyansh Gupta)

Pull request description:

  this pr aims to fix : #2697

ACKs for top commit:
  apoelstra:
    ACK 16e4d22693
  tcharding:
    ACK 16e4d22693

Tree-SHA512: 55757d7e593cb284aff7040cf3298931c7f3d8e9e36d7328bd748a39be743e5c4202c55505add0219b2766d35d1660affc5ed4a7b9480b3a3bfb89982fe3970a
2024-06-20 14:27:50 +00:00
Tobin C. Harding a42bcdc22e
Remove usage of blockdata from paths
the `blockdata` directory is code organisation thing, all the
types/modules are re-exported from other places. In preparation for, and
to make easier, the `primitives` crate smashing work - remove all
explicit usage of `blockdata`.

Note that the few instances remain as they seem required e.g.,

  `pub(in crate::blockdata::script)`

Refactor only, no logic changes.
2024-06-20 12:00:22 +10:00
Tobin C. Harding 9ddd7dacac
Merge rust-bitcoin/rust-bitcoin#2884: Automated daily update to rustc (to nightly-2024-06-19)
a0c139d40c Automated update to Github CI to rustc nightly-2024-06-19 (Update Nightly Rustc Bot)

Pull request description:

  Automated update to Github CI workflow `rust.yml` by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  tcharding:
    ACK a0c139d40c

Tree-SHA512: c2cfc3c9235c50d15ab248c2eb56378300a1684983b6c832de62287c4d1dcb87be45de9dbceaeaa68f176fdbbb7aa1547d91b72636b0db6943ce64563dbae2c3
2024-06-20 11:41:24 +10:00
Update Nightly Rustc Bot a0c139d40c Automated update to Github CI to rustc nightly-2024-06-19 2024-06-20 01:22:39 +00:00
Andrew Poelstra d063cc1d5c
Merge rust-bitcoin/rust-bitcoin#2864: Add trait bound to Merkle tree method; fix typing
90b6d6748b merkle_tree: remove some now-redundant code from block.rs (Andrew Poelstra)
48ad5e4789 api changes for "rewrite merkle root calculation" (Andrew Poelstra)
f7ce9bbee8 merkle_node: rewrite algorithm (Andrew Poelstra)
2bc97b22e2 api changes for new calculate_root method (Andrew Poelstra)
8d5cb014ce merkle_tree: introduce MerkleNode trait to better-type merkle tree calculation (Andrew Poelstra)
04353901ba api changes after moving the hashes (Andrew Poelstra)
5d8aa94069 Move merkle_tree hash types (Andrew Poelstra)

Pull request description:

  Alternate to https://github.com/rust-bitcoin/rust-bitcoin/pull/2853. Takes patch 1 from that PR.

ACKs for top commit:
  Kixunil:
    ACK 90b6d6748b
  tcharding:
    ACK 90b6d6748b

Tree-SHA512: 0e0a3f532e2efb4116f4ebc50719d3a2022c37405b0a22b15f79189b54b623e906e8fdd53997efc611eac5ceaee4c0ef12dab1d5cb595755c0c9e091c0a5904f
2024-06-19 14:52:25 +00:00
Divyansh Gupta 16e4d22693 clarify the meaning of Height & Time based locktime. 2024-06-19 20:14:04 +05:30
Andrew Poelstra 700085d8b2
Merge rust-bitcoin/rust-bitcoin#2863: Updated workflows/README.md to mention new Shellcheck job
e9de541428 Updated workflows/README.md to mention new shellcheck job (Jamil Lambert, PhD)

Pull request description:

  Added the new Shellcheck CI job to `./github/workflows/README.md` to fix: #2767

ACKs for top commit:
  storopoli:
    ACK e9de541428
  apoelstra:
    ACK e9de541428 pretty-much anything here is fine by me
  tcharding:
    ACK e9de541428

Tree-SHA512: 805d301a39ec17c159e78c275e28ac0046237e36860987cb70e2d872a29fb5ea65c891adc72ebf2d618ad5686f1548fca2cc139be23386580cd5a115e9fc6faa
2024-06-19 13:49:43 +00:00
Andrew Poelstra 90b6d6748b
merkle_tree: remove some now-redundant code from block.rs 2024-06-18 16:11:37 +00:00
Andrew Poelstra 48ad5e4789
api changes for "rewrite merkle root calculation" 2024-06-18 16:11:37 +00:00
Andrew Poelstra f7ce9bbee8
merkle_node: rewrite algorithm
Drop recursion, reduce memory usage to be logarithmic in size of tree
rather than linear, and put it all in one function rather than three.

Also make the method an trait method on MerkleNode which makes it a
easier on type inference, by writing e.g. TxMerkleNode::calculate_root.
2024-06-18 16:11:32 +00:00
Jamil Lambert, PhD e9de541428 Updated workflows/README.md to mention new shellcheck job
Added the new shellcheck CI job to the workflows README.md file
2024-06-18 11:19:58 +01:00
Andrew Poelstra 2bc97b22e2
api changes for new calculate_root method
These changes are nontrivial. They

* Drop the `From` impls from (w)txids to (w)TxMerkleRoots
* Introduce a new trait and bound calculate_root on it...
* ...in such a way that its return value cannot be inferred without
  further hints (though in practice this doesn't matter because usually
  the return value is immediately assigned to something with a known
  type such as a BlockHeader field)
2024-06-17 19:10:26 +00:00
Andrew Poelstra 8d5cb014ce
merkle_tree: introduce MerkleNode trait to better-type merkle tree calculation 2024-06-17 19:10:26 +00:00
Andrew Poelstra 04353901ba
api changes after moving the hashes
These are pretty noisy but it's just a move.
2024-06-17 19:10:26 +00:00
Andrew Poelstra 5d8aa94069
Move merkle_tree hash types
Currently we are defining the two merkle tree hash types in the `block`
module, a better home for them is the `merkle_tree` module.

This is an API breaking change because the types were public in the
`block` module, however the change should/could be unnoticeable to users
if they use the crate level re-export - which is maintained.
2024-06-17 19:10:23 +00:00
Andrew Poelstra 0ae6f49cea
Merge rust-bitcoin/rust-bitcoin#2872: Update PushBytes::read_scriptint(x) to x.read_scriptint()
e7f33a2a12 Update PushBytes::read_scriptint(x) to x.read_scriptint() (Shing Him Ng)

Pull request description:

  Fixes #2849

  There were a few other usages of PushBytes::read_scriptint(_) in the tests such as [this](406e3486ab/bitcoin/src/blockdata/script/tests.rs (L315)), but they couldn't be updated as cleanly as the changes in this PR. I wasn't sure if the intention of this issue was to fix those as well, but I can update this PR if needed

ACKs for top commit:
  tcharding:
    ACK e7f33a2a12
  Kixunil:
    ACK e7f33a2a12

Tree-SHA512: 4620f4972c40b0bf7333dbe302d1dabc5dbcb39749c734cc297a019d36983757f59659d76ae40b4a6121e51d0bde1e2b7883a0c77536be18927d1cfef53ba579
2024-06-17 16:24:01 +00:00
Andrew Poelstra de7da69298
Merge rust-bitcoin/rust-bitcoin#2794: Enforce script size limit when hashing scripts
6014788a74 api: Run just check-api (Tobin C. Harding)
e87a54f617 Enforce script size limit when hashing scripts (Tobin C. Harding)
4686d48ec4 Rename p2wsh script to witness_script (Tobin C. Harding)
9cdb514434 Remove odd script hash test (Tobin C. Harding)

Pull request description:

  There are two limits that the Bitcoin network enforces in regard to hashing scripts

  - For P2SH the redeem script must be less than 520 bytes (bip 16)
  - For P2WSH the witness script must be less than 10,000 bytes (bip 141)

  Currently we are only enforcing the p2sh limit when creating an address with `Address::p2sh`.

  There are various ways to create addresses from script hashes and if users manually hash a script then use the `ScriptHash` (or `WScritpHash`) our APIs assume the script that was hashed is valid. This means there is the potential for users to get burned by creating addresses that cannot be spent, something we would like to avoid.

  - Add fallible constructors to `ScriptHash` and `WScriptHash`
  - Add `TryFrom` impls as well to both types
  - Remove the `From` impls

  Close: #2794

ACKs for top commit:
  apoelstra:
    ACK 6014788a74

Tree-SHA512: 90c722ee6b63d02ebf39b77bf003f71ec90e745b32831a0d69aa4d6f363624bd6d2c86445f8807ed319d1845d639d2494756a8321207f917e57377d4557c436f
2024-06-17 15:47:47 +00:00
Tobin C. Harding 4c67993a28
Merge rust-bitcoin/rust-bitcoin#2873: Automated daily update to rustc (to nightly-2024-06-16)
418bb29ccd Automated update to Github CI to rustc nightly-2024-06-16 (Update Nightly Rustc Bot)

Pull request description:

  Automated update to Github CI workflow `rust.yml` by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  tcharding:
    ACK 418bb29ccd

Tree-SHA512: 1dd930ef735dca5cc4af8292623a0d221b475478d67586a4eabef608b399eab0fc589048f84f0263d06e22d021353a85014906f84a0badd13352d6e157063062
2024-06-17 13:08:50 +10:00
Update Nightly Rustc Bot 418bb29ccd Automated update to Github CI to rustc nightly-2024-06-16 2024-06-17 01:26:39 +00:00
Tobin C. Harding 6014788a74
api: Run just check-api 2024-06-17 10:32:06 +10:00
Tobin C. Harding e87a54f617
Enforce script size limit when hashing scripts
There are two limits that the Bitcoin network enforces in regard to
hashing scripts

- For P2SH the redeem script must be less than 520 bytes
- For P2WSH the witness script must be less than 10,000 bytes

Currently we are only enforcing the p2sh limit when creating an address
with `Address::p2sh`.

There are various ways to create addresses from script hashes and if
users manually hash a script then use the `ScriptHash` (or
`WScritpHash`) our APIs assume the script that was hashed is valid. This
means there is the potential for users to get burned by creating
addresses that cannot be spent, something we would like to avoid.

- Add fallible constructors to `ScriptHash` and `WScriptHash`
- Add `TryFrom` impls as well to both types
- Remove the `From` impls
2024-06-17 10:32:03 +10:00
Tobin C. Harding 4686d48ec4
Rename p2wsh script to witness_script
The script in a p2wsh is typically referred to as the witness script not
the redeem script - rename the local test variable to follow suit.

Refactor only, no logic changes.
2024-06-17 10:25:24 +10:00
Tobin C. Harding 9cdb514434
Remove odd script hash test
This test does an odd combination of function calls, its not obvious
what it is supposed to be testing. The `to_p2wsh.is_p2wsh` is already
tested above. The leading `to_p2sh` does not prove anything, one can put
currently pass any script to `to_p2wsh` so this tests nothing.

In preparation for patching the script hashing functionality first
remove this odd test.
2024-06-17 10:25:24 +10:00
Shing Him Ng e7f33a2a12 Update PushBytes::read_scriptint(x) to x.read_scriptint() 2024-06-16 17:11:33 -05:00
Andrew Poelstra 406e3486ab
Merge rust-bitcoin/rust-bitcoin#2871: Automated nightly rustfmt (2024-06-16)
4745b55cae 2024-06-16 automated rustfmt nightly (Fmt Bot)

Pull request description:

  Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  apoelstra:
    ACK 4745b55cae

Tree-SHA512: 1781948d9cb4946c92920007e0af4daf8c144743f25b13d8da4984dc2da35c7def0170b708a87c41cd4263b471f9d34fe6c3ac59daf66a0e3c1f1a3fcb3a3397
2024-06-16 14:18:59 +00:00
Fmt Bot 4745b55cae 2024-06-16 automated rustfmt nightly 2024-06-16 01:09:27 +00:00
Andrew Poelstra dc866a70bc
Merge rust-bitcoin/rust-bitcoin#2866: Run schemars test from extra_tests
1f58476cb4 Run schemars test from extra_tests (Tobin C. Harding)

Pull request description:

  We have a mechanism to run additional custom tests by way of the `extra_tests.sh` script in each crate.

  Remove the CI job and run the schemars test using `extra_tests.sh`. This patch changes the test coverage because currently the schemars test is only run with a stable toolchain but with this patch applied it runs with stable, MSRV, and nightly.

  Fix: #2787

ACKs for top commit:
  apoelstra:
    ACK 1f58476cb4

Tree-SHA512: 607132890ed08bf75fb544a0e10aeeda5f9c137eb04349f8af5ab28866408d4208cae4688c08645ffca95e7d9568562dbbbfa992382b5d2cb3efeba583d78b1f
2024-06-15 12:54:57 +00:00
Andrew Poelstra 45fe754ae3
Merge rust-bitcoin/rust-bitcoin#2865: Refactor test module in `merkle_tree/block.rs`
3f4eb07769 Add a comment to regression test (Jamil Lambert, PhD)
fc2876ba10 Move use statements to top of module (Jamil Lambert, PhD)
778a44dd64 Refactor merkle block test (Jamil Lambert, PhD)
c4c1252a9e Change encode path (Jamil Lambert, PhD)

Pull request description:

  Refactored the `extract_matches_from_merkleblock()` test function following https://github.com/rust-bitcoin/rust-bitcoin/pull/2859#issuecomment-2161710169.

  Moved use statements to the top of the test module and changed it to use one level of path instead of importing the function names.  e.g. `encode::serialize()` instead of `serialize()`.

  Added the missing comment to the `regression_2606()` test.  I was not sure where the hex value came from that was used to test that the deserialization fails.  The comment was generated by copilot and may need to be edited, it does fit with the error given by deserialize: `OversizedVectorAllocation { requested: 12811880876963004416, max: 4000000 }`.

ACKs for top commit:
  tcharding:
    ACK 3f4eb07769
  apoelstra:
    ACK 3f4eb07769 the `prelude::*` is fine since it was already there since #298, but FYI I would not have accepted it today

Tree-SHA512: 203a30eee51ea91051cb10d5d7dd55b560d9d4d785120143c9fb29ea26ec77696124adc9c5bcb8cd736a7d293b897e665958bec5f66626a5c1c95c98b6029e0d
2024-06-15 03:12:23 +00:00
Andrew Poelstra 4defdb08fa
Merge rust-bitcoin/rust-bitcoin#2868: Pass keys by value
9f01871c11 api: Run just check-api (Tobin C. Harding)
7929b51640 Pass keys by value (Tobin C. Harding)

Pull request description:

  We should pass `Copy` types by value not by reference. Pass the key types by value.

  This is patch 1 from #2404

ACKs for top commit:
  apoelstra:
    ACK 9f01871c11 this will annoy some people but I think we should do it

Tree-SHA512: 18afab537edf4ade4dc1c1e5992e50060b8935531f1e3cbe1d3b94b2fcb87aafa39947f342e0e762835bda3b4091dd35b3b74ea79f4dbb3b21660ffd21d1f82e
2024-06-14 23:56:46 +00:00
Andrew Poelstra 31f7565559
Merge rust-bitcoin/rust-bitcoin#2867: Link to std::error::Error
c81e330e48 Link to std::error::Error (Tobin C. Harding)

Pull request description:

  In #2521 I removed the link from `std::error::Error` with the claim that it broke no-std builds. However there are a ton of other places where we link to `std::` types.

  I have no idea where the breakage was, I assume it existed and I was sane at the time, CI on this patch will tell us.

  Close: #2571

ACKs for top commit:
  apoelstra:
    ACK c81e330e48

Tree-SHA512: 137fe62eb88359a6439ce5cddaf615704cc72a3df256e66d3730ce429c7b86973d62749c658796e95f9119443da0e286db78a41641b560a5667b076660c9b2b5
2024-06-14 17:16:31 +00:00
Andrew Poelstra 72ce271b6b
Merge rust-bitcoin/rust-bitcoin#2852: Add inherent functions to hashes
18b2788a5a api: Run just check-api (Tobin C. Harding)
6b7d02e5ae Add inherent functions to hashes (Tobin C. Harding)

Pull request description:

  Currently we have a trait `Hash` that is required for `Hmac`, `Hkdf`, and other use cases. However, it is unegonomic for users who just want to do a simple hash to have to import the trait.

  Add inherent functions to all hash types including those created with the new wrapper type macros.

  This patch introduces some duplicate code but we are trying to make progress in the hashes API re-write. We can come back and de-dublicate later.

  Includes making `to_byte_array`,`from_byte_array`, `as_byte_array`, and `all_zeros` const where easily possible.

ACKs for top commit:
  apoelstra:
    ACK 18b2788a5a

Tree-SHA512: 6b7a8d8a8501e981416d767040e5bd9fa8d1134be2ca133b5c53aa55f65c8456dccb63b642e30d0d571ca838c6f9eaeff6527d92a9b4212819a49ce619c4e093
2024-06-14 16:30:52 +00:00
Jamil Lambert, PhD 3f4eb07769 Add a comment to regression test
The comment at the top was generated by AI
2024-06-14 10:33:39 +01:00
Jamil Lambert, PhD fc2876ba10 Move use statements to top of module
Moved all of the use statements to the top of the tests module.

Change to have one level of path instead of importing the function name.
2024-06-14 10:33:39 +01:00
Jamil Lambert, PhD 778a44dd64 Refactor merkle block test
Refactored the unit test as suggested in
https://github.com/rust-bitcoin/rust-bitcoin/pull/2859#issuecomment-2161710169
2024-06-14 10:33:39 +01:00
Jamil Lambert, PhD c4c1252a9e Change encode path
Change the path for `consensus::encode` to use one level of path instead of importing the function name
2024-06-14 10:33:20 +01:00
Tobin C. Harding 9f01871c11
api: Run just check-api 2024-06-14 14:19:07 +10:00
Tobin C. Harding 7929b51640
Pass keys by value
We should pass `Copy` types by value not by reference. Pass the key
types by value.
2024-06-14 14:16:28 +10:00
Tobin C. Harding c81e330e48
Link to std::error::Error
In #2521 I removed the link from `std::error::Error` with the claim that
it broke no-std builds. However there are a ton of other places where we
link to `std::` types.

I have no idea where the breakage was, I assume it existed and I was
sane at the time, CI on this patch will tell us.

Close: #2571
2024-06-14 14:00:58 +10:00
Tobin C. Harding 1f58476cb4
Run schemars test from extra_tests
We have a mechanism to run additional custom tests by way of the
`extra_tests.sh` script in each crate.

Remove the CI job and run the schemars test using `extra_tests.sh`. This
patch changes the test coverage because currently the schemars test is
only run with a stable toolchain but with this patch applied it runs
with stable, MSRV, and nightly.

Fix: #2787
2024-06-14 13:44:18 +10:00
Tobin C. Harding efdcadf2fd
Merge rust-bitcoin/rust-bitcoin#2862: Automated daily update to rustc (to nightly-2024-06-12)
024d1fa53b Automated update to Github CI to rustc nightly-2024-06-12 (Update Nightly Rustc Bot)

Pull request description:

  Automated update to Github CI workflow `rust.yml` by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  tcharding:
    ACK 024d1fa53b

Tree-SHA512: e075c3aca81ab3cddbac470f17d48acf39483e664341894203f042a01cec12534efd013c070c6985c864687ef8575f2df31d2eb8af33dea952bb6676f667640a
2024-06-14 13:32:25 +10:00
Tobin C. Harding 18b2788a5a
api: Run just check-api 2024-06-14 10:51:01 +10:00
Tobin C. Harding 6b7d02e5ae
Add inherent functions to hashes
Currently we have a trait `Hash` that is required for `Hmac`, `Hkdf`,
and other use cases. However, it is unegonomic for users who just want
to do a simple hash to have to import the trait.

Add inherent functions to all hash types including those created with
the new wrapper type macros.

This patch introduces some duplicate code but we are trying to make
progress in the hashes API re-write. We can come back and de-dublicate
later.

Includes making `to_byte_array`,`from_byte_array`, `as_byte_array`, and
`all_zeros` const where easily possible.
2024-06-14 10:17:00 +10:00
Andrew Poelstra 59d06f7073
Merge rust-bitcoin/rust-bitcoin#2859: Moved private doctest to unit test
8d256b4e79 Moved doctest to unit test (Jamil Lambert, PhD)

Pull request description:

  Moved the doctest from the private module to a unit test to fix: #2840

ACKs for top commit:
  apoelstra:
    ACK 8d256b4e79
  tcharding:
    ACK 8d256b4e79

Tree-SHA512: 233961288579381cb5c51235331c78c9980046f0317a2062cb108a2e604adde322e2dd834e724d1fe05f54f92721fe6c9f5344dcf930f99aa3756a698ddf9732
2024-06-13 13:20:32 +00:00
Update Nightly Rustc Bot 024d1fa53b Automated update to Github CI to rustc nightly-2024-06-12 2024-06-13 01:23:39 +00:00
Jamil Lambert, PhD 8d256b4e79 Moved doctest to unit test
Moved the doctest from the private module to a unit test, since it does not appear in doc.rs.
2024-06-12 16:00:28 +01:00