Rust Bitcoin library
  • Rust 98.6%
  • Shell 1.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Kyle 🐆 5aacba79ef
Ignore beads and Dolt working files
Local issue-tracker state, not part of the fork. Keeps a dirty worktree
from sweeping them into a commit.
2026-09-06 20:04:11 -04:00
.cargo Whitelist mutants in deprecated functions 2026-08-12 12:53:55 +10:00
.github Merge rust-bitcoin/rust-bitcoin#6736: benches: fix encoding use, add CI check, and standardize on criterion 2026-09-05 12:05:21 +00:00
addresses Merge rust-bitcoin/rust-bitcoin#6748: Capitalize Bitcoin protocol references in docs 2026-08-28 01:56:50 +00:00
base58 Merge rust-bitcoin/rust-bitcoin#6736: benches: fix encoding use, add CI check, and standardize on criterion 2026-09-05 12:05:21 +00:00
benches benches: Add the v2 field to the block header literal 2026-09-06 18:05:49 -04:00
bip158 bip158: Add Official test vectors 2026-08-23 00:48:44 +01:00
bitcoin bitcoin: Validate the header form against the hardfork rules 2026-09-06 09:48:26 -04:00
chacha20_poly1305 Remove test_ prefix from tests 2026-08-31 17:24:11 +10:00
consensus_encoding Merge rust-bitcoin/rust-bitcoin#6715: internals: migrate the u256 type from the include system to the internals package 2026-09-05 12:09:05 +00:00
contrib api: remove api snapshot files 2026-08-29 13:29:32 -03:00
crypto Merge rust-bitcoin/rust-bitcoin#6819: Remove panics from LegacyPublicKey::from_str 2026-09-06 12:19:36 +00:00
docs Capitalize Bitcoin protocol references 2026-08-20 16:04:14 +10:00
fuzz Address review findings on the extended header 2026-09-06 09:43:44 -04:00
hashes p2p: Cover a headers message that mixes header widths 2026-09-06 09:33:04 -04:00
include internals: migrate the u256 from include to internals 2026-08-31 12:47:21 -07:00
internals internals: add const-compatible u64 to u128 cast 2026-09-05 23:42:50 +08:00
io io: update API tests to new conventions 2026-07-17 11:15:31 -07:00
key_expression Merge rust-bitcoin/rust-bitcoin#6715: internals: migrate the u256 type from the include system to the internals package 2026-09-05 12:09:05 +00:00
logo chore: format and standardize all markdowns files 2024-04-27 06:29:23 -03:00
network ci: fail if bitcoin-internals is exposed in public api 2026-08-31 11:51:02 -07:00
p2p p2p: Gate the mixed-width headers test on std 2026-09-06 17:43:31 -04:00
primitives Address review findings on the extended header 2026-09-06 09:43:44 -04:00
taproot_primitives Make Keypair::as_inner private 2026-08-31 16:23:33 +10:00
units internals: add const-compatible u64 to u128 cast 2026-09-05 23:42:50 +08:00
.gitattributes Set diff=rust for *.rs in .gitattributes 2024-07-27 08:53:19 +02:00
.gitignore Ignore beads and Dolt working files 2026-09-06 20:04:11 -04:00
AGENTS.md update LLM rules a bit 2026-08-16 14:26:59 +00:00
Cargo-minimal.lock fuzz: delete hashes_0_32_cbor target 2026-09-01 18:14:22 -03:00
Cargo-recent.lock fuzz: delete hashes_0_32_cbor target 2026-09-01 18:14:22 -03:00
Cargo.toml Merge rust-bitcoin/rust-bitcoin#6821: Automated weekly update to rustc stable (to 1.98.1) on master 2026-09-06 12:20:03 +00:00
CLAUDE.md doc: Add agents.md 2025-11-11 09:12:04 +01:00
clippy.toml clippy: modify config file 2026-01-23 11:20:02 -08:00
CONTRIBUTING.md benches: migrate last old benchmark and consolidate on criterion only 2026-08-31 15:03:49 -07:00
justfile ci: upgrade to cargo-rbmt 0.5.3 2026-08-29 13:29:24 -03:00
LICENSE Add LICENSE file with CC0 in it 2014-07-18 17:37:13 -07:00
README.md Document the fork 2026-09-06 15:51:08 -04:00
rustfmt.toml chore: fix typos 2025-10-01 16:55:46 +08:00
SECURITY.md Update the security policy to mention repos 2026-05-09 08:33:05 +10:00

rust-bitcoin with BLAKE2b proof of work

This is an unofficial fork of rust-bitcoin that follows the BLAKE2b proof-of-work hardfork of Bitcoin. It is not affiliated with the rust-bitcoin project. Upstream tracks Bitcoin Core consensus and has not adopted the fork, so use upstream instead if that is what you want.

Not reviewed by upstream. It holds no keys and no funds, but wallets trust it for chain data, so a bug in header parsing or the block id means they follow the wrong chain. Everything below the divider is upstream's documentation and describes rust-bitcoin rather than this fork.

