Commit Graph

82 Commits

Author SHA1 Message Date
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
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
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
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
Tobin C. Harding 69e56a64ed
Add bitcoin-units crate
Add a new crate `bitcoin-units`, move the `amount` module over to it and
re-export all types from `bitcoin::amount` so this as not a breaking
change.
2023-12-11 08:52:31 +11:00
Tobin C. Harding c34e3cc7cc
Re-write size/weight API
Recently we introduced a bug in the weight/size code, while
investigating I found that our `Transaction`/`Block` weight/size APIs
were in a total mess because:

- The docs were stale
- The concept of weight (weight units) and size (bytes) were mixed up

I audited all the API functions, read some bips (141, 144) and re-wrote
the API with the following goals:

- Use terminology from the bips
- Use abstractions that mirror the bips where possible
2023-09-25 08:25:49 +10:00
Tobin C. Harding d4e8f49fc3
Move p2p::constants::Network to crate root
The `Network` type is not a p2p construct, it is more general, used
throughout the codebase to define _which_ Bitcoin network we are
operating on.
2023-08-01 16:46:59 +10:00
Tobin C. Harding 1bac1fd518
Rename the network module to p2p
The `network` module deals with data types and logic related to
internetworking bitcoind nodes, this is commonly referred to as the p2p
layer.

Rename the `network` module to `p2p` and fix all the paths.
2023-08-01 16:36:12 +10:00
Tobin C. Harding 92749d29e4
Rename PartiallySignedTransaction to Psbt
Last release we added a type alias for `Psbt`, now lets just rename the
type and be done with it.

Includes re-export at the crate root because `bitcoin::Psbt` is clear
and obvious.
2023-07-15 08:32:29 +10:00
Andrew Poelstra 2860aae1a5
fuzz: don't fuzz hashes against RustCrypto
We should probably restore this in the future, but we need to rethink
how we fuzz hashes -- right now when cfg(fuzzing) is set, we break all
the hash functions in a way that won't match any other library.

We should probably make this breakage opt-in but this will require
buy-in from rust-lightning and maybe others.
2023-04-27 00:24:53 +00:00
Andrew Poelstra 6467728202
fuzz: disable tests unless 'cfg(fuzzing)' is passed; update README for reproducing failures 2023-04-27 00:24:53 +00:00
Andrew Poelstra 6e2ee5be66
fuzz: run 'cargo fmt' on all the fuzz targets 2023-04-27 00:24:53 +00:00
Andrew Poelstra 933ecb19e1
fuzz: fix warnings, clippy lints, 1.48.0 failures 2023-04-27 00:24:53 +00:00
Andrew Poelstra fd88e48696
fuzz: remove AFL support
AFAICT we literally never used this; it was available only on the
bitcoin targets and not the honggfuzz ones; AFL has a broken dep
tree (or at least, requires some more MSRV pins that I did not care
to investigate).

Just remove it entirely.
2023-04-27 00:24:52 +00:00
Andrew Poelstra 0be75f7edc
move hashes/fuzz into main fuzz/ directory 2023-04-27 00:24:52 +00:00
Andrew Poelstra 5a891dec2d
move bitcoin fuzz targets into bitcoin/ subdirectory 2023-04-27 00:24:52 +00:00
Andrew Poelstra e3111c748b
move bitcoin/fuzz into repo root; add to workspace
This allows testing the fuzztests and making sure that they compile and
tests pass, etc., just using `cargo test --all` in the root.
2023-04-27 00:24:48 +00:00
Tobin C. Harding b9643bf3e9 Import bitcoin_hashes crate into hashes
We would like to bring the `bitcoin_hashes` crate into the
`rust-bitcoin` repository.

Import `bitcoin_hashes` into `rust-bitocin/hashes`, doing so looses all
the commit history from the original crate but if we archive the
original repository then the history will be preserved. We maintain the
same version number obviously and in the changelog we note the change of
repository.

