Commit Graph

144 Commits

Author SHA1 Message Date
Fmt Bot c060285851 2025-06-22 automated rustfmt nightly 2025-06-22 01:46:07 +00:00
merge-script 5743a81128
Merge rust-bitcoin/rust-bitcoin#4589: Move `bitcoin::p2p` into `p2p`
d9cf7270eb Move `bitcoin/p2p` into `p2p` (rustaceanrob)

Pull request description:

  Could use a rebase on #4568

  Somehow lost the branch of my original draft so some of the review context is removed, but all comments were addressed in separate PRs.

  First commit moves everything required to implement encoding within `p2p`, so we have a reference for functions to add to future moves to `internals`. Second commit does the relocation and third commit removes the `bitcoin/p2p` module.

ACKs for top commit:
  apoelstra:
    ACK d9cf7270eb457fd660fa505701895ab4756e394d; successfully ran local tests
  tcharding:
    ACK d9cf7270eb

Tree-SHA512: 31bf960788f45bb60b04dd73793a06828a5540e1e6118376776494bad9330dc8ebcb57749bc84b70a00e4d1d2a5686506e089269833ed99c4f9fa0c3e3b2e5b7
2025-06-19 17:00:08 +00:00
rustaceanrob d9cf7270eb
Move `bitcoin/p2p` into `p2p`
Moves all of the content from `bitcoin/p2p` into `p2p`.

`TryFrom<Network>` must be implemented for `Network -> Magic` now that
`Network` is a foreign, non-exhaustive type. Ser/de test is updated
accordingly, as well as the `Magic::from_network` constructor, which I
have opted to return an `Option<Self>`. The `TryFrom` implementation
uses a new `UnknownNetworkError(Network)` that mirrors the `Magic ->
Network` error.

The example handshake does not generate a random nonce for the version
message, as there is no `rand` dependency in this crate and the program
only makes a single, user-defined connection.

It appears we can do better than copying and pasting the consensus
encoding macros and functions from `bitcoin` without doing weird
cross-crate macros that require some special knowledge of the crate to
know when they will compile.
2025-06-18 14:11:35 +01:00
Tobin C. Harding 0ff8d82193
Make FeeRate from sat constructors infallible
We now have constructors that take an arbitrary size fee
rate (`Amount`). The `from_sat_per_foo` constructors can be made
infallible by taking a `u32` instead of `u64`. This makes the API more
ergonomic but limits the fee rate to just under 42 BTC which is plenty.

Note we just delete the `from_sat_per_vb_u32` function because it is
unreleased, in the past we had `from_sat_per_vb_unchecked` so we could
put that back in if we wanted to be a bit more kind to downstream. Can
be done later, we likely want to go over the public API before release
and add a few things back in that we forgot to deprecate or could not
for some reason during dev.

Fuzz with a new function that consumes a `u32`.
2025-06-16 09:56:42 +10:00
Tobin C. Harding b27d8e5819
Change the internal representation of FeeRate
To get more precision use sats per million virtual bytes.

To make review easier keep most calls in tests using
`FeeRate::from_sats_per_kwu` and just unwrap. These can likely be
cleaned up later on if we want to.

For `serde` just change the module to `_floor` and leave it at that. The
serde stuff likely needs re-visiting before release anyways.
2025-05-31 07:52:31 +01:00
Luis Schwab 6335c623f6
fix(p2p): remove `AddrV2` <> `SocketAddr` conversions 2025-05-27 10:32:23 -03:00
Fmt Bot c73131c8f0 2025-05-25 automated rustfmt nightly 2025-05-25 01:42:57 +00:00
Erick Cestari 2c236ae24f
fuzz: Add p2p address round-trip fuzzing test 2025-05-21 16:49:27 -03:00
Fmt Bot a74e08a53d 2025-03-16 automated rustfmt nightly 2025-03-16 01:25:25 +00:00
Jamil Lambert, PhD ddb6dd520e
Move module out of fuzz_target directory
The new module `fuzz_utils` in the `fuzz_targets/` directory causes
`verify-execution` to fail.

