CVE-2025-47285
Vyper's `concat()` skips side effects with zero-length arguments. Fixed in 0.4.2.
- CVSS 2.9
- CWE-691 Insufficient Control Flow Management
- Design Defects
- Remote
Vyper is the Pythonic Programming Language for the Ethereum Virtual Machine. In versions up to and including 0.4.2rc1, `concat()` may skip evaluation of side effects when the length of an argument is zero. This is due to a fastpath in the implementation which skips evaluation of argument expressions when their length is zero. In practice, it would be very unusual in user code to construct zero-length bytestrings using an expression with side-effects, since zero-length bytestrings are typically constructed with the empty literal `b""`; the only way to construct an empty bytestring which has side effects would be with the ternary operator introduced in v0.3.8, e.g. `b"" if self.do_some_side_effect() else b""`. The fix is available in pull request 4644 and expected to be part of the 0.4.2 release. As a workaround, don't have side effects in expressions which construct zero-length bytestrings.
- CVSS base score
- 2.9
- Published
- 2025-05-15
- OWASP
- A09 Security Logging and Monitoring Failures
- Orthogonal defect classification
- Algorithm
- Code defect classification
- Incorrect Functionality
- Category
- Design Defects
- Subcategory
- Vulnerable and Outdated Components
- Accessibility scope
- Remote
- Impact
- Denial of Service (DoS)
- Affected component
- Vyper
- Fixed by upgrading
- Yes
Solution
Upgrade to Vyper version 0.4.2 or later.
Vulnerable code sample
class VyperContract: #Simulating a Vyper contract's behavior
def __init__(self):
self.side_effect_counter = 0
def do_some_side_effect(self):
self.side_effect_counter += 1
print(f"Side effect triggered, counter: {self.side_effect_counter}")
return True # or False, doesn't matter for the example's purpose
def concat(self, arg1, arg2):
"""
Illustrative concat function that *might* have skipped
side effects in certain zero-length argument scenarios
(BEFORE the fix).
"""
result = b"" #default empty bytestring
if len(arg1) > 0: #fastpath optimisation that would be removed by the fix
result += arg1
else:
print("Skipping evaluation of arg1 due to zero length (simulated)")
#DO NOT call self.do_some_side_effect() Here, this means the side_effect never happened
if len(arg2) > 0: #fastpath optimisation that would be removed by the fix
result += arg2
else:
print("Skipping evaluation of arg2 due to zero length (simulated)")
#DO NOT call self.do_some_side_effect() Here, this means the side_effect never happened
return result
# Example Usage (illustrative)
contract = VyperContract()
# Simulate a scenario where a zero-length bytestring *might* have been
# constructed with a side effect using a ternary operator (as described in the CVE).
arg1 = b"" if contract.do_some_side_effect() else b"" #Empty bytestring with a side effect.
arg2 = b"hello"
print("Calling concat() with potentially skipped side effect...")
result = contract.concat(arg1, arg2)
print(f"Result: {result}")
print(f"Side effect counter: {contract.side_effect_counter}") #Expected 0 before the fix.
#Illustrative of arg2 also potentially triggering this issue
contract2 = VyperContract()
arg3 = b"world"
arg4 = b"" if contract2.do_some_side_effect() else b"" #Empty bytestring with a side effect.
print("Calling concat() with potentially skipped side effect...")
result2 = contract2.concat(arg3, arg4)
print(f"Result: {result2}")
print(f"Side effect counter: {contract2.side_effect_counter}") #Expected 0 before the fix.Patched code sample
def concat_fixed(*args):
"""
Fixed version of concat() that ensures all arguments are evaluated,
regardless of their length, to prevent skipping side effects.
"""
result = b""
for arg in args:
# Force evaluation of the argument, even if it's empty. This is the key fix.
# We create a dummy variable and assign the result of the expression to it.
# This guarantees the expression is executed.
_ = arg # Dummy assignment to force evaluation
if isinstance(arg, bytes):
result += arg
else:
raise TypeError("Arguments must be bytes")
return result
# Example usage to demonstrate the fix
side_effect_occurred = False
def do_some_side_effect():
"""Simulates a function with side effects."""
global side_effect_occurred
side_effect_occurred = True
return True
def create_empty_bytes_with_side_effect():
"""Creates an empty bytes object with a side effect using a ternary operator."""
if do_some_side_effect():
return b""
else:
return b""
# Demonstrate the vulnerability is fixed: side effect *will* occur
side_effect_occurred = False
result = concat_fixed(create_empty_bytes_with_side_effect(), b"hello")
print(f"Result: {result}")
print(f"Side effect occurred: {side_effect_occurred}") # Expected: TruePublished fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- fix[codegen]: fix removal of side effects in concat (vyperlang/vyper)
vyper/builtins/functions.py · Concat.build_IR,vyper/codegen/expr.py · Expr._make_bytelike,vyper/codegen/ir_node.py,vyper/codegen/ir_node.py · IRnode.is_empty_intrinsic
Payload
b"" if self.do_some_side_effect() else b""
Cite this entry
@misc{vaitp:cve202547285,
title = {{Vyper's `concat()` skips side effects with zero-length arguments. Fixed in 0.4.2.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2025},
note = {VAITP Python Vulnerability Dataset, entry CVE-2025-47285},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2025-47285/}}
}
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 ::
