CVE-2024-24561
Executive Summary
CVE-2024-24561 is a critical integer overflow vulnerability in the Vyper smart contract language (versions 0.3.10 and earlier). The flaw exists in the bounds checking logic for slice operations when non-literal arguments are used for start or length. An attacker can exploit this to cause an integer overflow, bypassing the intended bounds check and enabling out-of-bounds (OOB) access to storage, memory, or calldata. This can lead to arbitrary data manipulation, contract state corruption, and potential total compromise of the smart contract. The CVSS score is 9.8 (Critical), and no official patch has been released at the time of analysis.
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). It is distributed via PyPI (vyper package) and GitHub. The vulnerability affects all versions up to and including 0.3.10. Since Vyper is used to compile smart contracts, any contract compiled with a vulnerable version is at risk. Developers must immediately upgrade to a patched version (once available) or apply manual mitigations. The supply chain risk is high because the vulnerability is in the compiler itself, affecting all downstream contracts.
CVSS Breakdown & Threat Level
- CVSS Score: 9.8 (Critical)
- Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
- Attack Vector: Network
- Attack Complexity: Low
- Privileges Required: None
- User Interaction: None
- Scope: Unchanged
- Confidentiality Impact: High
- Integrity Impact: High
- Availability Impact: High
The vulnerability is trivially exploitable by any attacker who can interact with a vulnerable smart contract. No authentication or user interaction is required. Successful exploitation leads to complete compromise of the contract's data and logic.
Deep Dive & Mechanics
The vulnerability resides in the Vyper compiler's handling of slice operations on arrays (e.g., arr[start:start+length]). When start or length are non-literal (i.e., variables or expressions), the compiler performs a bounds check: start + length <= len(arr). However, if start + length overflows (e.g., start = 2^256 - 1 and length = 1), the sum wraps around to a small value, bypassing the check. This allows an attacker to specify a slice that extends beyond the array bounds, enabling OOB read/write.
The root cause is the use of unchecked arithmetic in the bounds check. The EVM's native arithmetic is modulo 2^256, so overflow is silent. The Vyper compiler did not use safe math (e.g., checked_add) for this specific check.
Attack Scenario:
- Deploy a contract with a vulnerable slice operation.
- Call a function that uses a non-literal
startorlengthparameter. - Provide values that cause
start + lengthto overflow (e.g.,start = 2^256 - 10,length = 20). - The bounds check passes (since
2^256 - 10 + 20wraps to10), but the actual slice accesses memory/storage beyond the array. - The attacker can read or write arbitrary storage slots, memory, or calldata.
Vulnerable vs. Patched Code
Vulnerable Code (Vyper 0.3.10):
@external
def vulnerable_slice(arr: uint256[10], start: uint256, length: uint256) -> uint256[10]:
# Bounds check: start + length <= 10
assert start + length <= 10, "out of bounds"
# Slice operation (simplified)
return arr[start:start+length]
Patched Code (Hypothetical):
@external
def patched_slice(arr: uint256[10], start: uint256, length: uint256) -> uint256[10]:
# Safe bounds check using checked arithmetic
assert start <= 10, "start out of bounds"
assert length <= 10 - start, "length out of bounds"
# Slice operation
return arr[start:start+length]
The patched version checks start and length separately, ensuring no overflow can occur. Alternatively, the compiler could use checked_add from Vyper's built-in safe math.
Exploitation & Lab Setup
Red Team (Exploitation)
Prerequisites:
- Vyper compiler 0.3.10 or earlier
- Ethereum development environment (e.g., Hardhat, Brownie)
- A vulnerable smart contract
Exploit Contract (Vyper):
# Exploit contract
@external
def exploit(target: address):
# Call vulnerable function with overflow values
# start = 2^256 - 10, length = 20
# This passes the bounds check but reads OOB
result: uint256[10] = target.vulnerable_slice([0,0,0,0,0,0,0,0,0,0], 2**256 - 10, 20)
# result now contains data from arbitrary storage
Exploit Steps:
- Deploy the vulnerable contract.
- Deploy the exploit contract.
- Call
exploit()with the target address. - The slice operation will read OOB data, potentially leaking sensitive information or overwriting critical storage.
Expected Outcome: The attacker gains unauthorized read/write access to the contract's storage, memory, or calldata.
Blue Team (Detection & Defense)
Detection:
- Monitor for transactions with unusually large
startorlengthparameters in slice operations. - Use static analysis tools to detect unsafe arithmetic in Vyper contracts.
- Deploy runtime monitoring that checks for OOB access patterns.
Defense:
- Immediately upgrade to a patched version of Vyper (once available).
- Apply manual safe math checks in all slice operations.
- Use Vyper's built-in
checked_addandchecked_subfunctions. - Limit the use of non-literal slice parameters in external functions.
Indicators of Compromise (IOCs)
- Transaction Patterns: Transactions with
startorlengthvalues near2^256 - 1in slice operations. - Storage Corruption: Unexpected changes to storage slots that should be immutable.
- Memory Leaks: Contracts returning data that should not be accessible (e.g., private variables).
- Compiler Version: Contracts compiled with Vyper <= 0.3.10.
Detection Engineering
YARA Rule
rule CVE_2024_24561_Vyper_Slice_Overflow {
meta:
description = "Detects Vyper bytecode with vulnerable slice bounds check"
author = "Valters IT"
date = "2024-01-01"
cve = "CVE-2024-24561"
strings:
$opcode1 = { 60 0A } // PUSH1 10 (array length)
$opcode2 = { 01 } // ADD (start + length)
$opcode3 = { 10 } // LT (comparison)
$opcode4 = { 15 } // ISZERO (assert)
condition:
all of them
}
Sigma Rule
title: CVE-2024-24561 Vyper Slice Overflow Detection
id: 8a9b7c6d-5e4f-3a2b-1c0d-9e8f7a6b5c4d
status: experimental
description: Detects transactions exploiting Vyper slice integer overflow
author: Valters IT
date: 2024-01-01
logsource:
category: ethereum
product: blockchain
detection:
selection:
- "function": "vulnerable_slice"
- "params.start": "> 2^255"
- "params.length": "> 2^255"
condition: selection
falsepositives:
- Legitimate use of large arrays (unlikely)
level: critical
Suricata Rule
alert ip any any -> any any (
msg:"CVE-2024-24561 Vyper Slice Overflow Exploit";
content:"|60 0A 01 10 15|";
sid:1000001;
rev:1;
reference:cve,2024-24561;
classtype:attempted-admin;
)
Remediation & Mitigation
Immediate Actions:
- Upgrade Vyper Compiler: Once a patched version is released (e.g., 0.3.11 or later), upgrade immediately.
- Manual Code Fix: For existing contracts, replace unsafe slice bounds checks with safe arithmetic:
assert start <= len(arr) assert length <= len(arr) - start - Use Safe Math: Leverage Vyper's built-in
checked_addandchecked_subfor all arithmetic in bounds checks.
Long-Term Measures:
- Implement static analysis in CI/CD pipelines to detect unsafe arithmetic.
- Conduct regular security audits of smart contracts.
- Monitor for new Vyper releases and apply patches promptly.
Workarounds:
- Avoid using non-literal arguments for
startandlengthin slice operations. - Restrict external functions that accept slice parameters to trusted callers only.
Valters IT
DevSecOps & Cyber Threat Intelligence