CVE-2025-26622: sqrt doesn't define rounding behavior in Vyper

Published Feb 21, 2025
·
Updated

vyper is a Pythonic Smart Contract Language for the EVM. Vyper 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. This issue is being addressed and a fix is expected in version 0.4.1. Users are advised to upgrade as soon as the patched release is available. There are no known workarounds for this vulnerability.

Other sources

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 zcur == zprev, 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.

— GitHub

Affected Software

2 affected componentsFixes available
vyperlang Vyper Python<0.4.1
pip/vyper<=0.4.0
0.4.1

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade pip/vyper to a version that resolves this vulnerability.

    Fixed in 0.4.1
  2. Upgrade

    Upgrade vyper to a version that resolves this vulnerability.

    Fixed in 0.4.1Patch https://github.com/vyperlang/vyper/pull/4486

Event History

Feb 21, 2025
CVE Published
via MITRE·09:36 PM
Data Sourced
via MITRE·09:36 PM
DescriptionWeakness
Advisory Published
via GitHub·10:43 PM
Data Sourced
via GitHub·10:43 PM
DescriptionWeaknessAffected Software

Frequently Asked Questions

1

What is the severity of CVE-2025-26622?

CVE-2025-26622 is considered a moderate severity vulnerability due to the potential for incorrect calculations in smart contracts.

2

How do I fix CVE-2025-26622?

To fix CVE-2025-26622, upgrade vyper to version 0.4.1 or later as it addresses the identified issue.

3

What software is affected by CVE-2025-26622?

CVE-2025-26622 affects the vyper package versions up to and including 0.4.0.

4

What are the consequences of CVE-2025-26622?

The consequence of CVE-2025-26622 is that the sqrt() function may return inaccurate rounded results, affecting the logic of smart contracts.

5

Is CVE-2025-26622 a remote or local vulnerability?

CVE-2025-26622 is primarily a local vulnerability since it involves the execution of smart contracts on the Ethereum Virtual Machine.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203