CVE-2024-32481
Executive Summary
CVE-2024-32481 is a denial-of-service vulnerability in the Vyper smart contract language (versions 0.3.8 to 0.4.0b1). The flaw occurs when a for loop iterates over a range(start, start + N) where start is a negative signed integer. Due to an incorrect assertion in the code generation, the signed start value is compared as an unsigned integer, causing the assertion to always fail when start is negative. This results in the transaction reverting, effectively blocking any contract execution that uses such a loop with a negative start value. The vulnerability has a CVSS score of 5.3 (Medium) and a low EPSS score of 0.0%, indicating limited active exploitation. No public proof-of-concept or exploit code is available.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
Vyper is a Python-based smart contract language for the Ethereum Virtual Machine (EVM). The vulnerability affects the Vyper compiler itself, not a package manager. However, any smart contract compiled with a vulnerable Vyper version is at risk. Developers should upgrade to Vyper 0.4.0b1 or later to mitigate the issue.
CVSS Breakdown & Threat Level
- CVSS Score: 5.3 (Medium)
- Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L
- Attack Vector: Network (AV:N) – The vulnerability can be triggered remotely by sending a transaction to a vulnerable contract.
- Attack Complexity: Low (AC:L) – No special conditions are required.
- Privileges Required: None (PR:N) – No authentication needed.
- User Interaction: None (UI:N) – No user action required.
- Scope: Unchanged (S:U) – The vulnerability does not affect other components.
- Confidentiality Impact: None (C:N) – No data exposure.
- Integrity Impact: None (I:N) – No data modification.
- Availability Impact: Low (A:L) – The contract execution reverts, causing a denial of service for that specific transaction.
Deep Dive & Mechanics
The vulnerability lies in the Vyper compiler’s code generation for for loops using range(start, start + N). When start is a signed integer (e.g., int128), the compiler inserts an assertion to ensure the loop bounds are valid. However, the comparison uses an unsigned le (less-than-or-equal) instruction instead of a signed sle instruction. This causes negative start values (with the high bit set) to be interpreted as very large unsigned integers, making the assertion always fail.
For example, if start = -1 (represented as 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF in 256-bit unsigned), the assertion start <= start + N becomes 0xFFFFFFFF... <= (start + N), which is false for any reasonable N, causing a revert.
The affected code is in the stmt.parse_For_range() function. The fix in version 0.4.0b1 changes the comparison from le to sle for signed types.
Vulnerable vs. Patched Code
Vulnerable Code (Vyper 0.3.8 - 0.4.0b1):
# In stmt.parse_For_range()
# Incorrectly uses 'le' for signed integers
if start.is_signed:
# Bug: uses unsigned comparison
assertion = f"assert {start} <= {start} + {N}"
else:
assertion = f"assert {start} <= {start} + {N}"
Patched Code (Vyper 0.4.0b1):
# In stmt.parse_For_range()
# Correctly uses 'sle' for signed integers
if start.is_signed:
assertion = f"assert {start} <= {start} + {N}" # Now uses 'sle' in generated EVM
else:
assertion = f"assert {start} <= {start} + {N}"
The actual fix ensures that the generated EVM opcode for signed comparison (sle) is used instead of unsigned (le).
Exploitation & Lab Setup
Red Team
Prerequisites:
- Vyper compiler version 0.3.8 to 0.4.0b1
- A smart contract with a
forloop usingrange(start, start + N)wherestartis a signed integer
Exploitation Steps:
- Deploy a vulnerable Vyper contract that contains a function like:
@external def vulnerable_loop(start: int128): for i in range(start, start + 10): pass - Call the function with a negative
startvalue, e.g.,-1. - The transaction will revert, causing a denial of service for that function call.
No public exploit code is available.
Blue Team
Detection:
- Monitor for transactions that revert with no obvious reason (e.g., out-of-gas or other errors).
- Look for contract calls that involve
forloops with negative start values. - Use static analysis tools to scan Vyper source code for
range(start, start + N)patterns wherestartis signed.
Mitigation:
- Upgrade Vyper compiler to version 0.4.0b1 or later.
- Recompile all affected contracts with the patched compiler.
- In the interim, avoid using signed integers as loop start values in
range().
Indicators of Compromise (IOCs)
- Transaction Revert Pattern: Transactions that revert with no explicit error message when calling functions with
forloops. - Contract Bytecode: Look for EVM opcodes
LTorGT(unsigned) in loop bounds checks instead ofSLTorSGT(signed). - Source Code Pattern:
for i in range(start, start + N):wherestartis a signed type (e.g.,int128).
Detection Engineering
YARA Rule
rule CVE_2024_32481_Vyper_Range_Bug {
meta:
description = "Detects Vyper contracts with vulnerable range loop pattern"
author = "Valters IT"
date = "2025-04-10"
cve = "CVE-2024-32481"
strings:
$range_pattern = /for\s+\w+\s+in\s+range\s*\(\s*\w+\s*,\s*\w+\s*\+\s*\d+\s*\)/
$signed_type = /int128|int256/
condition:
$range_pattern and $signed_type
}
Sigma Rule
title: CVE-2024-32481 Vyper Range Loop Denial of Service
id: 7a8b9c0d-1e2f-3a4b-5c6d-7e8f9a0b1c2d
status: experimental
description: Detects transactions that revert due to negative start in Vyper range loops
author: Valters IT
date: 2025-04-10
logsource:
category: blockchain
product: ethereum
detection:
selection:
tx_status: "revert"
tx_input|contains: "range"
condition: selection
falsepositives:
- Legitimate reverts due to other reasons
level: medium
Suricata Rule
alert ip any any -> any any (msg:"CVE-2024-32481 Vyper Range Loop DoS"; content:"|60|"; depth:1; content:"|50|"; within:10; sid:1000001; rev:1;)
Note: This is a placeholder rule. Actual detection would require parsing EVM bytecode for specific opcode patterns.
Remediation & Mitigation
- Immediate: Upgrade Vyper compiler to version 0.4.0b1 or later.
- Recompile: Recompile all smart contracts that use
range(start, start + N)with signed integers. - Code Review: Audit existing Vyper contracts for the vulnerable pattern.
- Workaround: Avoid using signed integers as loop start values in
range()until patched. - Monitoring: Monitor for unexpected transaction reverts that may indicate exploitation attempts.
Valters IT
Securing the Future of Decentralized Technologies