CVE-2024-24559: Vyper Vyper Sha3 Codegen Bug Vulnerability

LOW
Advisory Identifier: GHSA-6845-xw22-ffxv
CVSS 3.7
CWE-327
Published
Advisory Summary

CVE-2024-24559 is a LOW (CVSS 3.7) vyper sha3 codegen bug vulnerability (CWE-327: Use of a Broken or Risky Cryptographic Algorithm) affecting Vyper libraries in the PyPI ecosystem. The issue involves vyper sha3 codegen bug. Remediation is available by upgrading affected packages to version 0.4.0.

CVE-2024-24559 at a Glance

CVE Identifier CVE-2024-24559
GHSA Identifier GHSA-6845-xw22-ffxv
Severity LOW
CVSS v3.1 Base Score 3.7
CWE Classification CWE-327: Use of a Broken or Risky Cryptographic Algorithm
Affected Product Vyper
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 3.7

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

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

How to Fix CVE-2024-24559

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: 0.4.0
pip install vyper>=0.4.0
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-2024-24559, 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 0.4.0), 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-327: Use of a Broken or Risky Cryptographic Algorithm, where the product uses a broken or risky cryptographic algorithm or protocol. 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

### Summary There is an error in the stack management when compiling the `IR` for `sha3_64`. Concretely, the `height` variable is miscalculated. The vulnerability can't be triggered without writing the `IR` by hand. That is, it cannot be triggered from regular vyper code, it can only be triggered by using the `fang` binary directly (this binary used to be called `vyper-ir` prior to v0.3.4). ### Details To compile `sha3_64`, the `arg[0]` and `arg[1]` have to be compiled: https://github.com/vyperlang/vyper/blob/c150fc49ee9375a930d177044559b83cb95f7963/vyper/ir/compile_ir.py#L585-L586 As can be seen, after compiling the 0th arg, the `height` variable isn't increased. If new `withargs` are defined in the inner scope, they are manipulated correctly, because both their `height` is off and also the global `height` is off and thus their placement on the stack is computed correctly. `sha3_64` is used for retrieval in mappings. No flow that would cache the `key` was found, the issue shouldn't be possible to trigger when compiling the compiler-generated `IR`. ### PoC Suppose the following hand-written IR: ```lisp (with _loc (with val 1 (with key 2 (sha3_64 val key))) (seq (sstore _loc (with x (sload _loc) (with ans (add x 1) (seq (assert (ge ans x)) ans)))))) ``` after compilation: ``` the generated bytecode: 6001600281806020525f5260405f2090509050805460018101818110610026579050815550005b5f80fd 0000 60 PUSH1 0x01 0002 60 PUSH1 0x02 0004 81 DUP2 0005 80 DUP1 *********** bad code here!!!!!! 0006 60 PUSH1 0x20 0008 52 MSTORE ``` It can be seen that the second `DUP` will dup the item on the top of the stack which is incorrect. ### Patches Patched in https://github.com/vyperlang/vyper/pull/4063. ### Impact Versions v0.2.0-v0.3.10 were evaluated, and access of the variable with the invalid height is not reachable from IR generated by the vyper front-end. Because the issue isn't triggered during normal compilation of vyper code, the impact is considered low.

CVE-2024-24559 Affected Vyper Versions

1 component(s)
Fixed Versions:
0.4.0
Product / Package Ecosystem Affected Versions Fixed Version
vyper
PyPI
< 0.4.0
0.4.0

References

Frequently Asked Questions

