|
1 | 1 | # bitcoin-kernel |
2 | 2 |
|
3 | | -An independent, auditable Bitcoin consensus engine that **proves itself in your browser**. |
| 3 | +An independent, zero-dependency implementation of Bitcoin's consensus rules. |
| 4 | +Pure ESM, so the same code runs in Node and in the browser. |
4 | 5 |
|
5 | | -**https://bitcoin-kernel.github.io/** loads its own vendored copy of the engine and Bitcoin |
6 | | -Core's own `script_tests.json`, and runs the differential live, same-origin — the numbers are |
7 | | -computed on the page, not claimed. It found and fixed 5 real consensus bugs along the way. |
| 6 | +It comes in three parts, all from one source of truth: |
8 | 7 |
|
9 | | -Fully standalone: the engine (`engine/codec/`), the consensus rules (`engine/schema/`), and |
10 | | -Core's vectors (`engine/vectors/`) are vendored in. No runtime dependency on anything else. |
| 8 | +- **Library** — import it and validate headers, difficulty, blocks, transactions, scripts and inclusion proofs. |
| 9 | +- **Test suite** — run live at **https://bitcoin-kernel.github.io/**, across all of Bitcoin's rules, from real test vectors (including Bitcoin Core's own script vectors). Every result is computed in your browser, not claimed. |
| 10 | +- **Specification** — **https://bitcoin-kernel.github.io/spec.html**, generated from the same machine-readable ruleset, so the spec cannot drift from the code. |
11 | 11 |
|
| 12 | +## Use it as a library |
| 13 | + |
| 14 | +```js |
| 15 | +import { createKernel } from 'bitcoin-kernel'; |
| 16 | + |
| 17 | +const k = createKernel(); // codec, script, interpreter, headers, blocks, spv |
| 18 | + |
| 19 | +const header = k.codec.decode('BlockHeader', headerHex); |
| 20 | +k.codec.blockHash(header); // the block hash |
| 21 | +k.headers.work(header); // its chain work |
12 | 22 | ``` |
13 | | -npm install # dev-only: pulls the engine to vendor from |
14 | | -npm run build # re-vendors engine + regenerates index.html |
| 23 | + |
| 24 | +Or import individual pieces: |
| 25 | + |
| 26 | +```js |
| 27 | +import { ScriptInterpreter, HeaderEngine, verifyEcdsa } from 'bitcoin-kernel'; |
| 28 | +``` |
| 29 | + |
| 30 | +The package lives in [`engine/`](engine/). From a clone you can import it directly |
| 31 | +(`./engine/index.js`) today; an `npm install bitcoin-kernel` is a later step. |
| 32 | + |
| 33 | +## What it checks |
| 34 | + |
| 35 | +Six suites, in the order a node validates a block: |
| 36 | + |
| 37 | +| Suite | Covers | |
| 38 | +|---|---| |
| 39 | +| Headers | prev-link, proof of work, timestamps, version, difficulty | |
| 40 | +| Difficulty | the 2016-block retarget, against real retargets from the chain | |
| 41 | +| Blocks | one coinbase first, merkle commitment, no duplicates, size and sigop limits | |
| 42 | +| Transactions & money | the halving schedule, the 21M cap, well-formed transactions | |
| 43 | +| Spending (scripts) | Bitcoin Core's script test vectors | |
| 44 | +| Light clients (SPV) | merkle inclusion proofs | |
| 45 | + |
| 46 | +## Build the site |
| 47 | + |
| 48 | +`build.js` vendors the engine and the test vectors into `engine/`, emits the |
| 49 | +importable library, and generates `index.html` and `spec.html`. |
| 50 | + |
| 51 | +```sh |
| 52 | +npm install # pulls the upstream engine to vendor from |
| 53 | +npm run build |
15 | 54 | ``` |
16 | 55 |
|
17 | | -Engine source: [@bitcoin-desktop/schema](https://github.com/bitcoin-desktop/schema). |
18 | | -Independent community project; not affiliated with Bitcoin Core. |
| 56 | +## Notes |
| 57 | + |
| 58 | +- About 2,400 lines of JavaScript, zero runtime dependencies. |
| 59 | +- The scripts suite runs about 1,191 of Bitcoin Core's roughly 1,222 script |
| 60 | + vectors. The rest (CLTV/CSV timelocks and some witness-malleability |
| 61 | + structural checks) are skipped, visibly, in the code. |
| 62 | +- The engine is developed upstream at |
| 63 | + [@bitcoin-desktop/schema](https://github.com/bitcoin-desktop/schema). |
| 64 | +- Independent community project, not affiliated with Bitcoin Core. |
0 commit comments