Move the module to the `src/` directory. Create a `lib.rs` file.
2025-03-07 15:47:39 +00:00
Erick Cestari 2a6cbda304 ci: Update GitHub workflows to use ubuntu-24.04 instead of ubuntu-latest 2025-03-05 16:24:41 -03:00
merge-script 16860fefd2
Merge rust-bitcoin/rust-bitcoin#4185: fuzz: cover more stuff for Script
08e0d4f0e5 fuzz: cover minimal_non_dust_custom  for Script (Bruno Garcia)
66fee1ef87 fuzz: add consume_u64 (Bruno Garcia)
35e7027a08 fuzz: move consume_random_bytes to a util file (Bruno Garcia)
eb8ecd5e3c fuzz: cover minimal_non_dust for Script (Bruno Garcia)
cab8a6134f fuzz: cover count_sigops{_legacy} for Script (Bruno Garcia)

Pull request description:

  This PR adds fuzz coverage for `count_sigops`, `count_sigops_legacy`, `minimal_non_dust` and `minimal_non_dust_custom`. In order to not duplicate `consume_random_bytes`, it moves it to a util file and adds a `consume_u64` function to be used in the `deserialize_script` target to fuzz `minimal_non_dust_custom`.

ACKs for top commit:
  apoelstra:
    ACK 08e0d4f0e53d97edd655ec1103d60a2b4715fb91; successfully ran local tests

Tree-SHA512: d9b0b94af3e2c1b06b790e0b7d13095493d372f8c22babb9139f25f45ff580020a04c00bdba023bf4f89e2db1e13ffdff8e43f073516e7699c2ccc0233b0eb4b
2025-03-05 14:46:45 +00:00
Bruno Garcia 08e0d4f0e5 fuzz: cover minimal_non_dust_custom for Script 2025-03-04 11:13:55 -03:00
Bruno Garcia 66fee1ef87 fuzz: add consume_u64 2025-03-04 11:13:51 -03:00
Jamil Lambert, PhD 2dad19a20f
Bump GitHub Actions Artifacts to v4
v3 is deprecated and causes an automatic fail of fuzz workflow.

Bump the version of `actions/upload-artifact` and
`actions/download-artifact` to v4.
2025-03-04 11:37:58 +00:00
Bruno Garcia 35e7027a08 fuzz: move consume_random_bytes to a util file 2025-03-03 13:47:52 -03:00
Bruno Garcia eb8ecd5e3c fuzz: cover minimal_non_dust for Script 2025-03-03 12:24:15 -03:00
Bruno Garcia cab8a6134f fuzz: cover count_sigops{_legacy} for Script 2025-03-03 12:06:55 -03:00
Bruno Garcia 2688abad19 fuzz: add coverage for Display for Script 2025-02-26 09:04:59 -03:00
Jamil Lambert, PhD 3520e832ac
Make capitalization of SegWit uniform in rustdocs 2024-12-17 14:28:28 +00:00
Tobin C. Harding 7819e50055
Move Block to primitives
On the way re-design the API by doing:

- Introduce `Checked` and `Unchecked` tags
- Rename the `txdata` field to `transactions`
- Make the `Block` fields private
- Add getters for `header` and `transactions` fields
- Move the various `compute_` methods to be free standing functions
- Make the `check_` functions private
- Introduce extension traits
2024-11-15 07:16:21 +11:00
Tobin C. Harding 98383a0fbe
Introduce Transaction extension traits
WARNING: This is not like all the other extension traits.

Because of the use of generics on various `Transaction` methods it is
not easily possible to use the `define_extension_trait` macro.

Manually create the extension traits (public and private) for the
`Transaction` type. This is quite ugly but c'est la vie

(Includes two in the `transaction` module and one in the
`consensus_validation` module.)
2024-10-30 12:28:52 +11:00
Tobin C. Harding 3b7ba4f977
Remove the SliceIndex implementation from hash types
If folk really want to index into a hash they can us `as_byte_array`
then index that.

Includes a bump to the version number of `hashes` to `v0.15.0` - this
is because otherwise `secp` won't build since we are breaking an API
that is used in the current release of secp.

