CVE-2023-40015: Vyper Reversed Order Of Side Effects Vulnerability

MODERATE
Advisory Identifier: GHSA-g2xh-c426-v8mf
CVSS 5.3
CWE-670
Published
Advisory Summary

CVE-2023-40015 is a MODERATE (CVSS 5.3) reversed order of side effects vulnerability (CWE-670: Always-Incorrect Control Flow Implementation) affecting Vyper libraries in the PyPI ecosystem. The issue involves reversed order of side effects for some operations. Remediation is available in the latest vendor maintenance releases.

CVE-2023-40015 at a Glance

CVE Identifier CVE-2023-40015
GHSA Identifier GHSA-g2xh-c426-v8mf
Severity MODERATE
CVSS v3.1 Base Score 5.3
CWE Classification CWE-670: Always-Incorrect Control Flow Implementation
Affected Product Vyper
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 5.3

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity Low (I:L)
Availability None (A:N)

How to Fix CVE-2023-40015

To remediate this vulnerability, upgrade all affected Vyper dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

vyper fixed: Latest secure release
pip install vyper>=Latest secure release
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show vyper

How to Check if You Are Affected

To determine whether your Python environment is affected by CVE-2023-40015, inspect your installed packages using pip:

pip show vyper

Analyze the terminal output to locate any version of Vyper in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than the patched release), your application is affected.

Note: The pip show vyper command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-670: Always-Incorrect Control Flow Implementation, where the code contains a control flow path that does not reflect the algorithm that the path is intended to implement, leading to incorrect behavior any time this path is navigated. In Vyper, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact 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` For example: ```Vyper f:uint256 @internal def side_effect() -> uint256: self.f = 12 return 1 @external def foo() -> uint256: return unsafe_add(self.f,self.side_effect()) # returns 13 instead of 1 ``` ```Vyper a:DynArray[uint256, 12] @external def bar() -> bool: self.a = [1,2,3] return len(self.a) == self.a.pop() # return false instead of true ``` ### Patches not yet patched, will address in a future release. tracking in https://github.com/vyperlang/vyper/issues/3604. ### Workarounds When using expressions from the list above, 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. ### References _Are there any links users can visit to find out more?_

CVE-2023-40015 Affected Vyper Versions

1 component(s)
Product / Package Ecosystem Affected Versions Fixed Version
vyper
PyPI
≤ 0.4.2

References

Frequently Asked Questions

What is CVE-2023-40015?
CVE-2023-40015 is a security vulnerability in Vyper involving reversed order of side effects for some operations under CWE-670: Always-Incorrect Control Flow Implementation.
Which Vyper versions are affected?
Affected versions include releases prior to current release patches across affected packages: vyper.
What version fixes CVE-2023-40015?
Upgrading to current release patches (or the latest patched release for your respective branch) resolves the vulnerability.
Is vyper affected?
Yes, vyper is affected in releases prior to Latest secure release. Upgrade your dependency to Latest secure release or later.
What is the CVSS score of CVE-2023-40015?
CVE-2023-40015 has a CVSS v3.1 base score of 5.3 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N.
What CWE is associated with CVE-2023-40015?
CVE-2023-40015 is classified under CWE-670: Always-Incorrect Control Flow Implementation (The code contains a control flow path that does not reflect the algorithm that the path is intended to implement, leading to incorrect behavior any time this path is navigated.).
How can I check PyPI dependencies for CVE-2023-40015?
Run the dependency tree command: 'pip show vyper'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-g2xh-c426-v8mf",
  "modified" : "2025-06-18T17:43:48Z",
  "published" : "2023-09-04T16:39:00Z",
  "aliases" : [ "CVE-2023-40015" ],
  "summary" : "Vyper: reversed order of side effects for some operations",
  "details" : "### Impact\n\nFor the following (probably non-exhaustive) list of expressions, the compiler evaluates the arguments from right to left instead of left to right.\n\n```\n- unsafe_add\n- unsafe_sub\n- unsafe_mul\n- unsafe_div\n- pow_mod256\n- |, &, ^ (bitwise operators)\n- bitwise_or (deprecated)\n- bitwise_and (deprecated)\n- bitwise_xor (deprecated)\n- raw_call\n- <, >, <=, >=, ==, !=\n- in, not in (when lhs and rhs are enums)\n```\n\nThis 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:\n\n- state modifying external call \n- state modifying internal call\n- `raw_call`\n- `pop()` when used on a Dynamic Array stored in the storage\n- `create_minimal_proxy_to`\n- `create_copy_of`\n- `create_from_blueprint`\n\nFor example:\n\n```Vyper\nf:uint256\n\n@internal\ndef side_effect() -> uint256:\n    self.f = 12\n    return 1\n\n@external\ndef foo() -> uint256:\n    return unsafe_add(self.f,self.side_effect()) # returns 13 instead of 1\n```\n\n```Vyper\na:DynArray[uint256, 12]\n@external\ndef bar() -> bool:\n    self.a = [1,2,3]\n    return len(self.a) == self.a.pop() # return false instead of true\n```\n\n### Patches\nnot yet patched, will address in a future release. tracking in https://github.com/vyperlang/vyper/issues/3604.\n\n### Workarounds\n\nWhen using expressions from the list above, 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.\n\n### References\n_Are there any links users can visit to find out more?_",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "vyper"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "last_affected" : "0.4.2"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/vyperlang/vyper/security/advisories/GHSA-g2xh-c426-v8mf"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-40015"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/vyperlang/vyper/issues/3604"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/vyperlang/vyper/issues/4019"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/vyperlang/vyper/pull/4157"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/vyper/PYSEC-2023-167.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/vyperlang/vyper"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-670" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-09-04T16:39:00Z",
    "nvd_published_at" : "2023-09-04T18:15:07Z"
  }
}