CVE-2024-32647: vyper performs double eval of raw_args in create_from_blueprint
Summary Using the createfromblueprint builtin can result in a double eval vulnerability when rawargs=True and the args argument has side-effects.
A contract search was performed and no vulnerable contracts were found in production. In particular, the rawargs variant of createfromblueprint was not found to be used in production.
Details It can be seen that the buildcreateIR function of the createfromblueprint builtin doesn't cache the mentioned args argument to the stack: https://github.com/vyperlang/vyper/blob/cedf7087e68e67c7bfbd47ae95dcb16b81ad2e02/vyper/builtins/functions.py#L1847
As such, it can be evaluated multiple times (instead of retrieving the value from the stack).
PoC The vulnerability is demonstrated in the following boa test: vyper src1 = """ c: uint256 """ deployer = """ createdaddress: public(address) deployed: public(uint256)
@external def get() -> Bytes[32]: self.deployed += 1 return b''
@external def create(target: address): self.createdaddress = createfromblueprint(target, rawcall(self, methodid("get()"), maxoutsize=32), rawargs=True, codeoffset=3) """
Factory = b.loadspartial(src1) c = Factory.deployasblueprint()
c2 = b.loads(deployer, b'') c2.create(c) c2.deployed() The output of c2.deployed() is 2 although create was called only once and the value was initialized to 0.
Patches Patched in https://github.com/vyperlang/vyper/pull/3976.
Impact 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.
Other sources
Vyper is a pythonic Smart Contract Language for the Ethereum virtual machine. In versions 0.3.10 and prior, using the createfromblueprint builtin can result in a double eval vulnerability when rawargs=True and the args argument has side-effects. It can be seen that the buildcreateIR function of the createfromblueprint builtin doesn't cache the mentioned args 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 exist.
— MITRE
Affected Software
Event History
Frequently Asked Questions
What is the severity of CVE-2024-32647?
CVE-2024-32647 is considered a moderate severity vulnerability due to potential exploitation through double evaluation.
How do I fix CVE-2024-32647?
To fix CVE-2024-32647, upgrade to Vyper version 0.4.1 or later that addresses this vulnerability.
Which versions of Vyper are affected by CVE-2024-32647?
CVE-2024-32647 affects Vyper versions prior to 0.4.1.
What is the impact of CVE-2024-32647?
The impact of CVE-2024-32647 can lead to unintended side-effects in smart contracts due to the double eval vulnerability.
What should I do if I am using an affected version of Vyper related to CVE-2024-32647?
If using an affected version of Vyper, immediately update to the latest version to mitigate the risks associated with CVE-2024-32647.