Get a Demo

Let's Patch It!

Book a short call with one our specialists, we'll walk you through how Endor Patches work, and ask you a few questions about your environment (like your primary programming languages and repository management). We'll also send you an email right after you fill out the form, feel free to reply with any questions you have in advance!

CVE

GHSA-fj2x-735w-74vq

gnark-crypto allows unchecked memory allocation during vector deserialization
Back to all
CVE

GHSA-fj2x-735w-74vq

gnark-crypto allows unchecked memory allocation during vector deserialization

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 → SIGABRT

```

### Vulnerable Code

Filegnark-crypto@v0.14.0+/ecc/bn254/fr/vector.go:136-144

The 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 Allocation2^32 elements × 32 bytes = 137,438,953,472 bytes ≈ 128 GB

## Root 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.

Package Versions Affected

Package Version
patch Availability
No items found.

Automatically patch vulnerabilities without upgrading

Fix Without Upgrading
Detect compatible fix
Apply safe remediation
Fix with a single pull request

CVSS Version

Severity
Base Score
CVSS Version
Score Vector
C
H
U
-
C
H
U
0
-
3.1
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
C
H
U
7.5
-
3.1
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

Related Resources

No items found.

References

https://github.com/Consensys/gnark-crypto/security/advisories/GHSA-fj2x-735w-74vq, https://github.com/Consensys/gnark-crypto/pull/759, https://github.com/Consensys/gnark-crypto/commit/2e7bf9190a0aac896eeec3876c87c77a35661be7, https://github.com/Consensys/gnark-crypto, https://pkg.go.dev/vuln/GO-2025-4087

Severity

7.5

CVSS Score
0
10

Basic Information

Ecosystem
Base CVSS
7.5
EPSS Probability
0%
EPSS Percentile
0%
Introduced Version
0.9.1,v0.19.0,v0.17.0,v0.0.0-20250207152332-7cfb6bd55d5c,v0.15.0,v0.0.0-20241210190033-77d62f9fa9d0,v0.11.2,v0.0.0-20230702194353-69ddf67791bb,v0.9.1,v0.0.0-20230124162613-e23e21934a3e
Fix Available
0.18.1,v0.19.2,v0.18.1,v0.0.0-20251023143326-2e7bf9190a0a

Fix Critical Vulnerabilities Instantly

Secure your app without upgrading.
Fix Without Upgrading