VAITP Dataset

← Back to the dataset

CVE-2025-26622

Vyper `sqrt()` may return rounded-up results due to oscillation. Upgrade to 0.4.1.

  • CVSS 2.3
  • CWE-682 Incorrect Calculation
  • Numeric Errors
  • Remote

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.

CVSS base score
2.3
Published
2025-02-21
OWASP
A03:2021 Cryptographic Failures
Orthogonal defect classification
Algorithm
Code defect classification
Incorrect Algorithm
Category
Numeric Errors
Subcategory
Numeric Errors
Accessibility scope
Remote
Impact
Information Disclosure
Affected component
Vyper
Fixed by upgrading
Yes

Solution

Upgrade to Vyper version 0.4.1.

Vulnerable code sample

def sqrt(x):
    """Vulnerable function that demonstrates the security issue."""
    
    if x < 0:
        raise ValueError("Cannot calculate square root of a negative number")
    if x == 0:
        return 0

    guess = x
    next_guess = (guess + 1) // 2 

    for _ in range(100): 
        guess = next_guess
        next_guess = (guess + x // guess) // 2 

    return guess

Patched code sample

def sqrt(x: int) -> int:
    """Secure function that fixes the vulnerability."""
    
    if x < 0:
        raise ValueError("Cannot calculate square root of negative number")
    if x == 0:
        return 0

    y = x
    z = (x + 1) // 2
    while z < y:
        y = z
        z = (x // z + z) // 2

    if (y + 1)**2 <= x:
       return y + 1
    else:
       return y

Payload

# This is a conceptual payload and might require adaptation based on the specific Vyper contract.
# It aims to exploit the oscillating final states issue in the sqrt() function.
# It relies on knowing an input value that triggers the rounding error.

# Example: Input value that is *suspected* to trigger the vulnerability.
# This value needs to be determined through analysis and testing of the vulnerable sqrt() implementation.
# The optimal input might depend on Vyper compiler version, EVM version, and other factors.
input_value = 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000  # Replace with a value found to be problematic.

# Vyper code snippet (Hypothetical contract vulnerable

Cite this entry

@misc{vaitp:cve202526622,
  title        = {{Vyper `sqrt()` may return rounded-up results due to oscillation. Upgrade to 0.4.1.
}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2025},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2025-26622},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2025-26622/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::