What differs from upstream

  • The extended block header. Header gains an optional HeaderV2 carrying the 84 bytes an extended header adds to the historical 80. A header announces its own form through bit 31 of the version word, so no activation height is compiled in and nothing keys off the block height.
  • BLAKE2b block ids. Header::block_hash() dispatches: SHA256d for the legacy form, and for the extended form the tagged-hash pipeline and two BLAKE2b passes that Bitcoin Knots uses, laid out by the ASIC profile in the header flags. BLAKE2b-256 lives in bitcoin_hashes::blake2b, which this line can do because bitcoin depends on the workspace copy.
  • A self-describing codec. The header length is only known after the version word, so HeaderEncoder and HeaderDecoder are hand written rather than composed from fixed width field codecs. A truncated header still reports the field it was truncated in.
  • Bit 31 is no longer part of the version. Version::from_consensus masks it off, by every construction path including Deserialize, so a header cannot be built that serializes as something other than the value it was made from.
  • Size and weight read the header's real length, and Params gains the activation height and the one-off target shift applied at it.
  • Header form validation. Header::validate_form and validate_form_at_height carry the four rules Knots enforces, so a header syncing client can apply them without building a Block.

Branches

Branch Base Use
master upstream master The 0.33 line. This branch. For when the ecosystem moves off 0.32.
0.32.xx upstream 0.32.xx The 0.32 line. This is what bdk, bdk_wallet and electrum-client pin, so it is the one in use today.

The two lines are separate: 0.33 replaced the consensus encoding traits with a push-based codec, so the header work is implemented differently on each and neither merges into the other.

Releases are tagged so a dependent can pin an immutable rev: a moving branch would let consensus code change under a fresh clone.

Activation

Network Height
mainnet 961,640
testnet4 150,308

Listed for reference. Parsing keys off the header itself rather than a height, so it needs no updating if these change. Params carries them for the rules that genuinely need chain context.

Verification

The extended header and its block id are checked against Bitcoin Knots' own test data at tag v29.4.1.knots20260508, covering all four ASIC layout profiles, and against 25,000 randomized headers generated from an independent transcription of Knots' CBlockHeader::GetHash. The decoder is fuzzed. Both lines produce identical block ids for the same vectors.


Rust Bitcoin

Rust Bitcoin logo by Hunter Trujillo, see license and source files under /logo

Library with support for de/serialization, parsing and executing on data-structures and network messages related to Bitcoin.

Crate Info CC0 1.0 Universal Licensed API Docs Rustc Version 1.74.0+ Chat on IRC

Supports (or should support)

  • De/serialization of Bitcoin protocol network messages
  • De/serialization of blocks and transactions
  • Script de/serialization
  • Private keys and address creation, de/serialization and validation (including full BIP-0032 support)

For JSONRPC interaction with Bitcoin Core, it is recommended to use corepc-client.

It is recommended to always use cargo-crev to verify the trustworthiness of each of your dependencies, including this one.

Known limitations

Consensus

This library must not be used for consensus code (i.e. fully validating blockchain data). It technically supports doing this, but doing so is very ill-advised because there are many deviations, known and unknown, between this library and the Bitcoin Core reference implementation. In a consensus based cryptocurrency, such as Bitcoin, it is critical that all parties are using the same rules to validate data, and this library is simply unable to implement the same rules as Core.

Given the complexity of both C++ and Rust, it is unlikely that this will ever be fixed, and there are no plans to do so. Of course, patches to fix specific consensus incompatibilities are welcome.

Support for 16-bit pointer sizes

16-bit pointer sizes are not supported, and we can't promise they will be. If you care about them please let us know, so we can know how large the interest is and possibly decide to support them.

Semver compliance

We try hard to maintain strict semver compliance with our releases. This codebase includes some public functions marked unstable (e.g., pub fn foo__unstable()). These functions do not adhere to semver rules; use them at your own discretion.

Documentation

Currently can be found on docs.rs/bitcoin. Patches to add usage examples and to expand on existing docs would be extremely appreciated.

Contributing

Contributions are generally welcome. If you intend to make larger changes please discuss them in an issue before PRing them to avoid duplicate work and architectural mismatches. If you have any questions or ideas you want to discuss, please join us in #bitcoin-rust on libera.chat.

For more information, please see CONTRIBUTING.md.

Minimum Supported Rust Version (MSRV)

This library should compile with any combination of features on Rust 1.74.0.

Use Cargo-minimal.lock to build the MSRV by copying to Cargo.lock and building.

No-std support

The std cargo feature is enabled by default. To build this project without the Rust standard library, use the --no-default-features flag or set default-features = false in your dependency declaration when adding it to your project.

For embedded device examples, see bitcoin/embedded or hashes/embedded.

External dependencies

We integrate with a few external libraries, most notably serde. These are available via feature flags. To ensure compatibility and MSRV stability, we provide two lock files as a means of inspecting compatible versions: Cargo-minimal.lock containing minimal versions of dependencies and Cargo-recent.lock containing recent versions of dependencies tested in our CI.

We do not provide any guarantees about the content of these lock files outside of "our CI didn't fail with these versions". Specifically, we do not guarantee that the committed hashes are free from malware. It is your responsibility to review them.

Policy on Altcoins/Altchains

Since the altcoin landscape includes projects which frequently appear and disappear, and are poorly designed anyway we do not support any altcoins. Supporting Bitcoin properly is already difficult enough, and we do not want to increase the maintenance burden and decrease API stability by adding support for other coins.

Our code is public domain so by all means fork it and go wild :)

Release Notes

Release notes are done per crate, see:

Licensing

The code in this project is licensed under the Creative Commons CC0 1.0 Universal license. We use the SPDX license list and SPDX IDs.