Bitcoin kernel

From claude-dev-suite/claude-dev-suite · View interactive version

Bitcoin kernel is an AI agent skill from the GitHub repository claude-dev-suite/claude-dev-suite. libbitcoinkernel: Bitcoin Core's experimental C library exposing the validation engine (block/header validation, block index traversal, block + undo reads, script verification), and the `bitcoinkernel` Rust bindings over `libbitcoinkernel-sys`. USE WHEN: embedding Core's exact consensus semantics in

How to use this skill

Skill file

libbitcoinkernel / rust-bitcoinkernel

Core's validation engine, factored out as a C-ABI library. Two layers:

the Bitcoin Core tree, plus the bitcoinkernel CMake target.

FFI/build crate. Repo: github.com/sedited/rust-bitcoinkernel

(the TheCharlatan/rust-bitcoinkernel URL still redirects there).

Status: experimental (as of September 2026)

The header's own Remarks section in Bitcoin Core v31.1 (July 2026)

states the API "is unversioned and not stable yet. Users should expect

breaking changes. It is also not yet included in releases of Bitcoin

Core." Upstream tracking is bitcoin/bitcoin#27587, "Bitcoin Kernel

Library Project Tracking" (open, last updated 31 July 2026).

It is not built by default. BUILD_KERNEL_LIB ("Build experimental

bitcoinkernel library") defaults to the value of BUILD_UTIL_CHAINSTATE,

which is OFF in v31.1, so you must opt in:

cmake -B build -DBUILD_KERNEL_LIB=ON       # BUILD_KERNEL_TEST follows it
cmake --build build

Treat the library as a moving target and pin an exact commit or crate

version.

Why it exists

Core's old libbitcoinconsensus was deprecated in v27.0 and removed

entirely in v28.0 (release notes, PR #29648) - src/script/bitcoinconsensus.h

is present at tag v27.0 and gone at v28.0. It only ever did isolated

script verification. The kernel library is the replacement and is

stateful: it owns a chainstate, so it can validate whole blocks against

real chain context, not just scripts.

Scope

Per the v31.1 header's Purpose section, the C API covers:

No P2P, no wallet, no RPC server, no mempool acceptance. A context is

passed to state-rich calls; a built-in static context covers the

"context-free" operations (SHA256 implementation self-check, RNG init,

secp256k1 static context self-check), so no explicit init is required

for those.

Install (Rust)

# latest on crates.io as of September 2026
[dependencies]
bitcoinkernel = "0.3"        # 0.3.0, 26 August 2026; MSRV 1.71.0

libbitcoinkernel-sys (0.4.0, 26 August 2026) is pulled in

transitively - depend on it directly only for raw FFI. All-time

downloads as of September 2026: ~44.6k for bitcoinkernel, ~47.6k for

libbitcoinkernel-sys.

Build requirements

libbitcoinkernel-sys vendors Bitcoin Core as a git subtree at

libbitcoinkernel-sys/bitcoin and statically compiles the kernel

library as part of cargo build. That means the host needs Core's own

build dependencies - cmake, a working C and C++ toolchain, and an

installation of Boost. First builds are slow; budget for them in CI.

Since bitcoinkernel 0.2.1 / libbitcoinkernel-sys 0.3.0 (both

20 May 2026) the sys crate ships checked-in bindings instead of

generating them with bindgen, which upstream notes removes some

build-time dependencies.

Users on rustc older than 1.77 should build with --locked

(Cargo-minimal.lock / Cargo-recent.lock pin the two extremes).

Android cross-compilation is available through the repo's Nix flake

(nix build .#libbitcoinkernel-android-aarch64), targeting API 24+.

Quick examples

Validate a block

use bitcoinkernel::{
    Block, ChainType, ChainstateManager, ContextBuilder, ProcessBlockResult,
};

let context = ContextBuilder::new()
    .chain_type(ChainType::Mainnet)
    .build()?;

let chainman = ChainstateManager::new(&context, "/path/to/data", "/path/to/blocks")?;

let block = Block::new(&block_bytes)?;
match chainman.process_block(&block) {
    ProcessBlockResult::NewBlock => println!("validated and written to disk"),
    ProcessBlockResult::Duplicate => println!("already known (valid)"),
    ProcessBlockResult::Rejected => println!("validation failed"),
}

Verify a script

use bitcoinkernel::{prelude::*, verify, PrecomputedTransactionData, Transaction, VERIFY_ALL};

let spending_tx = Transaction::new(&spending_tx_bytes)?;
let prev_tx = Transaction::new(&prev_tx_bytes)?;
let prev_output = prev_tx.output(0)?;
let tx_data = PrecomputedTransactionData::new(&spending_tx, &[prev_output])?;

let result = verify(
    &prev_output.script_pubkey(),
    Some(prev_output.value()),
    &spending_tx,
    0,                      // input index
    Some(VERIFY_ALL),
    &tx_data,
);

Passing the spent outputs is what enables taproot verification; without

them the precomputed data cannot produce a BIP341 sighash.

Crate layout

| Module | Holds |

|--------|-------|

| core | Blocks, transactions, scripts |

| state | ChainstateManager, Context, ChainParams |

| notifications | Validation / tip-update / warning callbacks |

| log | Bridge to Core's logging |

| prelude | Extension traits (ScriptPubkeyExt, TxInExt, ...) |

0.3.0 (August 2026) added context-free Block::check and

Transaction::check, witness-stack accessors (TxInExt::witness_stack),

a typed ScriptVerificationFlags in place of a bare u32, and

ChainParams::new_signet / ContextBuilder::signet for custom signets.

Use cases

byte on what is valid.

The repo's examples/ ships a bare-bones silent payments scanner.

chainman_process_block and script_verify cargo-fuzz targets.

Common pitfalls

no compatibility promise; the Rust crate has had renames and signature

changes at every minor (e.g. 0.3.0 renamed

ProcessBlockHeaderResult::Success/Failed to Valid/Invalid and

made process_block_header return a Result). Pin exact versions.

the same crate version against different subtree commits are different

consensus engines. Check subtree movement with

./contrib/check_subtree_kernel_commits.sh after a

git subtree pull.

supply blocks. No mempool acceptance and no policy RPCs.

returned None for every input.

system package to link against; you build it.

See also

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.