{"id":"CVE-2024-24560","aliases":["CVE-2024-24560","GHSA-gp3w-2v2m-p686","PYSEC-2024-148"],"related":[],"kind":"vulnerability","state":"published","title":"Vyper external calls can overflow return data to return input buffer","summary":"Vyper is a Pythonic Smart Contract Language for the Ethereum Virtual Machine. When calls to external contracts are made, we write the input buffer starting at byte 28, and allocate the return buffer to start at byte 0 (overlapping with the input buffer). When checking RETURNDATASIZE for dynamic types, the size is compared only to the minimum allowed size for that type, and not to the returned value's length. As a result, malformed return data can cause the contract to mistake data from the input buffer for returndata.  When the called contract returns invalid ABIv2 encoded data, the calling contract can read different invalid data (from the dirty buffer) than the called contract returned.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Vyper is a Pythonic Smart Contract Language for the Ethereum Virtual Machine. When calls to external contracts are made, we write the input buffer starting at byte 28, and allocate the return buffer to start at byte 0 (overlapping with the input buffer). When checking RETURNDATASIZE for dynamic types, the size is compared only to the minimum allowed size for that type, and not to the returned value's length. As a result, malformed return data can cause the contract to mistake data from the input buffer for returndata.  When the called contract returns invalid ABIv2 encoded data, the calling contract can read different invalid data (from the dirty buffer) than the called contract returned.","source":"cvelist"},{"lang":"en","text":"## Summary\n\nWhen calls to external contracts are made, we write the input buffer starting at byte 28, and allocate the return buffer to start at byte 0 (overlapping with the input buffer). When checking `RETURNDATASIZE` for dynamic types, the size is compared only to the minimum allowed size for that type, and not to the returned value's `length`. As a result, malformed return data can cause the contract to mistake data from the input buffer for returndata.\n\nThis advisory is given a severity of \"Low\" because when the called contract returns invalid ABIv2 encoded data, the calling contract can read different invalid data (from the dirty buffer) than the called contract returned.\n\n## Details\n\nWhen arguments are packed for an external call, we create a buffer of size `max(args, return_data) + 32`. The input buffer is placed in this buffer (starting at byte 28), and the return buffer is allocated to start at byte 0. The assumption is that we can reuse the memory becase we will not be able to read past `RETURNDATASIZE`.\n\n```python\nif fn_type.return_type is not None:\n    return_abi_t = calculate_type_for_external_return(fn_type.return_type).abi_type\n\n    # we use the same buffer for args and returndata,\n    # so allocate enough space here for the returndata too.\n    buflen = max(args_abi_t.size_bound(), return_abi_t.size_bound())\nelse:\n    buflen = args_abi_t.size_bound()\n\nbuflen += 32  # padding for the method id\n```\n\nWhen data is returned, we unpack the return data by starting at byte 0. We check that `RETURNDATASIZE` is greater than the minimum allowed for the returned type:\n```python\nif not call_kwargs.skip_contract_check:\n    assertion = IRnode.from_list(\n        [\"assert\", [\"ge\", \"returndatasize\", min_return_size]],\n        error_msg=\"returndatasize too small\",\n    )\n    unpacker.append(assertion)\n```\n\nThis check ensures that any dynamic types returned will have a size of at least 64. However, it does not verify that `RETURNDATASIZE` is as large as the `length` word of the dynamic type. \n\nAs a result, if a contract expects a dynamic type to be returned, and the part of the return data that is read as `length` includes a size that is larger than the actual `RETURNDATASIZE`, the return data read from the buffer will overrun the actual return data size and read from the input buffer.\n\n## Proof of Concept\n\nThis contract calls an external contract with two arguments. As the call is made, the buffer includes:\n- byte 28: method_id\n- byte 32: first argument (0)\n- byte 64: second argument (hash)\n\nThe return data buffer begins at byte 0, and will return the returned bytestring, up to a maximum length of 96 bytes.\n\n```python\ninterface Zero:\n    def sneaky(a: uint256, b: bytes32) -> Bytes[96]: view\n\n@external\ndef test_sneaky(z: address) -> Bytes[96]:\n    return Zero(z).sneaky(0, keccak256(\"oops\"))\n```\nOn the other side, imagine a simple contract that does not, in fact, return a bytestring, but instead returns two uint256s. I've implemented it in Solidity for ease of use with Foundry:\n```solidity\nfunction sneaky(uint a, bytes32 b) external pure returns (uint, uint) {\n    return (32, 32);\n}\n```\n\nThe return data will be parsed as a bytestring. The first 32 will point us to byte 32 to read the length. The second 32 will be perceived as the length. It will then read the next 32 bytes from the return data buffer, even though those weren't a part of the return data.\n\nSince these bytes will come from byte 64, we can see above that the hash was placed there in the input buffer.\n\nIf we run the following Foundry test, we can see that this does in fact happen:\n```solidity\nfunction test__sneakyZeroReturn() public {\n    ZeroReturn z = new ZeroReturn();\n    c = SuperContract(deployer.deploy(\"src/loose/\", \"ret_overflow\", \"\"));\n    console.logBytes(c.test_sneaky(address(z)));\n}\n```\n\n```md\nLogs:\n  0xd54c03ccbc84dd6002c98c6df5a828e42272fc54b512ca20694392ca89c4d2c6\n```\n\n### Patches\nPatched in https://github.com/vyperlang/vyper/pull/3925, https://github.com/vyperlang/vyper/pull/4091, https://github.com/vyperlang/vyper/pull/4144, https://github.com/vyperlang/vyper/pull/4060.\n\n## Impact\n\nMalicious or mistaken contracts returning the malformed data can result in overrunning the returned data and reading return data from the input buffer.","format":"markdown","source":"ghsa"},{"lang":"es","text":"Vyper es un lenguaje de contrato inteligente pitónico para la máquina virtual Ethereum. Cuando se realizan llamadas a contratos externos, escribimos el búfer de entrada comenzando en el byte 28 y asignamos el búfer de retorno para que comience en el byte 0 (superponiéndose con el búfer de entrada). Al verificar RETURNDATASIZE para tipos dinámicos, el tamaño se compara solo con el tamaño mínimo permitido para ese tipo y no con la longitud del valor devuelto. Como resultado, los datos de devolución con formato incorrecto pueden hacer que el contrato confunda los datos del búfer de entrada con los datos de devolución. Cuando el contrato llamado devuelve datos codificados ABIv2 no válidos, el contrato que llama puede leer datos no válidos diferentes (del búfer sucio) que los devueltos por el contrato llamado.","source":"nvd"}],"published":"2024-02-02T16:19:45.822Z","modified":"2026-09-10T03:50:05.649Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:N","score":3.7,"rating":"LOW"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:N","score":3.7,"rating":"LOW"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:N/A:N","score":3.7,"rating":"LOW"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N","score":5.3,"rating":"MEDIUM"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N","score":5.3,"rating":"MEDIUM"}],"cwes":["CWE-119"],"affected":[{"ranges":[{"version":"<= 0.3.10","status":"affected"}],"vendor":"vyperlang","product":"vyper","source":"cvelist"},{"ranges":[{"type":"custom","introduced":"0","lastAffected":"0.3.10","status":"affected"}],"vendor":"vyperlang","product":"vyper","cpe":"cpe:2.3:a:vyperlang:vyper:*:*:*:*:*:python:*:*","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"0.4.0"}],"ecosystem":"PyPI","package":"vyper","purl":"pkg:pypi/vyper","source":"ghsa"},{"ranges":[{"status":"affected","lastAffected":"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.4.0b1"}],"ecosystem":"PyPI","package":"vyper","purl":"pkg:pypi/vyper","source":"pysec"}],"references":[{"url":"https://github.com/vyperlang/vyper/security/advisories/GHSA-gp3w-2v2m-p686","tags":["advisory","exploit","vendor-advisory","web","x-refsource-confirm","x-transferred"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2024-24560","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/vyper/PYSEC-2024-148.yaml","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/vyperlang/vyper","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"partial","date":"2024-06-26T14:31:50.296Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2024-24560","url":"https://www.cve.org/CVERecord?id=CVE-2024-24560","licence":"CVE Terms of Use","modified":"2024-08-01T23:19:52.915Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-gp3w-2v2m-p686","url":"https://github.com/advisories/GHSA-gp3w-2v2m-p686","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:05.649Z"},{"source":"nvd","name":"NVD","id":"CVE-2024-24560","url":"https://nvd.nist.gov/vuln/detail/CVE-2024-24560","licence":"Public domain","modified":"2026-06-17T07:14:36.490Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2024-148","url":"https://osv.dev/vulnerability/PYSEC-2024-148","licence":"CC-BY-4.0","modified":"2024-11-21T14:57:09.929Z"}],"updatedAt":"2026-11-25T22:58:36.529Z","epss":{"score":0.00526,"percentile":0.46007,"date":"2026-12-01T12:00:22.000Z"}}