Commit hash that was tip of `bitcoin_hashes` at time of import:

 commit 54c16249e06cc6b7870c7fc07d90f489d82647c7

Includes making `embedded` and `fuzzing` per-crate i.e., move them into
`bitcoin` as hashes includes these also.

NOTE: Does _not_ enable fuzzing for `hashes` in CI.

Notes on CI:

Attempts to merge in the github actions from the hashes crate however reduces
coverage by not running hashes tests for beta toolchain. Some additional
work could be done to improve the CI to increase efficiency without
reducing coverage. Leaving for another day.
2022-11-08 08:58:09 +11:00
Tobin C. Harding b84e1d46c0 Move amount module out of util
Done as part of flattening the `util` module. Simply move the `amount`
module out of the `util` module and to the crate root. Justified by the
fact that the `Amount` type is more-or-less a "primitive" bitcoin type.
2022-10-21 10:16:49 +11:00
Tobin C. Harding facd8ba556 Move bip152 module to crate root
We are attempting to flatten the `util` module; move the `bip152` module
to the crate root out of `util`.

Currently `src/util/` is ignored by the formatter so this move causes
the `bip152` module to be formatted.
2022-10-19 06:40:33 +11:00
Tobin C. Harding cb9893c4a9 Add Target and Difficulty types
Currently we use the `Uint256` type to represent two proof of work
integers, namely target and difficulty (work).

It would be nice to not have a public integer type that is not fully
implemented (i.e., does not implement arithmetic etc as do integer types
in stdlib). Instead of implementing all the stdlib functions we can
instead add two new wrapper types, since these are not general purpose
integers they do not need to implement anything we do not need to use.

- Add a `pow` module.
- Put a modified version of `Uint256` to `pow`.
- Add two new wrapper types `Target` and `Difficulty`.
- Only implement methods that we use on each type.

Note this patch does not remove the original `Uint256`, that will be
done as a separate patch.
2022-09-28 04:16:59 +10:00
Andrew Poelstra 433952d53a
Merge rust-bitcoin/rust-bitcoin#1279: Add fuzz test for PrefilledTransaction
b79c178ea8 Add fuzz test for PrefilledTransaction (Tobin Harding)

Pull request description:

  Add a simple deserialization fuzz test for `PrefilledTransaction`.

  Fixes: #460 (I think, I'm not sure if any of the other types need fuzzing?)

ACKs for top commit:
  apoelstra:
    ACK b79c178ea8
  Kixunil:
    ACK b79c178ea8

Tree-SHA512: 3e5cbda6b17c36f414bce05b562b5648d82433b185853e6c8aa33ec491b58e527626eb09caca2a988120329efd92dfd3aaad60ef99746d6ac41555160efeb9d6
2022-09-20 14:07:05 +00:00
Tobin Harding b79c178ea8 Add fuzz test for PrefilledTransaction
Add a simple deserialization fuzz test for `PrefilledTransaction`.
2022-09-16 13:02:24 +10:00
Tobin C. Harding 3f275f7f2b Remove code deprecated in v0.28.0
I believe we said we'd keep deprecated code around for two release
cycles so this code can  all be deleted now.
2022-09-15 13:29:02 +10:00
Tobin C. Harding e1ae9d86bb Move the address module out of util
The identifier 'util' does not convey any information. We have a whole
bunch of modules inside the `util` module.

As part of work to reduce the amount of arbitrary things in the `util`
module move the `address` module to the crate root level.
2022-08-12 07:35:15 +10:00
eunoia_1729 89bd4b61a4
Modify from_script functions in address.rs to return result
Modify from_script functions to return result instead of option so that, in case of errors, there is more
information on what went wrong.

Resolves: #1022
2022-06-09 01:13:51 +05:30
Riccardo Casatta 106acdc3ac
Add fuzzing for Witness struct 2021-12-28 09:56:41 +01:00