5.3medium
vyper performs double eval of the argument of sqrt
- Severity
- 5.3medium CVSS:3.1 by GitHub_M
- Exploit likelihood
- 0.57% (higher than 41% of CVEs)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-5jrj-52x8-m64hPYSEC-2024-209
Description
Vyper is a pythonic Smart Contract Language for the Ethereum virtual machine. In versions 0.3.10 and prior, using the `sqrt` builtin can result in double eval vulnerability when the argument has side-effects. It can be seen that the `build_IR` function of the `sqrt` builtin doesn't cache the argument to the stack. As such, it can be evaluated multiple times (instead of retrieving the value from the stack). No vulnerable production contracts were found. Additionally, double evaluation of side-effects should be easily discoverable in client tests. As such, the impact is low. As of time of publication, no fixed versions are available.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| vyperlang vyper | <= 0.3.10, *, before 0.4.0 | CVE List, NVD |
| vyper (PyPI) | before 0.4.0 | GitHub Advisory Database, PyPA Advisory Database |
All scores
| GitHub_M | 5.3medium CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N |
| GitHub | 5.3medium CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N |
| NVD | 5.3medium CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N |
| PyPA Advisory Database | 5.3medium CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N |
Classification
SSVC (CISA-ADP): exploitation poc, automatable yes, technical impact partial.
What each source says
CVE List
Vyper is a pythonic Smart Contract Language for the Ethereum virtual machine. In versions 0.3.10 and prior, using the `sqrt` builtin can result in double eval vulnerability when the argument has side-effects. It can be seen that the `build_IR` function of the `sqrt` builtin doesn't cache the argument to the stack. As such, it can be evaluated multiple times (instead of retrieving the value from the stack). No vulnerable production contracts were found. Additionally, double evaluation of side-effects should be easily discoverable in client tests. As such, the impact is low. As of time of publication, no fixed versions are available.
GitHub Advisory Database
Summary
Using the sqrt builtin can result in multiple eval evaluation of side effects when the argument has side-effects. The bug is more difficult (but not impossible!) to trigger as of 0.3.4, when the unique symbol fence was introduced (https://github.com/vyperlang/vyper/pull/2914).
A contract search was performed and no vulnerable contracts were found in production.
Details
It can be seen that the build_IR function of the sqrt builtin doesn't cache the argument to the stack:
https://github.com/vyperlang/vyper/blob/4595938734d9988f8e46e8df38049ae0559abedb/vyper/builtins/functions.py#L2151
As such, it can be evaluated multiple times (instead of retrieving the value from the stack).
PoC
With at least Vyper version 0.2.15+commit.6e7dba7 the following contract:
c: uint256
@internal
def some_decimal() -> decimal:
self.c += 1
return 1.0
@external
def foo() -> uint256:
k: decimal = sqrt(self.some_decimal())
return self.c
passes the following test:
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.13;
import "../../lib/ds-test/test.sol";
import "../../lib/utils/Console.sol";
import "../../lib/utils/VyperDeployer.sol";
import "../ITest.sol";
contract ConTest is DSTest {
VyperDeployer vyperDeployer = new VyperDeployer();
ITest t;
function setUp() public {
t = ITest(vyperDeployer.deployContract("Test"));
}
function testFoo() public {
uint256 val = t.foo();
console.log(val);
assert (val == 4);
}
}
Patches
Patched in https://github.com/vyperlang/vyper/pull/3976.
Impact
No vulnerable production contracts were found.
NVD (es)
Vyper es un lenguaje de contrato inteligente pitónico para la máquina virtual Ethereum. En las versiones 0.3.10 y anteriores, el uso de la función incorporada `sqrt` puede generar una vulnerabilidad de doble evaluación cuando el argumento tiene efectos secundarios. Se puede ver que la función `build_IR` del incorporado `sqrt` no almacena en caché el argumento en la pila. Como tal, se puede evaluar varias veces (en lugar de recuperar el valor de la pila). No se encontraron contratos de producción vulnerables. Además, la doble evaluación de los efectos secundarios debería poder descubrirse fácilmente en las pruebas de los clientes. Como tal, el impacto es bajo. Al momento de la publicación, no hay versiones fijas disponibles.
References
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2024-32649 changed 2024-08-02 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-5jrj-52x8-m64h changed 2026-06-10 | CC-BY-4.0 |
| NVD | CVE-2024-32649 changed 2026-06-17 | Public domain |
| PyPA Advisory Database | PYSEC-2024-209 changed 2026-06-10 | CC-BY-4.0 |