GHSA-fj2x-735w-74vq is a high-severity (CVSS 7.5) remote code execution vulnerability in github.com/consensys/gnark-crypto. A fix is available for github.com/consensys/gnark-crypto — see the affected versions and patch details below.
gnark-crypto allows unchecked memory allocation during vector deserialization
Real-World Exposure
github.com/consensys/gnark-crypto🐹github.com/consensys/gnark-cryptoReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects Go packages — download data is not available via public APIs for these ecosystems.
Description
The issue has been reported by @raefko from @fuzzinglabs. Excerpts from the report:
A critical vulnerability exists in the gnark-crypto library's
Vector.ReadFrom()function that allows an attacker to trigger arbitrary memory allocation by crafting malicious input data. An attacker can cause the verifier to attempt allocating up to 128 GB of memory with a minimal malicious input, leading to out-of-memory crashes and denial of service.Root Cause
The vulnerability stems from unchecked deserialization of attacker-controlled length fields in the gnark-crypto library's
Vector.ReadFrom()function. The function reads a 4-byte unsigned integer from untrusted input and directly uses it to allocate memory without any validation or bounds checking.Vulnerable Code Path
User Input (Malicious Proof/Data) ↓ gnark Proof/Data Deserialization ↓ Vector.ReadFrom() (ecc/bn254/fr/vector.go:136-144) → sliceLen := binary.BigEndian.Uint32(buf[:4]) // ← ATTACKER-CONTROLLED → (*vector) = make(Vector, sliceLen) // ← UNCHECKED ALLOCATION ↓ runtime.makeslice attempts 100+ GB allocation ↓ fatal error: runtime: out of memory → SIGABRTVulnerable Code
File:
[email protected]+/ecc/bn254/fr/vector.go:136-144The code reads a 4-byte big-endian unsigned integer (
sliceLen) directly from the input stream and uses it to allocate a slice without any bounds checking or validation. Each element is 32 bytes (fr.Element for BN254 curve), so an attacker can request up to:Maximum Allocation:
2^32 elements × 32 bytes = 137,438,953,472 bytes ≈ 128 GBRoot Cause Analysis
The gnark-crypto library implements a generic serialization format for field element vectors. The format is:
[4 bytes: length (n)] [n × 32 bytes: elements]The deserialization code trusts the length field implicitly without any validation. This is a classic integer-to-allocation vulnerability pattern, similar to issues that have affected many serialization libraries over the years.
Impact
The issue impacts users deserializing vectors directly from untrusted sources. In case of malicious input it would lead to OOM in case the server doesn't have sufficient memory (depending on the field, but could allocate from 32GB to 196GB).
Patches
The issue is patched in https://github.com/Consensys/gnark-crypto/pull/759. It will be backported to gnark-crypto v0.18 and v0.19.
Workarounds
The user could manually peek into the first 4 bytes of the serialized data to estimate if the header would allocate large amounts of memory.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 🐹Go | github.com/consensys/gnark-crypto | ≥ 0.9.1&&< 0.18.1 | 0.18.1go get github.com/consensys/gnark-crypto@v0.18.1 |
| 🐹Go | github.com/consensys/gnark-crypto | ≥ 0.19.0&&< 0.19.2 | 0.19.2go get github.com/consensys/gnark-crypto@v0.19.2 |
Detection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for github.com/consensys/gnark-crypto, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update github.com/consensys/gnark-crypto to 0.18.1 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-fj2x-735w-74vq is resolved across your whole dependency graph.
Workarounds
If you can't upgrade right away: gate or disable the affected feature, validate untrusted input at the boundary, and avoid passing attacker-controlled data into the vulnerable path. O3's runtime protection blocks exploitation in production as an interim safeguard until the upgrade lands.
How O3 protects you
O3 Security's impact-aware SCA analyses which vulnerable code paths your application actually calls, so a match like GHSA-fj2x-735w-74vq can be triaged on real exposure rather than presence alone.
Tailored to GHSA-fj2x-735w-74vq. Runtime protection reduces exposure until a permanent patch is applied and verified — it complements patching, it doesn't replace it.
Frequently Asked Questions
Is GHSA-fj2x-735w-74vq in your dependencies?
O3 Security finds GHSA-fj2x-735w-74vq across Go dependencies, including transitive ones, and its impact-aware SCA ranks findings by whether your code actually calls the vulnerable path.