Commit Graph

4542 Commits

Author SHA1 Message Date
Andrew Poelstra 4652ce20ed
API changes for "delete `all_zeros`"
This is the kind of diff that is nicer to read than the source code.
2024-06-22 15:09:52 +00:00
Andrew Poelstra 8869f35a69
hashes: drop the `all_zeros` method on arbitrary hashes
Manually implement it for Wtxid, Txid and BlockHash, where the all-zero
"hash" has a consensus meaning. But in general we should not be
implementing this method unless we have a good reason to do so. It can
be emulated or implemeted in terms of from_byte_array.

The use of Wtxid::all_zeros is obscure and specific enough that I am
tempted to drop it. But for txid and blockhash, the 0 hash appears in
actual blockdata and we should keep it.

All other uses of all_zeros were either in test code or in places where
the specific hash was not important and [u8; 32] was a more appropriate
type.
2024-06-22 15:09:28 +00:00
Andrew Poelstra 9f8797f486
API changes for constification of hash constructors
This is a noisy diff and probably can just be ignored vs reading the
source diff in the previous commit.
2024-06-22 15:08:15 +00:00
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
Tobin C. Harding aebf216619
Use 100 column width for rustdoc
We use 100 column width for rustdoc in this project, while not a super
hard rule the docs on `read_scriptint` are long, using the 100 column
width reduces the line count a reasonable amount.

No text changes, only whitespace.
2024-06-22 08:21:48 +10:00
Tobin C. Harding c71ae9ac16
Move PushBytes::read_scriptint
The `push_bytes` module has a `private` module that exists solely to
protect the invariant on the `PushBytes` inner byte slice. There is a
`PushBytes` impl block outside the private module for functions that can
not and do not violate the length invariant.

Recently we move the `read_scriptint` method to be on the `PushBytes`
but we put it inside the `private` module, since the method only reads
off of the slice it cannot invalidate the invariant and does not need
to be inside the `private` module.

Move the `read_scriptint` method outside of the `private` module to keep
that module as small as possible, helping with its stated aim of being
the only place that requires auditing.
2024-06-22 08:21:47 +10:00
Jose Storopoli 9ffa01f5ed
Contributing: add instructions on wildcards in import statements 2024-06-21 19:27:35 +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
Divyansh Gupta 39df0a9fbe update api 2024-06-20 10:19:22 +05:30
Divyansh Gupta 3a5f2932a4 create constants for ChildNumber enum
These constants are ->
   * `ONE_NORMAL` & `ZERO_NORMAL`
   * `ZERO_HARDENED` & `ONE_HARDENED`
2024-06-20 10:19:11 +05:30
Tobin C. Harding 865ba3fc39
Move serde string macros to internals
The macros are internal things and can live in `internals`. This will
help with future crate smashing.
2024-06-20 14:25:43 +10:00
Tobin C. Harding 4a2b13fcde
internals: Feature gate whole serde module
Instead of feature gating the individual code blocks just feature gate
the whole `serde` module.
2024-06-20 14:20:50 +10:00
Tobin C. Harding 72655607b6
api: Run just check-api 2024-06-20 13:05:24 +10:00
Tobin C. Harding e8250cd96a
Remove InvalidInternalKey variant from TaprootBuilderError
This variant is unused, remove it.

Done as part of #2883.
2024-06-20 13:03:59 +10: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
Tobin C. Harding 433fd6bf7e
api: Run just check-api 2024-06-20 09:23:45 +10:00
Tobin C. Harding 8fd583b069
Pass hash types by value
We should pass `Copy` types by value not by reference. Pass the hash
types by value.
2024-06-20 09:09:58 +10: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
Jamil Lambert, PhD 9ea8c58ad6 Fix case sensitivity of denomination
The comment in `FromStr` says that any combination of upper and lower case is considered valid, but the code only allowed a set list of variations. It also had a non exhaustive list of `CONFUSING_FORMS`.

The comment and code has been changed to only consider all upper case or all lower case denominations as valid or where BTC/btc is prefixed with a lower case c, m or u.  `CONFUSING_FORMS` has been changed to contain all combinations of an upper case prefix on an otherwise valid denomination.
2024-06-18 10:46:17 +01:00
Jamil Lambert, PhD 67569ca632 Remove denominations < 1 satoshi
Removed all millisatoshi, nano and pico bitcoin denominations and tests from `Amount`
2024-06-18 10:26:20 +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