Skip to main content
Menu
Advisories

Point-validation exceptions leave backend stack state damaged

GHSA-85G9-F6V5-WQQ7Published Updated GitHub

Description

The WebAssembly build of tiny-secp256k1 can leave its shadow-stack pointer changed when point validation throws a JavaScript exception from inside an active WASM call. Catching the exception in application code does not restore the pointer. The generated @bitcoin-js/tiny-secp256k1-asmjs backend contains the same skipped stack-restoration path.

Repeated invalid inputs can exhaust the shared module's stack and make later valid cryptographic operations fail. A long-running application that passes untrusted public keys to the affected operations can therefore lose cryptographic service until the module is reloaded.

Details

The JavaScript validators check byte-array types and lengths but do not perform all curve-membership checks. An invalid point with the expected length can reach the Rust/WASM implementation.

When a point check fails, the WASM code invokes an imported JavaScript throwError function. That function throws a TypeError. The exception leaves the active WASM call without running the cleanup that would restore its LLVM shadow-stack pointer.

The loader shares one module instance, so later operations use the damaged state. A try/catch around the library call does not undo the change to the mutable WASM global. JavaScript cleanup of input buffers also does not restore that pointer.

Affected paths include pointAdd, pointCompress, pointMultiply, pointAddScalar and verify. The x-only and Schnorr operations present in later releases add xOnlyPointFromPoint, xOnlyPointAddTweak, xOnlyPointAddTweakCheck and verifySchnorr.

Static inspection of the integrity-checked asm.js packages shows a translated mutable stack pointer, a call to the imported throwError function on point rejection and restoration code after that call. The thrown exception skips restoration there too. The WASM exhaustion thresholds and downstream effects below have not been measured for asm.js.

Example

With the published WASM build of tiny-secp256k1 2.2.4, an invalid public key with the correct length reaches backend point validation:

import * as ecc from "tiny-secp256k1";

const hash = new Uint8Array(32);
const signature = new Uint8Array(64).fill(1);
const invalidPoint = new Uint8Array(32).fill(0xff);

try {
  ecc.verifySchnorr(hash, invalidPoint, signature);
} catch (error) {
  console.log(error.name, error.message); // TypeError: Expected Point
}

This example illustrates one rejection, not stack exhaustion. The reporter observed that repeated rejections eventually make valid operations trap in the published WASM module. The number of calls depends on the operation and compiled binary. Use an isolated process when examining the affected artifact.

Impact

An attacker who can make an application repeatedly process invalid points can disable signing and verification in the shared instance. This is not just a failure of the rejected calls: valid operations can fail afterwards.

The reporter also observed pointer wraparound and corruption of static point-multiplication tables after millions of further calls. That can lead to incorrect public-key results. Such corruption requires substantially more calls than stack exhaustion and is dependent on the compiled memory layout. This report does not establish private-key disclosure.

Affected versions

  • tiny-secp256k1: 2.0.0 through 2.2.4.
  • @bitcoin-js/tiny-secp256k1-asmjs: 2.2.2 through 2.2.4, based on the generated code's skipped-restoration path.

Not every listed operation exists in every affected release. The v1 native/JavaScript backends do not use this WASM boundary mechanism.

Remediation and workarounds

Upgrade tiny-secp256k1 and @bitcoin-js/tiny-secp256k1-asmjs, as applicable, to 2.2.5 or a later patched release. Backend point validation now returns an error code normally so the frame completes its cleanup. The JavaScript wrapper throws after the backend call returns. This removes the imported JavaScript validation exception from the active WASM or asm.js frame.

Use isolated, restartable workers when processing untrusted inputs. If an affected instance has been used for repeated invalid-point calls, replace the instance or restart its worker rather than continuing to use it for valid cryptographic work.

References

Affected versions

References

GitHub · bitcoinjs/tiny-secp256k1