What is CVE-2024-24559?
CVE-2024-24559 is a security vulnerability in Vyper involving Vyper sha3 codegen bug under CWE-327: Use of a Broken or Risky Cryptographic Algorithm.
Which Vyper versions are affected?
Affected versions include releases prior to 0.4.0 across affected packages: vyper.
What version fixes CVE-2024-24559?
Upgrading to 0.4.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is vyper affected?
Yes, vyper is affected in releases prior to 0.4.0. Upgrade your dependency to 0.4.0 or later.
What is the CVSS score of CVE-2024-24559?
CVE-2024-24559 has a CVSS v3.1 base score of 3.7 (LOW) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:N.
What CWE is associated with CVE-2024-24559?
CVE-2024-24559 is classified under CWE-327: Use of a Broken or Risky Cryptographic Algorithm (The product uses a broken or risky cryptographic algorithm or protocol.).
How can I check PyPI dependencies for CVE-2024-24559?
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-6845-xw22-ffxv",
  "modified" : "2024-11-22T20:45:28Z",
  "published" : "2024-02-05T19:21:52Z",
  "aliases" : [ "CVE-2024-24559" ],
  "summary" : "Vyper sha3 codegen bug",
  "details" : "### Summary\nThere is an error in the stack management when compiling the `IR` for `sha3_64`. Concretely, the `height` variable is miscalculated.\nThe vulnerability can't be triggered without writing the `IR` by hand. That is, it cannot be triggered from regular vyper code, it can only be triggered by using the `fang` binary directly (this binary used to be called `vyper-ir` prior to v0.3.4).\n\n### Details\nTo compile `sha3_64`, the `arg[0]` and `arg[1]` have to be compiled:\nhttps://github.com/vyperlang/vyper/blob/c150fc49ee9375a930d177044559b83cb95f7963/vyper/ir/compile_ir.py#L585-L586\n\nAs can be seen, after compiling the 0th arg, the `height` variable isn't increased. If new `withargs` are defined in the inner scope, they are manipulated correctly, because both their `height` is off and also the global `height` is off and thus their placement on the stack is computed correctly.\n\n`sha3_64` is used for retrieval in mappings. No flow that would cache the `key` was found, the issue shouldn't be possible to trigger when compiling the compiler-generated `IR`.\n\n### PoC\nSuppose the following hand-written IR:\n```lisp\n(with _loc\n\t(with val 1 \n\t\t(with key 2 \n\t\t\t(sha3_64 val key))) \n\t\t\t\t(seq \n\t\t\t\t\t(sstore _loc \n\t\t\t\t\t(with x (sload _loc) \n\t\t\t\t\t\t(with ans (add x 1) (seq (assert (ge ans x)) ans))))))\n```\nafter compilation:\n```\nthe generated bytecode: 6001600281806020525f5260405f2090509050805460018101818110610026579050815550005b5f80fd\n\n0000    60  PUSH1 0x01\n0002    60  PUSH1 0x02\n0004    81  DUP2\n0005    80  DUP1       *********** bad code here!!!!!!\n0006    60  PUSH1 0x20\n0008    52  MSTORE\n```\n\nIt can be seen that the second `DUP` will dup the item on the top of the stack which is incorrect.\n\n### Patches\nPatched in https://github.com/vyperlang/vyper/pull/4063.\n\n### Impact\nVersions v0.2.0-v0.3.10 were evaluated, and access of the variable with the invalid height is not reachable from IR generated by the vyper front-end. Because the issue isn't triggered during normal compilation of vyper code, the impact is considered low.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "vyper"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.4.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/vyperlang/vyper/security/advisories/GHSA-6845-xw22-ffxv"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-24559"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/vyperlang/vyper/pull/4063"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/vyperlang/vyper/commit/d9f9fdadd81a148cbc68f02dbbbcdc0c92fad652"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/pypa/advisory-database/tree/main/vulns/vyper/PYSEC-2024-147.yaml"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/vyperlang/vyper"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/vyperlang/vyper/blob/c150fc49ee9375a930d177044559b83cb95f7963/vyper/ir/compile_ir.py#L585-L586"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-327" ],
    "severity" : "LOW",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-02-05T19:21:52Z",
    "nvd_published_at" : "2024-02-05T21:15:12Z"
  }
}