{"id":"CVE-2023-42443","aliases":["CVE-2023-42443","GHSA-c647-pxm2-c52w","PYSEC-2023-306"],"related":[],"kind":"vulnerability","state":"published","title":"Vyper vulnerable to memory corruption in certain builtins utilizing `msize`","summary":"Vyper is a Pythonic Smart Contract Language for the Ethereum Virtual Machine (EVM). In version 0.3.9 and prior, under certain conditions, the memory used by the builtins `raw_call`, `create_from_blueprint` and `create_copy_of` can be corrupted. For `raw_call`, the argument buffer of the call can be corrupted, leading to incorrect `calldata` in the sub-context. For `create_from_blueprint` and `create_copy_of`, the buffer for the to-be-deployed bytecode can be corrupted, leading to deploying incorrect bytecode.\n\nEach builtin has conditions that must be fulfilled for the corruption to happen. For `raw_call`, the `data` argument of the builtin must be `msg.data` and the `value` or `gas` passed to the builtin must be some complex expression that results in writing to the memory. For `create_copy_of`, the `value` or `salt` passed to the builtin must be some complex expression that results in writing to the memory. For `create_from_blueprint`, either no constructor parameters should be passed to the builtin or `raw_args` should be set to True, and the `value` or `salt` passed to the builtin must be some complex expression that results in writing to the memory.\n\nAs of time of publication, no patched version exists. The issue is still being investigated, and there might be other cases where the corruption might happen. When the builtin is being called from an `internal` function `F`, the issue is not present provided that the function calling `F` wrote to memory before calling `F`. As a workaround, the complex expressions that are being passed as kwargs to the builtin should be cached in memory prior to the call to the builtin.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Vyper is a Pythonic Smart Contract Language for the Ethereum Virtual Machine (EVM). In version 0.3.9 and prior, under certain conditions, the memory used by the builtins `raw_call`, `create_from_blueprint` and `create_copy_of` can be corrupted. For `raw_call`, the argument buffer of the call can be corrupted, leading to incorrect `calldata` in the sub-context. For `create_from_blueprint` and `create_copy_of`, the buffer for the to-be-deployed bytecode can be corrupted, leading to deploying incorrect bytecode.\n\nEach builtin has conditions that must be fulfilled for the corruption to happen. For `raw_call`, the `data` argument of the builtin must be `msg.data` and the `value` or `gas` passed to the builtin must be some complex expression that results in writing to the memory. For `create_copy_of`, the `value` or `salt` passed to the builtin must be some complex expression that results in writing to the memory. For `create_from_blueprint`, either no constructor parameters should be passed to the builtin or `raw_args` should be set to True, and the `value` or `salt` passed to the builtin must be some complex expression that results in writing to the memory.\n\nAs of time of publication, no patched version exists. The issue is still being investigated, and there might be other cases where the corruption might happen. When the builtin is being called from an `internal` function `F`, the issue is not present provided that the function calling `F` wrote to memory before calling `F`. As a workaround, the complex expressions that are being passed as kwargs to the builtin should be cached in memory prior to the call to the builtin.","source":"cvelist"},{"lang":"en","text":"### Impact\nIn certain conditions, the memory used by the builtins `raw_call`, `create_from_blueprint` and `create_copy_of` can be corrupted.\n\n- For `raw_call`, the argument buffer of the call can be corrupted, leading to incorrect `calldata` in the sub-context.\n- For  `create_from_blueprint` and `create_copy_of`, the buffer for the to-be-deployed bytecode can be corrupted, leading to deploying incorrect bytecode.\n\nBelow are the conditions that must be fulfilled for the corruption to happen for each builtin:\n\n#### `raw_call`\n- memory is not fully initialized, ex. all parameters to an external function live in calldata\nand\n- The `data` argument of the builtin is `msg.data`.\nand\n- The `to`, `value` or `gas` passed to the builtin is some complex expression that results in writing to uninitialized memory (e.g. calling an internal function)\n\n#### `create_copy_of`\n- memory is not fully initialized, ex. all parameters to an external function live in calldata\nand\n- The `value` or `salt` passed to the builtin is some complex expression that results in writing to  uninitialized memory (e.g. calling an internal function)\n\n#### `create_from_blueprint`\n- memory is not fully initialized, ex. all parameters to an external function live in calldata\nand\n- Either no constructor parameters are passed to the builtin or `raw_args` is set to True.\nand\n- The `value` or `salt` passed to the builtin is some complex expression that results in writing to uninitialized memory (e.g. calling an internal function)\n\nNote: When the builtin is being called from an `internal` function `f` from a function `g`, the issue is not present provided that `g` has written to memory before calling `f`.\n \n#### Examples\n\n\n##### `raw_call`\n\nIn the following contract, calling `bar(1,1)` will return:\n\n``` Python\nae42e95100000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000001\n```\ninstead of:\n``` Python\nae42e95100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001\n```\n\n```Python\nidentity: constant(address) = 0x0000000000000000000000000000000000000004\n\n@external\ndef foo():\n    pass\n\n@internal\n@view\ndef get_address()->address:\n    a:uint256 = max_value(uint256) # 0xfff...fff\n    return identity\n@external\ndef bar(f:uint256, u:uint256) -> Bytes[100]:\n    a: Bytes[100] = raw_call(self.get_address(), msg.data, max_outsize=100)\n    return a\n```\n\n##### `create_copy_of`\nIn the following contract, after calling `test()`, the code deployed at `self.created_address` does not match the bytecode at `target`.\n\n``` Vyper\ncreated_address: public(address)\n\n@external\ndef test(target: address) -> address:\n    # The expression in salt= is complex and will require to store to memory\n    self.created_address = create_copy_of(target, salt = keccak256(_abi_encode(target)))\n    return self.created_address\n```\n\n##### `create_from_blueprint`\nIn the following contract, after calling `test()`, the init bytecode used to create the contract deployed at the address `self.created_address` will not match the blueprint bytecode stored at `target`.\n\n``` Vyper\ncreated_address: public(address)\n\nsalt: constant(bytes32) = keccak256(\"kebab\")\n\n@external\n@payable\ndef test(target: address):\n    # The expression in salt= is complex and will require to store to memory\n    self.created_address = create_from_blueprint(target, code_offset=0, salt=keccak256(_abi_encode(target)))\n```\n### Patches\nissue tracking in https://github.com/vyperlang/vyper/issues/3609, patched in #3610 \n\n### Workarounds\n\nThe complex expressions that are being passed as kwargs to the builtin should be cached in memory prior to the call to the builtin. For the last example above, it would be:\n\n``` Vyper\ncreated_address: public(address)\n\nsalt: constant(bytes32) = keccak256(\"kebab\")\n\n@external\n@payable\ndef test(target: address):\n    salt: bytes32 = keccak256(_abi_encode(target))\n    self.created_address = create_from_blueprint(target, code_offset=0, salt=salt)\n```\n### References\n_Are there any links users can visit to find out more?_","format":"markdown","source":"ghsa"},{"lang":"es","text":"Vyper es un Lenguaje de Contrato Inteligente Pitónico para la Máquina Virtual Ethereum (EVM). En la versión 0.3.9 y anteriores, bajo ciertas condiciones, la memoria utilizada por las funciones integradas `raw_call`, `create_from_blueprint` y `create_copy_of` puede estar dañada. Para `raw_call`, el búfer de argumentos de la llamada puede estar dañado, lo que genera `calldata` incorrectos en el subcontexto. Para `create_from_blueprint` y `create_copy_of`, el búfer para el código de bytes que se va a implementar puede estar dañado, lo que lleva a implementar un código de bytes incorrecto. Cada elemento incorporado tiene condiciones que deben cumplirse para que se produzca la corrupción. Para `raw_call`, el argumento `data` del incorporado debe ser `msg.data` y el `valor` o `gas` pasado al incorporado debe ser alguna expresión compleja que dé como resultado la escritura en la memoria. Para `create_copy_of`, el `valor` o `salt` pasado al incorporado debe ser alguna expresión compleja que dé como resultado la escritura en la memoria. Para `create_from_blueprint`, no se deben pasar parámetros de constructor al incorporado o `raw_args` debe establecerse en True, y el `valor` o `salt` pasado al incorporado debe ser alguna expresión compleja que dé como resultado la escritura en la memoria . Al momento de la publicación, no existe ninguna versión parcheada. El problema aún se está investigando y es posible que haya otros casos en los que se produzca corrupción. Cuando se llama a la función incorporada desde una función \"interna\" \"F\", el problema no está presente siempre que la función que llama a \"F\" haya escrito en la memoria antes de llamar a \"F\". Como workaround, las expresiones complejas que se pasan como kwargs al incorporado deben almacenarse en caché en la memoria antes de la llamada al incorporado.","source":"nvd"}],"published":"2023-09-18T20:52:33.664Z","modified":"2026-06-17T06:23:50.420Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H","score":8.1,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H","score":8.1,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H","score":8.1,"rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H","score":8.1,"rating":"HIGH"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H","score":8.1,"rating":"HIGH"}],"cwes":["CWE-787"],"affected":[{"ranges":[{"version":"<= 0.3.9","status":"affected"}],"vendor":"vyperlang","product":"vyper","source":"cvelist"},{"ranges":[{"type":"custom","introduced":"0","lastAffected":"0.3.9","status":"affected"}],"vendor":"vyperlang","product":"vyper","cpe":"cpe:2.3:a:vyperlang:vyper:*:*:*:*:*:python:*:*","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0.3.4","status":"affected","fixed":"0.3.10"}],"ecosystem":"PyPI","package":"vyper","purl":"pkg:pypi/vyper","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"0.3.10"}],"vendor":"vyperlang","product":"vyper","cpe":"cpe:2.3:a:vyperlang:vyper:*:*:*:*:*:python:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"0.3.10"}],"ecosystem":"PyPI","package":"vyper","purl":"pkg:pypi/vyper","source":"pysec"}],"references":[{"url":"https://github.com/vyperlang/vyper/security/advisories/GHSA-c647-pxm2-c52w","tags":["advisory","exploit","patch","vendor-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/vyperlang/vyper/issues/3609","tags":["advisory","issue-tracking","vendor-advisory","web","x-refsource-misc","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2023-42443","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/vyperlang/vyper/pull/3610","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/vyperlang/vyper/commit/79303fc4fcba06994ee5c6a7baef57bdb185006c","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/vyper/PYSEC-2023-306.yaml","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/vyperlang/vyper","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"none","automatable":"no","technicalImpact":"total","date":"2024-09-24T18:49:35.863Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2023-42443","url":"https://www.cve.org/CVERecord?id=CVE-2023-42443","licence":"CVE Terms of Use","modified":"2024-09-24T18:57:14.382Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-c647-pxm2-c52w","url":"https://github.com/advisories/GHSA-c647-pxm2-c52w","licence":"CC-BY-4.0","modified":"2024-11-22T20:45:54.793Z"},{"source":"nvd","name":"NVD","id":"CVE-2023-42443","url":"https://nvd.nist.gov/vuln/detail/CVE-2023-42443","licence":"Public domain","modified":"2026-06-17T06:23:50.420Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2023-306","url":"https://osv.dev/vulnerability/PYSEC-2023-306","licence":"CC-BY-4.0","modified":"2024-11-21T14:57:23.838Z"}],"updatedAt":"2026-11-25T22:58:27.979Z","epss":{"score":0.00832,"percentile":0.58722,"date":"2026-12-01T12:00:22.000Z"}}