GHSA-4VM8-79JJ-J6W4
Proof-of-work verification accepts invalid compact targets
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-4VM8-79JJ-J6W4 divulgada · CVSS 7.5 (GitHub) | |
| Remediación | Parche 7.0.5 | bitcoinjs-lib · 0 d desde divulgación | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Summary
`Block.checkProofOfWork()` in `bitcoinjs-lib` compares a header hash against the magnitude returned by `Block.calculateTarget()` without first validating the compact target in the header's `nBits` field. It can therefore return `true` for a header whose proof-of-work target is invalid under Bitcoin's rules.
Impact
An attacker who can supply headers to an application using this method may cause it to accept invalid headers as having valid proof of work. This affects applications that rely on the result without independently validating the compact target and the applicable consensus rules. The resulting impact depends on what the application trusts or authorizes based on those headers.
Details
The compact format has an exponent, a mantissa and a sign bit. The conversion masks off the sign bit, so `checkProofOfWork()` treats a negative target as a positive magnitude instead of rejecting it.
Overflow handling depends on the version:
- Versions 2.2.0 and 2.3.0 use indexed Buffer writes. V7 uses indexed Uint8Array writes. Out-of-range writes are discarded, so an overflowing target can become a large 256-bit value that passes the hash comparison. For example, `0x2101ffff` is invalid because its target exceeds 256 bits, but truncation leaves a value starting with `ffff`.
- V3 through v6 use checked Buffer writes. Those versions throw for that overflow example rather than accepting it. They remain affected by the missing negative-target check for compact encodings that fit their write bounds.
These are version-dependent manifestations of the same missing compact-target validation before the proof-of-work comparison.
Affected versions
The affected API was introduced in 2.2.0. Inspection of the published package contents confirms the following affected releases:
| Version line | Affected releases |
| --- | --- |
| v2 through v4 | 2.2.0 through 4.0.5 |
| v5 | 5.0.0 through 5.2.2 |
| v6 | 6.0.0 through 6.1.9, including 6.1.0-rc.0 |
| v7 | 7.0.0-rc.0 through 7.0.4 |
Patched npm releases are 5.2.3, 6.1.10 and 7.0.5. Versions below v5 have no backport; affected users must upgrade to a fixed version on one of those lines.
Reproduction
On the published `bitcoinjs-lib@7.0.4`, this CommonJS example prints `true` for both invalid targets:
const { Block } = require('bitcoinjs-lib');
for (const bits of [0x20ffffff, 0x2101ffff]) {
const block = new Block();
block.version = 1;
block.prevHash = new Uint8Array(32);
block.merkleRoot = new Uint8Array(32);
block.timestamp = 0;
block.bits = bits;
block.nonce = 0;
const parsed = Block.fromHex(block.toHex(true));
console.log(bits.toString(16), parsed.checkProofOfWork());
}The first target is negative. The second overflows 256 bits. Both must be rejected regardless of the header hash. This example uses the actual serialized headers and their computed hashes.
Remediation and workaround
Upgrade to bitcoinjs-lib 5.2.3, 6.1.10 or 7.0.5, or a later patched release on the corresponding line. The fix rejects negative, zero and overflowing compact targets before comparing the header hash, using the compact-target validity rules in Bitcoin Core. Applications that cannot upgrade must perform this validation independently before relying on `checkProofOfWork()`.
Applications must also enforce their network's proof-of-work limit and the difficulty required at that point in the chain. The method has no network or chain context, so even a corrected `true` result is not a complete validation of a header or chain.
References
- Bitcoin Core compact-target decoding
https://github.com/bitcoin/bitcoin/blob/master/src/arith_uint256.cpp - Bitcoin Core proof-of-work validation
https://github.com/bitcoin/bitcoin/blob/master/src/pow.cpp - Fix: Reject invalid compact proof-of-work targets
https://github.com/bitcoinjs/bitcoinjs-lib/commit/0486f08d475c84c258e40703bf83a598caa41a4b
Reported by ARSB (@ARSB1).
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
npmbitcoinjs-lib |
Corregida | 7.0.5 | 0 d | 7.0.5 no afectada |
5.0.07.0.5Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/bitcoinjs/bitcoinjs-lib/security/advisories/GHSA-4vm8-79jj-j6w4Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
