CVE-2023-40015
Vyper compiler's right-to-left evaluation causes side effect vulnerabilities
- CVSS 5.3
- CWE-670 Always-Incorrect Control Flow Implementation
- Input Validation and Sanitization
- Remote
Vyper is a Pythonic Smart Contract Language. For the following (probably non-exhaustive) list of expressions, the compiler evaluates the arguments from right to left instead of left to right. `unsafe_add, unsafe_sub, unsafe_mul, unsafe_div, pow_mod256, |, &, ^ (bitwise operators), bitwise_or (deprecated), bitwise_and (deprecated), bitwise_xor (deprecated), raw_call, <, >, <=, >=, ==, !=, in, not in (when lhs and rhs are enums)`. This behaviour becomes a problem when the evaluation of one of the arguments produces side effects that other arguments depend on. The following expressions can produce side-effect: state modifying external call , state modifying internal call, `raw_call`, `pop()` when used on a Dynamic Array stored in the storage, `create_minimal_proxy_to`, `create_copy_of`, `create_from_blueprint`. This issue has not yet been patched. Users are advised to make sure that the arguments of the expression do not produce side effects or, if one does, that no other argument is dependent on those side effects.
- CVSS base score
- 5.3
- Published
- 2023-09-04
- OWASP
- A04 Insecure Design
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- Vyper
Solution
No known patch (05-11-2024)
Vulnerable code sample
# Example demonstrating the vulnerability CVE-2023-40015 in Vyper-like behavior
# Simulated state
state = {"value": 0}
def side_effect_function():
state["value"] += 1
return state["value"]
# Vulnerable usage
result = unsafe_add(5, side_effect_function()) # This can lead to unexpected behavior
print(result) # The result may not be as expected due to right-to-left evaluationPatched code sample
# Example demonstrating the vulnerability CVE-2023-40015 in Vyper-like behavior
# Simulated state
state = {"value": 0}
def side_effect_function():
state["value"] += 1
return state["value"]
def safe_expression(arg1, arg2):
# Ensure no side effects are present in the arguments
return arg1 + arg2
# Vulnerable usage
result = unsafe_add(side_effect_function(), 5) # This can lead to unexpected behavior
# Fixed usage
# Avoid using side-effect producing functions directly in expressions
side_effect_result = side_effect_function()
result = safe_expression(side_effect_result, 5) # Safe as side effects are evaluated firstPublished 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]: panic on potential eval order issue for some builtins (vyperlang/vyper)
vyper/builtins/functions.py,vyper/builtins/functions.py · Extract32.build_IR,vyper/builtins/functions.py · Slice.build_IR
Cite this entry
@misc{vaitp:cve202340015,
title = {{Vyper compiler's right-to-left evaluation causes side effect vulnerabilities}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2023},
note = {VAITP Python Vulnerability Dataset, entry CVE-2023-40015},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2023-40015/}}
}
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 ::
