{"id":1338,"cve":"CVE-2025-47285","cve_url":"https:\/\/www.cvedetails.com\/cve\/CVE-2025-47285\/","cwe":"CWE-691 Insufficient Control Flow Management","cwe_number":691,"cwe_url":"https:\/\/cwe.mitre.org\/data\/definitions\/691","cvss_score":2.9,"published":"2025-05-15","owasp":"A09 Security Logging and Monitoring Failures","odc":"Algorithm","cdc":"Incorrect Functionality","category":"Design Defects","subcategory":"Vulnerable and Outdated Components","scope":"Remote","impact":"Denial of Service (DoS)","summary":"Vyper's `concat()` skips side effects with zero-length arguments. Fixed in 0.4.2.","permalink":"https:\/\/netpack.pt\/vaitp\/vulnerability\/CVE-2025-47285\/","description":"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.","solution":"Upgrade to Vyper version 0.4.2 or later.","affected_component":"Vyper","fixed_by_upgrading":true,"vulnerable_code":"class VyperContract:  #Simulating a Vyper contract's behavior\n\n    def __init__(self):\n        self.side_effect_counter = 0\n\n    def do_some_side_effect(self):\n        self.side_effect_counter += 1\n        print(f\"Side effect triggered, counter: {self.side_effect_counter}\")\n        return True # or False, doesn't matter for the example's purpose\n\n    def concat(self, arg1, arg2):\n        \"\"\"\n        Illustrative concat function that *might* have skipped\n        side effects in certain zero-length argument scenarios\n        (BEFORE the fix).\n        \"\"\"\n        result = b\"\" #default empty bytestring\n\n        if len(arg1) > 0: #fastpath optimisation that would be removed by the fix\n            result += arg1\n        else:\n            print(\"Skipping evaluation of arg1 due to zero length (simulated)\")\n            #DO NOT call self.do_some_side_effect() Here, this means the side_effect never happened\n\n        if len(arg2) > 0: #fastpath optimisation that would be removed by the fix\n            result += arg2\n        else:\n            print(\"Skipping evaluation of arg2 due to zero length (simulated)\")\n            #DO NOT call self.do_some_side_effect() Here, this means the side_effect never happened\n\n        return result\n\n\n# Example Usage (illustrative)\ncontract = VyperContract()\n\n# Simulate a scenario where a zero-length bytestring *might* have been\n# constructed with a side effect using a ternary operator (as described in the CVE).\n\narg1 = b\"\" if contract.do_some_side_effect() else b\"\"   #Empty bytestring with a side effect.\narg2 = b\"hello\"\n\nprint(\"Calling concat() with potentially skipped side effect...\")\nresult = contract.concat(arg1, arg2)\nprint(f\"Result: {result}\")\nprint(f\"Side effect counter: {contract.side_effect_counter}\")  #Expected 0 before the fix.\n\n\n#Illustrative of arg2 also potentially triggering this issue\ncontract2 = VyperContract()\n\narg3 = b\"world\"\narg4 = b\"\" if contract2.do_some_side_effect() else b\"\"  #Empty bytestring with a side effect.\n\n\nprint(\"Calling concat() with potentially skipped side effect...\")\nresult2 = contract2.concat(arg3, arg4)\nprint(f\"Result: {result2}\")\nprint(f\"Side effect counter: {contract2.side_effect_counter}\")  #Expected 0 before the fix.","patched_code":"def concat_fixed(*args):\n    \"\"\"\n    Fixed version of concat() that ensures all arguments are evaluated,\n    regardless of their length, to prevent skipping side effects.\n    \"\"\"\n    result = b\"\"\n    for arg in args:\n        # Force evaluation of the argument, even if it's empty.  This is the key fix.\n        # We create a dummy variable and assign the result of the expression to it.\n        # This guarantees the expression is executed.\n        _ = arg  # Dummy assignment to force evaluation\n\n        if isinstance(arg, bytes):\n            result += arg\n        else:\n            raise TypeError(\"Arguments must be bytes\")\n    return result\n\n# Example usage to demonstrate the fix\nside_effect_occurred = False\n\ndef do_some_side_effect():\n    \"\"\"Simulates a function with side effects.\"\"\"\n    global side_effect_occurred\n    side_effect_occurred = True\n    return True\n\ndef create_empty_bytes_with_side_effect():\n    \"\"\"Creates an empty bytes object with a side effect using a ternary operator.\"\"\"\n    if do_some_side_effect():\n        return b\"\"\n    else:\n        return b\"\"\n\n\n# Demonstrate the vulnerability is fixed: side effect *will* occur\nside_effect_occurred = False\nresult = concat_fixed(create_empty_bytes_with_side_effect(), b\"hello\")\nprint(f\"Result: {result}\")\nprint(f\"Side effect occurred: {side_effect_occurred}\")  # Expected: True","payload_needed":true,"payload":"```python\nb\"\" if self.do_some_side_effect() else b\"\"\n```","payload_status":"available","published_fix":[{"repository":"vyperlang\/vyper","commit_url":"https:\/\/github.com\/vyperlang\/vyper\/pull\/4644","commit_subject":"fix[codegen]: fix removal of side effects in concat","units":[{"file":"vyper\/builtins\/functions.py","function":"Concat.build_IR"},{"file":"vyper\/codegen\/expr.py","function":"Expr._make_bytelike"},{"file":"vyper\/codegen\/ir_node.py","function":null},{"file":"vyper\/codegen\/ir_node.py","function":"IRnode.is_empty_intrinsic"}]}],"references":null}