Commit Graph

5776 Commits

Author SHA1 Message Date
Tobin C. Harding fd4586eaae
Invert dependency between io and hashes
Currently in order to release `hashes v1.0` we need to 1.0 `io` as well.
For multiple reasons, many out of our control, the `io` crate may not
stabalise any time soon.

Instead we can invert the dependency between the two crates.

This is an ingenious idea, props to Kixunil for coming up with it.

Notes

- `io` does not currently re-export the `hashes` crate.
- This work highlights that we cannot call `hash_reader` on a siphash.
- The `Hmac::hash_reader` uses the default key which may not be obvious.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
2025-02-11 09:17:21 +11:00
Tobin C. Harding 9833ca32ce
primitives: Do not depend on bitcoin_io
Currently the `primitives` crate does not use the `io` dependency. I
don't know if this is just a mistake of if it used to and the manifest
is just stale.
2025-02-10 10:50:59 +11:00
merge-script 9c3a52be88
Merge rust-bitcoin/rust-bitcoin#4025: Automated daily update to rustc (to nightly-2025-02-07)
c9a86dcf58 Automated update to Github CI to rustc nightly-2025-02-07 (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 c9a86dcf58

Tree-SHA512: 550874dff82af919d5cc3c7c7805761ee2b5ed8437ce4db2e8c3dfa4729a23943c17a1807e4935c856a3e4c4be2b2a09364ba775cd43627f71d5bd2fb22ad6a6
2025-02-10 10:13:17 +11:00
merge-script 329aaf452b
Merge rust-bitcoin/rust-bitcoin#4010: Add a tagged hash engine
6002ccdc56 Add a tagged sha256t hash engine (Tobin C. Harding)
3e8e2e46bf Use Self::Engine in GeneralHash impl (Tobin C. Harding)
a0211906fe sha256t: Remove standalone from_engine function (Tobin C. Harding)
5ce8781162 Remove the Tag::engine method (Tobin C. Harding)
ba6425947f hashes: Use associated cost for pre-tagging (Tobin C. Harding)
613fddc82b Delete deprecated sha256t_hash_newtype macro (Tobin C. Harding)

Pull request description:

  Add a new hash engine to the `sha256t` module and put the tag on it.

  Note the issue suggests adding the tag to `sha256::HashEngine` but this PR adds a new type to `sha256t` and adds the tag on it.

  Resolve: #1552

ACKs for top commit:
  apoelstra:
    ACK 6002ccdc567b26c69f6b55173f5d11b95b4d6966; successfully ran local tests
  Kixunil:
    ACK 6002ccdc56

Tree-SHA512: 8a8945bdb89841b87af2eb94073b4d01993338f34a7a3e919bccf4e8edea0fe9d5d2818b6484700b2e72143f315633338692a436149935c5156b77757b025f5e
2025-02-09 20:04:56 +00:00
merge-script 0d76669418
Merge rust-bitcoin/rust-bitcoin#3903: refactor: use convenience method to calculate fee
ee0486a43f refactor: use convenience method to calculate fee (yancy)

Pull request description:

  The FeeRate module provides a convenience method to calculate the fee.

ACKs for top commit:
  tcharding:
    ACK ee0486a43f
  apoelstra:
    ACK ee0486a43f33a6068f13fb1a82244ecb60b94740; successfully ran local tests

Tree-SHA512: 076750b8733d2988ba482096a1903f1cae01b6055743fba8176a61d15159273fffc79007a01b212c9ad2c3835cdbbc17157da48ea7dd58113a5398eaad6e7c37
2025-02-09 17:53:12 +00:00
merge-script 170fad53c0
Merge rust-bitcoin/rust-bitcoin#4014: Return `Self::Output` from `ops::Rem`
94f9bac6aa Return Self::Output from ops::Rem (Tobin C. Harding)

Pull request description:

  The ops traits return `Self::Output` not `Self`. The current code builds because `Self` and `Self::Output` are both the same type.

  Use `Self::Output` as the return value of `ops::Rem`.

ACKs for top commit:
  Kixunil:
    ACK 94f9bac6aa
  apoelstra:
    ACK 94f9bac6aadec17bbda66f7ad23a970fccdd840e; successfully ran local tests

Tree-SHA512: da609b7963e80f9a6550bfdb80c0ab465ab16caa3f95c92b1b3272378cf23656feb9ac5de4ed457ef9e2109b19e2721ee3b1314f0e602851378194d5f6b28850
2025-02-09 16:25:30 +00:00
merge-script a1bd90eb52
Merge rust-bitcoin/rust-bitcoin#4024: primitives: Add tests to Sequence
963dba2bdf Test sequence formatting (Jamil Lambert, PhD)
6c3d7f6443 Test Sequence properties (Jamil Lambert, PhD)

Pull request description:

  Add tests to kill the mutants found in Sequence.

ACKs for top commit:
  tcharding:
    ACK 963dba2bdf
  apoelstra:
    ACK 963dba2bdf102b2015393014d06cc56b8473520a; successfully ran local tests

Tree-SHA512: f03a02cd49df2b29232bf4f9baf663a7b51b0de504de88ae4d62de96d4e672800ac2387d0675aa48280dcbdfc0738f80484842f98b58324a09462c01956566cf
2025-02-08 15:10:46 +00:00
merge-script b70dd554be
Merge rust-bitcoin/rust-bitcoin#4018: Add missing re-exports to primitives crate root
e5c74c38a2 Add missing re-exports to primitives crate root (Jamil Lambert, PhD)

Pull request description:

  There are re-exports in the bitcoin root from primitives that were not re-exported in the primitives crate root.

  Add the missing re-exports to primitives crate root.

  First mentioned here https://github.com/rust-bitcoin/rust-bitcoin/pull/4012#discussion_r1943895283

ACKs for top commit:
  tcharding:
    ACK e5c74c38a2
  apoelstra:
    ACK e5c74c38a20e153f0919b43755d58dff8f2c8da2; successfully ran local tests

Tree-SHA512: c3355981ccd3a5db32423f6f44a6e169062c8cbce1f5e358ae2791e24801459a9db22065b83e54950dd3fd745ac4af4dcb1e1bd4625b5f25a9dd4f8fd4e6b860
2025-02-08 04:30:32 +00:00
Tobin C. Harding 6002ccdc56
Add a tagged sha256t hash engine
We would like it if two different pre-tagged engines were considered
different types so it is not possible to mix them up.

Add a new `sha256t::HashEngine<T>` where `T` is a tag the same as on
`sha256t::Hash<T>`.
2025-02-08 13:27:30 +11:00
Tobin C. Harding 3e8e2e46bf
Use Self::Engine in GeneralHash impl
Match the trait method signature. Internal change only.
2025-02-08 13:27:30 +11:00
Tobin C. Harding a0211906fe
sha256t: Remove standalone from_engine function
This function is meant to be used in conjunction with the
`general_hash_type` macro but the `sha256t` module does not use that
macro.

Inline the function. Internal change only.
2025-02-08 13:27:30 +11:00
Tobin C. Harding 5ce8781162
Remove the Tag::engine method
Now we have an associated const we can do away with the `engine` trait
method all together. Users can call `Hash<FooTag>::engine` instead. This
is better because its an API more similar to the other hash types and
therefor easier to discover and remember.
2025-02-08 13:27:30 +11:00
Tobin C. Harding ba6425947f
hashes: Use associated cost for pre-tagging
Instead of requiring users of the `Tag` trait to implement the `engine`
method we can have an associated const and provide an `engine` method
with a default implementation.

Use an associated const for the pre-tagged hash engine. Fro now keep the
`engine` trait method but have a default impl that returns the const. We
will remove it as a separate patch to assist review.
2025-02-08 13:27:30 +11:00
Tobin C. Harding 613fddc82b
Delete deprecated sha256t_hash_newtype macro
This macro is a maintenance burden. We would like to put a tag on the
hash engine but doing so would require breaking this macro anyway so
lets just delete it.
2025-02-08 13:27:30 +11:00
Update Nightly Rustc Bot c9a86dcf58 Automated update to Github CI to rustc nightly-2025-02-07 2025-02-08 01:37:36 +00:00
merge-script 8464b1452f
Merge rust-bitcoin/rust-bitcoin#4015: hashes: Derive `Debug` for all hash engines
6263b9c6af hashes: Derive Debug for all hash engines (Tobin C. Harding)

Pull request description:

  Public types typically should implement `Debug`.

  Derive `Debug` for all the hash engines.

ACKs for top commit:
  Kixunil:
    ACK 6263b9c6af
  apoelstra:
    ACK 6263b9c6afc377822d0cefb1303e98ea51f1a5b6; successfully ran local tests

Tree-SHA512: c50b7b23229c6b4bc05754142bdcc1669393dd11a7eec829f9f950d75209468693e4977582e356e2b2db6a445d22071c6e60cb6a778ab8fff705e71e680b3c8c
2025-02-07 23:57:31 +00:00
merge-script 9aaf6ae358
Merge rust-bitcoin/rust-bitcoin#4020: primitives: Add tests to CompactTarget
b2d0737acc Add tests to CompactTarget (Jamil Lambert, PhD)

Pull request description:

  Add tests to pow.rs to kill the mutants found in CompactTarget.

ACKs for top commit:
  tcharding:
    ACK b2d0737acc
  apoelstra:
    ACK b2d0737accb998071e0f19cda6f988956b6c097a; successfully ran local tests

Tree-SHA512: 8245b2342fabb7142cc0369cc53f4213f8f685dd0ed9d357214b2f692237b3484236462a96315d2c9409625fcf59484fc505674859542311893c23e50da6ffdf
2025-02-07 21:44:22 +00:00
merge-script 9aef27a52b
Merge rust-bitcoin/rust-bitcoin#4019: primitives: Add test to opcodes
486d55f042 Add test to opcodes (Jamil Lambert, PhD)

Pull request description:

  Cargo mutant found a mutant in opcodes.

  Add a test to kill it.

ACKs for top commit:
  tcharding:
    ACK 486d55f042
  apoelstra:
    ACK 486d55f0421a05c0aaa8f883bc15cacd212dcc19; successfully ran local tests

Tree-SHA512: 8bd28d56d6e5d79a3531f0a3391ac26021f8351a77e632dcceb8a57b2f1cce05aa02ec5e37d5b5771c3a42a2a7010a241d8f232521678604cc6ecb4bdb3327a5
2025-02-07 20:11:16 +00:00
Jamil Lambert, PhD 963dba2bdf
Test sequence formatting
Add a test to kill the mutants in Sequence formatting.
2025-02-07 17:50:45 +00:00
Jamil Lambert, PhD 6c3d7f6443
Test Sequence properties
Cargo mutants found multiple mutants in the functions that return true
or false for various Sequence properties.

Add a test to kill the mutants.
2025-02-07 17:48:17 +00:00
Jamil Lambert, PhD e5c74c38a2
Add missing re-exports to primitives crate root
There are re-exports in the bitcoin root from primitives that were not
re-exported in the primitives crate root.

Add the missing re-exports to primitives crate root.
2025-02-07 08:01:46 +00:00
merge-script 21d1defced
Merge rust-bitcoin/rust-bitcoin#4011: Update example imports to use `relative::*`
a4fe67645a Use relative::* or absolute::* in locktime example (ndungudedan)

Pull request description:

  Aims to resolve #3976

  Apart from the examples in the `relative.rs` file, I see others in the **examples** folder. If this patch is good, I can continue with them.

  I will happily appreciate a review.

ACKs for top commit:
  tcharding:
    ACK a4fe67645a
  jamillambert:
    ACK a4fe67645a

Tree-SHA512: a9551c77bf91fdc212126d387adb110a7dc71635620f4efa25dc1e4306a9953968a4ad0e1528c990d5083bd9833702e62ae819db474a49f1284327fd042fb1c2
2025-02-07 06:09:16 +00:00
merge-script 94c3fa4ca7
Merge rust-bitcoin/rust-bitcoin#4012: primitives: Add tests to `block.rs`
ff3b3ddb67 Add a test for Header size (Jamil Lambert, PhD)
0df15d5cfd Add version test (Jamil Lambert, PhD)
927251ef8e Expand version signalling test (Jamil Lambert, PhD)

Pull request description:

  Running `cargo mutants` on `primitives/src/block.rs` found multiple mutants.

  Add tests to kill the mutants and replace one verbosely written out sum with the result.

ACKs for top commit:
  apoelstra:
    ACK ff3b3ddb675446fd21f3f7488749fc7fb26c7ef2; successfully ran local tests
  tcharding:
    ACK ff3b3ddb67

Tree-SHA512: a30cabf699b5c1c5f1b3507385f1041795316c8a5739454b219719aafe24d1f10e20b69b3cb2330290b7df71d5fedfd0d353b63404f47bef9476e0be2b115295
2025-02-07 05:15:53 +00:00
Tobin C. Harding 6263b9c6af
hashes: Derive Debug for all hash engines
Public types typically should implement `Debug`.

Derive `Debug` for all the hash engines
2025-02-07 11:16:59 +11:00
Tobin C. Harding 94f9bac6aa
Return Self::Output from ops::Rem
The ops traits return `Self::Output` not `Self`. The current code builds
because `Self` and `Self::Output` are both the same type.

Use `Self::Output` as the return value of `ops::Rem`.
2025-02-07 11:16:50 +11:00
merge-script 786e835312
Merge rust-bitcoin/rust-bitcoin#4013: CI: Remove the API job
2eccb3897a CI: Remove the API job (Tobin C. Harding)

Pull request description:

  It has been argued that the API files provide value for verifying that code changes produce API changes in the expected way. This helps devs and reviewers.

  It has also been argued that the CI job adds friction and forces devs to configure their environment unnecessarily.

  Both viewpoints have some merit.

  Lets remove the API files for now, and when we start doing 1.0-alpha releases and can start to expect minimal API breaking changes (and therefore minimal need to use the tooling)

ACKs for top commit:
  Kixunil:
    ACK 2eccb3897a

Tree-SHA512: 566edf6cdce6669841d8239bdd46506b6df7884a0a1fd481b4aec0db7134b1109fd7b6216a54e6e92444a4f17e3a740628c0016b028b5966bb460daf84de4b8c
2025-02-06 23:38:34 +00:00
yancy ee0486a43f refactor: use convenience method to calculate fee
The FeeRate module provides a convenience method to calculate the fee.
2025-02-06 16:19:32 -06:00
ndungudedan a4fe67645a
Use relative::* or absolute::* in locktime example
Users should be encouraged to explicitly use relative::* or

absolute::* instead of just LockTime, Time, or Height so that

it is clear when looking at the code if it is a relative or

absolute locktime.
2025-02-06 22:28:13 +03:00
Jamil Lambert, PhD b2d0737acc
Add tests to CompactTarget
Add tests to pow.rs to kill the mutants found in CompactTarget.
2025-02-06 17:06:41 +00:00
Jamil Lambert, PhD 486d55f042
Add test to opcodes
Cargo mutant found a mutant in opcodes.

Add a test to kill it.
2025-02-06 16:30:52 +00:00
merge-script 16cf1f7f2a
Merge rust-bitcoin/rust-bitcoin#3989: Do `hashes` file re-org
85e0330d7f Run the formatter (Tobin C. Harding)
7be0db730a hashes: Move bench and test code into files (Tobin C. Harding)
665fa9de99 hashes: Pull crypto out into submodule (Tobin C. Harding)
1bfd1e071a hashes: Make module subdirectories (Tobin C. Harding)

Pull request description:

  This is an attempt at point 3 in https://github.com/rust-bitcoin/rust-bitcoin/pull/3961#issuecomment-2619946074

  However instead of using `api.rs` and `implementation.rs` it uses `crypto.rs` for the cryptography stuff and leaves the rest in `mod.rs`.

  This whole PR is internal changes only. Almost entirely code moves, review is easy if you have your `diff` configured nicely.

ACKs for top commit:
  Kixunil:
    ACK 85e0330d7f
  apoelstra:
    ACK 85e0330d7f057c9fe447bff5fdb6023150ead319; successfully ran local tests; look great! thanks!

Tree-SHA512: e52e6410e86fc93ec34a72be8c64f02148f46958f8f5c1850075b1a7f41886c220f09144ccd05a98a551c356a5d25524c8884fc8578a205b27f385ec0725f13b
2025-02-06 16:08:17 +00:00
Jamil Lambert, PhD ff3b3ddb67
Add a test for Header size
Calculate the header size and test it is equal to `Header::SIZE`
2025-02-06 14:28:22 +00:00
Jamil Lambert, PhD 0df15d5cfd
Add version test
Mutant found in Version.

Add a round trip test for version::from_consensus to kill the mutant.
2025-02-06 14:17:28 +00:00
Jamil Lambert, PhD 927251ef8e
Expand version signalling test
Add a check for max soft fork signalling bit 28
2025-02-06 14:11:07 +00:00
Tobin C. Harding 2eccb3897a
CI: Remove the API job
It has been argued that the API files provide value for verifying that
code changes produce API changes in the expected way. This helps devs
and reviewers.

It has also been argued that the CI job adds friction and forces devs
to configure their environment unnecessarily.

Both viewpoints have some merit.

Lets remove the API files for now, and when we start doing 1.0-alpha
releases and can start to expect minimal API breaking changes (and
therefore minimal need to use the tooling).
2025-02-06 08:44:15 +11:00
merge-script a380d4b9de
Merge rust-bitcoin/rust-bitcoin#4006: Rename fee_wu and remove fee_vb
a7526b6a70 Remove `fee_vb` (yancy)
73b14d03b9 Add `to_fee` in place of `fee_wu` (yancy)

Pull request description:

  Rename fee_wu and remove fee_vb

  closes https://github.com/rust-bitcoin/rust-bitcoin/issues/3908

ACKs for top commit:
  apoelstra:
    ACK a7526b6a70642e04f0a8ad8a89aa368031fdb6cd; successfully ran local tests
  Kixunil:
    ACK a7526b6a70

Tree-SHA512: fd865525e56caddc49158fd94fb125d92fd09654d5c72609a6f8e34370e79a9be4213dbd7e69b0d8498d92fca8a970142262f56b63cebd76c200aca75b6e0ca6
2025-02-05 20:15:08 +00:00
Tobin C. Harding 85e0330d7f
Run the formatter
Run `just fmt`, no other manual changes.
2025-02-06 07:12:17 +11:00
Tobin C. Harding 7be0db730a
hashes: Move bench and test code into files
We are trying to make the `hashes` crate easier to read and also
possibly parseable by machines to see what is different where.

Move the test and bench code into separate files. Make special effort to
keep formatting as is so the diff is easier to review. We will run the
formatter in the next patch.

Internal change only.
2025-02-06 07:10:02 +11:00
Tobin C. Harding 665fa9de99
hashes: Pull crypto out into submodule
There are five modules in `hashes` that implement cryptography (i.e.
have a `process_block` function). For each of them create a new
submodule called `crypto` and move the code there.

Code organisational refactor only, no logic changes.
2025-02-06 07:10:02 +11:00
Tobin C. Harding 1bfd1e071a
hashes: Make module subdirectories
In preparation for removing a bunch of macros move all the modules to
`<mod>/mod.rs`.

Do so by running the following shell:

```bash
for mod in hash160 ripemd160 sha1 sha256 sha256d sha256t \
sha384 sha512 sha512_256 siphash24 hkdf hmac; do
mkdir $mod
mv "$mod.rs" "$mod/mod.rs"
done
```

Internal change only.
2025-02-06 07:10:02 +11:00
merge-script 5fef0dd5d4
Merge rust-bitcoin/rust-bitcoin#3985: Minor: Fix policy module link
5cb1a1d565 Fix policy module link (Peter Todd)

Pull request description:

ACKs for top commit:
  tcharding:
    ACK 5cb1a1d565
  apoelstra:
    ACK 5cb1a1d5650caaaa6df00aba6d1a57340097991c; successfully ran local tests

Tree-SHA512: 6c9b20819376920ff251092bc999e7bc323c09fd7f5bc633a8e47f43d6b3ba0e875ca398e36448c02358dc2c9735b5da5aab18d497a99a2ceb6a40d167920194
2025-02-05 19:29:23 +00:00
yancy a7526b6a70 Remove `fee_vb`
This is redundant given Weight::from_vb is provided.  After converting
to a weight_unit, use to_fee().
2025-02-05 09:05:51 -06:00
yancy 73b14d03b9 Add `to_fee` in place of `fee_wu`
Use the more idiomatic to_fee instead of `fee_wu`.  Since the method
takes a strongly typed argument, remove `wu` from the method name
to improve clarity.
2025-02-04 18:34:52 -06:00
merge-script 422ea03ef7
Merge rust-bitcoin/rust-bitcoin#4005: Manual update to rustc (to nightly-2025-01-31)
ebab2d9aa7 Update cargo-public-api version (Jamil Lambert, PhD)
3b350d4f54 Update to rustc (to nightly-2025-01-31) (Jamil Lambert, PhD)
55ab2f34a7 Remove manual implementation of ok (Jamil Lambert, PhD)
30132c56bb Fix rustdoc indentation (Jamil Lambert, PhD)

Pull request description:

  Fix the errors found when updating `rustc` to `nightly-2025-01-31`.  Then update the version in `nightly-version`.

  Update `cargo-public-api` to `v0.43.0` since `v0.42.0` is only compatible with `nightly-2024-10-18 — nightly-2025-01-24`

ACKs for top commit:
  apoelstra:
    ACK ebab2d9aa7310eb62a6c42bf4dfb266cff441965; successfully ran local tests
  tcharding:
    ACK ebab2d9aa7

Tree-SHA512: 3c037b8bbfb0fa69be1b6fa1438c7c38636683dc7ffe9bce018afdd6b9033edaa18b5f3e5fa489ebb720221b8780ff628e573b5408270bf6c45edf9ca01a97e7
2025-02-04 23:30:30 +00:00
Peter Todd 5cb1a1d565
Fix policy module link 2025-02-04 21:31:44 +00:00
Jamil Lambert, PhD ebab2d9aa7
Update cargo-public-api version
Version 0.42.0 is not compatible with the new version of rust nightly.

Update to v0.43.0
2025-02-04 17:36:26 +00:00
Jamil Lambert, PhD 3b350d4f54
Update to rustc (to nightly-2025-01-31) 2025-02-04 16:54:05 +00:00
Jamil Lambert, PhD 55ab2f34a7
Remove manual implementation of ok
New rustc nightly gives error: manual implementation of `ok`.

Remove it.
2025-02-04 16:47:43 +00:00
Jamil Lambert, PhD 30132c56bb
Fix rustdoc indentation
New nightly lint picked up an incorrect indentation.

Remove extra space.
2025-02-04 16:47:43 +00:00
merge-script 511ac2c47c
Merge rust-bitcoin/rust-bitcoin#4003: Add engine function to `siphash24::Hash`
51cb36881f api: Run just check-api (Tobin C. Harding)
1bcfc80fe7 Add engine function to siphash24::Hash (Tobin C. Harding)

Pull request description:

  The other hashes that require initial state (keys etc) both have an `engine` function on the hash type because they cannot use the `GeneralHash::engine` function.

  Add an `engine` function to the `siphash24::Hash` type.

ACKs for top commit:
  apoelstra:
    ACK 51cb36881f5291daa4136a714c286cf01f968cf0; successfully ran local tests

Tree-SHA512: 5cafa5b717235e94167b98a7ff675c3bde5071e736cdc4515ae534b517a5a96eead2bebd25b5dc0123e5e8615bb191c6990ae1ea7dea59b1b58d72547514b5b5
2025-02-03 23:25:45 +00:00