CVE-2025-26622: Vyper Vyper's Sqrt Doesn't Define Rounding Vulnerability

LOW
Advisory Identifier: GHSA-2p94-8669-xg86
CWE-682
Published
Advisory Summary

CVE-2025-26622 is a LOW vyper's sqrt doesn't define rounding vulnerability (CWE-682: Incorrect Calculation) affecting Vyper libraries in the PyPI ecosystem. The issue involves vyper's sqrt doesn't define rounding behavior. Remediation is available by upgrading affected packages to version 0.4.1.

CVE-2025-26622 at a Glance

CVE Identifier CVE-2025-26622
GHSA Identifier GHSA-2p94-8669-xg86
Severity LOW
CVSS v3.1 Base Score N/A
CWE Classification CWE-682: Incorrect Calculation
Affected Product Vyper
Package Ecosystem PyPI
Published Date
Last Updated

How to Fix CVE-2025-26622

To remediate this vulnerability, upgrade all affected Vyper dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

vyper fixed: 0.4.1
pip install vyper>=0.4.1
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show vyper

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2025-26622, inspect your installed packages using pip:

pip show vyper

Analyze the terminal output to locate any version of Vyper in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.4.1), your application is affected.

Note: The pip show vyper command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-682: Incorrect Calculation, where the product performs a calculation that generates incorrect or unintended results that are later used in security-critical decisions or resource management. In Vyper, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

Vyper's `sqrt()` builtin uses the babylonian method to calculate square roots of decimals. Unfortunately, improper handling of the oscillating final states may lead to sqrt incorrectly returning rounded up results. the fix is tracked in https://github.com/vyperlang/vyper/pull/4486 ### Vulnerability Details Vyper injects the following code to handle calculation of decimal sqrt. x is the input provided by user. ```python assert x >= 0.0 z: decimal = 0.0 if x == 0.0: z = 0.0 else: z = x / 2.0 + 0.5 y: decimal = x for i: uint256 in range(256): if z == y: break y = z z = (x / z + z) / 2.0 ``` Notably, the terminal condition of the algorithm is either `z_cur == z_prev`, or the algorithm runs for 256 rounds. However, for certain inputs, `z` might actually oscillate between `N` and `N + epsilon`, where `N ** 2 <= x < (N + epsilon) ** 2`. This means that the current behavior does not define whether it will round up or down to the nearest epsilon. The example snippet here returns 0.9999999999, the rounded up result for sqrt(0.9999999998). This is due to the oscillation ending in N + epsilon instead of N. ```vyper @external def test(): d: decimal = 0.9999999998 r: decimal = sqrt(d) #this will be 0.9999999999 ``` Note that `sqrt()` diverges from `isqrt()` here -- `isqrt()` consistently rounds down, so it is not subject to the same issue. ### Impact Details Since `sqrt()` can be used for determining boundary conditions, rounding down is preferred. However, since `sqrt()` is used very rarely in the wild, this advisory has been assigned an impact of `low`.

CVE-2025-26622 Affected Vyper Versions

1 component(s)
Fixed Versions:
0.4.1
Product / Package Ecosystem Affected Versions Fixed Version
vyper
PyPI
< 0.4.1
0.4.1

References

Frequently Asked Questions

What is CVE-2025-26622?
CVE-2025-26622 is a security vulnerability in Vyper involving Vyper's sqrt doesn't define rounding behavior under CWE-682: Incorrect Calculation.
Which Vyper versions are affected?
Affected versions include releases prior to 0.4.1 across affected packages: vyper.
What version fixes CVE-2025-26622?
Upgrading to 0.4.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is vyper affected?
Yes, vyper is affected in releases prior to 0.4.1. Upgrade your dependency to 0.4.1 or later.
What CWE is associated with CVE-2025-26622?
CVE-2025-26622 is classified under CWE-682: Incorrect Calculation (The product performs a calculation that generates incorrect or unintended results that are later used in security-critical decisions or resource management.).
How can I check PyPI dependencies for CVE-2025-26622?
Run the dependency tree command: 'pip show vyper'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-2p94-8669-xg86",
  "modified" : "2025-04-09T20:11:26Z",
  "published" : "2025-02-21T22:43:30Z",
  "aliases" : [ "CVE-2025-26622" ],
  "summary" : "Vyper's sqrt doesn't define rounding behavior",
  "details" : "Vyper's `sqrt()` builtin uses the babylonian method to calculate square roots of decimals. Unfortunately, improper handling of the oscillating final states may lead to sqrt incorrectly returning rounded up results.\n\nthe fix is tracked in https://github.com/vyperlang/vyper/pull/4486\n\n### Vulnerability Details\n\nVyper injects the following code to handle calculation of decimal sqrt. x is the input provided by user.\n```python\nassert x >= 0.0\nz: decimal = 0.0\n\nif x == 0.0:\n    z = 0.0\nelse:\n    z = x / 2.0 + 0.5\n    y: decimal = x\n\n    for i: uint256 in range(256):\n        if z == y:\n            break\n        y = z\n        z = (x / z + z) / 2.0\n```\nNotably, the terminal condition of the algorithm is either `z_cur == z_prev`, or the algorithm runs for 256 rounds.\n\nHowever, for certain inputs, `z` might actually oscillate between `N` and `N + epsilon`, where `N ** 2 <= x < (N + epsilon) ** 2`. This means that the current behavior does not define whether it will round up or down to the nearest epsilon.\n\nThe example snippet here returns 0.9999999999, the rounded up result for sqrt(0.9999999998). This is due to the oscillation ending in N + epsilon instead of N.\n```vyper\n@external\ndef test():\n    d: decimal = 0.9999999998\n    r: decimal = sqrt(d)    #this will be 0.9999999999\n```\n\nNote that `sqrt()` diverges from `isqrt()` here -- `isqrt()` consistently rounds down, so it is not subject to the same issue.\n\n### Impact Details\n\nSince `sqrt()` can be used for determining boundary conditions, rounding down is preferred. However, since `sqrt()` is used very rarely in the wild, this advisory has been assigned an impact of `low`.",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:H/AT:P/PR:L/UI:N/VC:L/VI:L/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "vyper"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.4.1"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 0.4.0"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/vyperlang/vyper/security/advisories/GHSA-2p94-8669-xg86"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-26622"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/vyperlang/vyper/pull/4486"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/vyper/PYSEC-2025-29.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/vyperlang/vyper"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-682" ],
    "severity" : "LOW",
    "github_reviewed" : true,
    "github_reviewed_at" : "2025-02-21T22:43:30Z",
    "nvd_published_at" : "2025-02-21T22:15:13Z"
  }
}