tiny-secp256k1: Stale buffer after ignored wasm failure accepts invalid infinity tweak
Affected packages
| Package | Affected → Fixed | |
|---|---|---|
| bitcoinjstiny-secp256k1 | — | Not listed |
| @bitcoin-jsiny-secp256k1-asmjs | — | Not listed |
| npmtiny-secp256k1 |
< 2.2.5→ 2.2.5 |
2.2.5 |
| npm@bitcoin-js/tiny-secp256k1-asmjs |
< 2.2.5→ 2.2.5 |
2.2.5 |
Original description The description as published by the source.
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 bu…
Source: CVE.org (CVE Program・cvelistV5) NVD GitHub Advisory
References
- advisory github.com
- package github.com
- web github.com
- web github.com
- web github.com
- web nvd.nist.gov
- web github.com