Fix: #3115
2024-10-02 10:18:45 +10:00
Chris Hyunhum Cho 33edaf935d fix: check overflow for push_int with push_int_unchecked 2024-09-25 03:15:03 +00:00
Jamil Lambert, PhD 9fce57b738
Change T::from_str(s) to s.parse::<T>() in tests
`s.parse` is more idiomatic and produces more helpful error messages.

This has been changed repo wide in tests.
2024-08-28 16:13:03 +01:00
Martin Habovstiak 0857697665 Replace impl blocks with extension traits
In preparation to move script types to `primitives` we replace impl
block with extension traits by replacing the temporary modules with
`define_extension_trait`.
2024-08-13 13:14:00 +02:00
Martin Habovstiak c72069e921 Bump MSRV to 1.63
The version 1.63 satisfies our requirements for MSRV and provides
significant benefits so this commit bumps it. This commit also starts
using some advantages of the new MSRV, namely namespaced features, weak
dependencies and the ability to use trait bounds in `const` context.

This however does not yet migrade the `rand-std` feature because that
requires a release of `secp256k1` with the same kind of change - bumping
MSRV to 1.63 and removing `rand-std` in favor of weak dependency.
2024-07-27 07:24:32 +02:00
merge-script e7af76f1cd
Merge rust-bitcoin/rust-bitcoin#2936: Bump honggfuzz version
43360bdd74 Bump honggfuzz version (yancy)

Pull request description:

  Bump hongfuzz version

ACKs for top commit:
  apoelstra:
    ACK 43360bdd74
  tcharding:
    ACK 43360bdd74

Tree-SHA512: fe0e9e5a54fa2d4205a3d9974c19b86e57bfd5e525cd7f379c3c1b7ed15d37b03e6808a7cbf5c15b35bf69df820bd302fb81b5a8525fd3a09102aef13f3abf0d
2024-07-22 21:57:14 +00:00
yancy 4576f4ba69 Remove fuzz rust version
Fuzz is not compatible with the workspace MSRV.
2024-07-01 14:17:14 -05:00
yancy 43360bdd74 Bump honggfuzz version 2024-06-28 12:04:58 -05:00
Tobin C. Harding 31a2324bfd
Fix fuzz script
Currently the `fuzz.sh` script fails with "unbound variable" if called
without any arguments, this has gone undetected since we added `set
-euox pipefail` because in CI we always call it with an argument.

Use chatGPT to fix the bug.

Fix: #2924
2024-06-27 08:49:10 +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
Shing Him Ng e7f33a2a12 Update PushBytes::read_scriptint(x) to x.read_scriptint() 2024-06-16 17:11:33 -05: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
Fmt Bot 8e9be3beed 2024-06-09 automated rustfmt nightly 2024-06-09 01:09:23 +00:00
Bruno Garcia 55cbae9c2f fuzz: add more coverage for `deserialize_psbt` 2024-06-06 13:49:32 -03:00
Andrew Poelstra 741589c5ad
Merge rust-bitcoin/rust-bitcoin#2828: fuzz: add more coverage for `deserialize_block`
ee30eaa81b fuzz: add more coverage for `deserialize_block` (Bruno Garcia)

Pull request description:

  This PR adds more coverage for the `deserialize_block` target. First, it serializes the block and compares with the data provided and then call some block functions to ensure they run without any issue.

ACKs for top commit:
  apoelstra:
    ACK ee30eaa81b Thanks!

Tree-SHA512: db6c7befa7b429267e9b28fb7910d2b9e8d462e22c791b544b1aa528c7ba4f8e1cd32e1276c67d3da1f97ce484e7ed19ec20b10d2030f2977fd8f855cf510ffe
2024-06-03 13:57:09 +00:00
Bruno Garcia ee30eaa81b fuzz: add more coverage for `deserialize_block` 2024-06-02 15:44:35 -03:00
Divyansh Gupta a336ec0dda refactor(script): move `read_scriptint` to `PushBytes` & create `read_int` function
* Moved read_scriptint method to Push_Bytes struct
 * Created Instruction::read_int method
