CVE-2024-32649: vyper performs double eval of the argument of sqrt

Published Apr 25, 2024
·
Updated

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 buildIR 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: vyper c: uint256

@internal def somedecimal() -> decimal: self.c += 1 return 1.0

@external def foo() -> uint256: k: decimal = sqrt(self.somedecimal()) return self.c passes the following test: solidity // 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.

Other sources

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 buildIR 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.

— MITRE

Affected Software

2 affected componentsFixes available
pip/vyper<0.4.0
0.4.0
vyperlang Vyper Python<0.4.0

Event History

Apr 25, 2024
CVE Published
via MITRE·05:53 PM
Data Sourced
via MITRE·05:53 PM
DescriptionSeverityWeakness
Advisory Published
via GitHub·07:50 PM

Frequently Asked Questions

1

What is the severity of CVE-2024-32649?

CVE-2024-32649 has a moderate severity rating due to potential unintended side effects from the `sqrt` builtin.

2

How do I fix CVE-2024-32649?

To fix CVE-2024-32649, upgrade Vyper to version 0.4.0 or later.

3

What software is affected by CVE-2024-32649?

CVE-2024-32649 affects Vyper versions prior to 0.4.0.

4

Who is the vendor for CVE-2024-32649?

The vendor for CVE-2024-32649 is Vyperlang, the organization behind the Vyper programming language.

5

What kind of issue is CVE-2024-32649?

CVE-2024-32649 is an issue related to multiple eval evaluations causing side effects with the `sqrt` builtin function.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203