bitcoinkernel

Crates.iobitcoinkernel
lib.rsbitcoinkernel
version
sourcesrc
created_at2024-11-04 14:11:22.897821
updated_at2024-12-04 10:19:22.973997
descriptionSafe Rust bindings to libbitcoinkernel
homepage
repositoryhttps://github.com/TheCharlatan/rust-bitcoinkernel
max_upload_size
id1435052
Cargo.toml error:TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Reproducibility Matters (TheCharlatan)

documentation

https://docs.rs/bitcoinkernel

README

rust-bitcoinkernel

:warning::construction: This library is still under contruction. :warning::construction:

rust-bitcoinkernel is a wrapper around libbitcoinkernel, a C++ library exposing Bitcoin Core's validation engine. It supports both validation of blocks and transaction outputs as well as reading block data.

Building

The library statically compiles the Bitcoin Core libbitcoinkernel library as part of its build system. Currently it targets the kernelApi branch on the following fork: https://github.com/TheCharlatan/bitcoin/tree/kernelApi.

Bitcoin Core is vendored as a git subtree in this project. The subtree can be updated, or made to point at a different commit or branch in Bitcoin Core's history with:

 git subtree pull --prefix libbitcoinkernel-sys/bitcoin https://github.com/TheCharlatan/bitcoin kernelApiNode --squash

To build this library, the usual Bitcoin Core build requirements, such as cmake and a working C and C++ compiler are required. An installation of boost is required as well. Consult the Bitcoin Core documentation for the required dependencies. Once setup, run:

cargo b

Examples

Examples for the usage of the library can be found in the examples/ directory and the tests. For now, the example binary implements a bare-bones silent payments scanner.

Fuzzing

Fuzzing is done with cargo fuzz.

There are currently three supported fuzzing targets: fuzz_target_block, fuzz_target_chainman and fuzz_target_verify. The chainman target touches the filesystem in /tmp. If /tmp is not already a tmpfs, the user should create a tmpfs in /tmp/rust_kernel_fuzz.

To get fuzzing run (in this case the verify target):

cargo fuzz run fuzz_target_verify

Sanitizers can be turned on with e.g.

RUSTFLAGS="-Zsanitizer=address" cargo fuzz run fuzz_target_block

To get the sanitizer flags working in the libbitcoinkernel Bitcoin Core library, the easiest way for now is to edit the libbitcoinkernel-sys/build.rs flags.

Coverage

Once fuzzed, a coverage report can be generated with (picking the verify target as an example):

RUSTFLAGS="-C instrument-coverage" cargo fuzz coverage fuzz_target_verify
llvm-cov show \
  -format=html \
  -instr-profile=fuzz/coverage/fuzz_target_verify/coverage.profdata \
  target/x86_64-unknown-linux-gnu/coverage/x86_64-unknown-linux-gnu/release/fuzz_target_verify \
  -show-line-counts-or-regions \
  -Xdemangler=rustfilt \
  -output-dir=coverage_report \
  -ignore-filename-regex="/rustc"

You may have to install the following tooling:

rustup component add llvm-tools-preview
cargo install rustfilt
Commit count: 141

cargo fmt