fix #1547
2024-05-28 15:36:17 +05:30
Andrew Poelstra 830a6e1b0c
fuzz: delete CBOR test
We were using an outdated CBOR crate for MSRV reasons. But this old
crate is causing suprious test failures. So delete it. (Sadly, updating
the crate doesn't fix the issue, replacing it with ciborium breaks our
MSRV tests because it needs a more recent `half` dependency, and
replacing it with `minicbor` doesn't work because minicbor is not based
on serde. So we don't really have any options.)

In general, I am suspicious of this decode-then-reencode test. CBOR has
some ambiguity in integer encoding. Empirically it has seemed to
work for a long time, but this seems more like an indictment of our test
than a positive result.

Also, round-trip testing serde encoding of a byte vector is probably not
a great use of our fuzz resources. I don't believe we have ever had a
problem with this.

Fixes #2801
2024-05-24 14:32:19 +00:00
Andrew Poelstra 91eb50b2db
fuzz: add lint to generate-files.sh
In #2785 I modified fuzz/Cargo.toml without updating the Cargo.toml
generating script. Oops. Fix that.
2024-05-24 14:30:49 +00:00
Andrew Poelstra 5ad7c245e3
cargo: whitelist all cfgs used in this repo 2024-05-22 13:32:24 +00:00
Jose Storopoli 021bea89bb
ci: shellcheck checks 2024-05-11 18:08:53 +00:00
Tobin C. Harding c750be2352
fuzz: Update generate-files.sh
Recently we modified the fuzz job manually and forgot about the
`generate-files.sh` file.

Update the script to match the current CI job, running it now produces
the same file `cron-daily-fuzz.sh`.
2024-05-02 16:02:28 +10:00
Jose Storopoli b355740da4
chore: format and standardize all markdowns files
according to the github flavor
(https://github.github.com/gfm/)
2024-04-27 06:29:23 -03:00
Andrew Poelstra 133531fab7
Merge rust-bitcoin/rust-bitcoin#2635: Add set -euo pipefail
3fa3d37c21 Add set -euo pipefail (Tobin C. Harding)

Pull request description:

  Add `euo pipefail` to all non-trial shell scripts, note if `x` is already set we maintain it.

ACKs for top commit:
  sanket1729:
    utACK 3fa3d37c21
  apoelstra:
    ACK 3fa3d37c21

Tree-SHA512: 24c0da96bea44ea4f550847c8f73bbe1d9ccd1bfee1714ef8a0c23075e3a6d438b6006e351cce0df7a1cb0b9d1b50096270f65a62d0def05c84c9573ffefacba
2024-03-27 18:14:42 +00:00
Tobin C. Harding 3fa3d37c21
Add set -euo pipefail
Add `euo pipefail` to all non-trial shell scripts, note if `x` is
already set we maintain it.

Note we have a pipe in `run_task.sh` that relies on grep not finding
anything i.e., failing, so we cannot use pipefail there. Disable it and
re-enable it after the pipe.
2024-03-27 11:02:27 +11:00
Tobin C. Harding 6ab0110964
Run fuzzer daily
Waiting for the fuzzer slows down the dev feedback loop because it makes
CI slow. We still want fuzz coverage but not in a way that slows down
devs.

Instead of running the fuzzer on every PR just run it once a nightly.

As we do for other daily jobs, rename the yaml file to make explicit
what it does.

Open questions:

- This should run for 30 minutes but I can't work out why the current
  set up only runs for a shorter time than that?
- Is this less fuzzing i.e., is 30 minutes once a day better or worse that 1
  minute 30 times?
2024-03-27 04:35:23 +11:00
Tobin C. Harding d38cb8af9e
fuzz: Use path in manifest instead of version
Using `path` instead of `version` makes the `fuzz` crate easier to
maintain because we don't have to update the version number to do
releases.
2024-03-21 16:20:03 +11:00
Andrew Poelstra e386cbfadf
ci: delete *test.sh files
These are not run in CI since #2353 and are likely to go out of date. If
we want a script that users can run locally then we should create a new
script that wraps our current CI.
2024-02-28 20:45:56 +00:00