---
title: "Compiler bugs"
url: https://dontgetrekt.today/dev/compiler-bug
section: "Can the platform be trusted?"
---

# Compiler bugs

The source code is correct, but the compiler produces wrong bytecode. In 2023, a bug in some Vyper versions broke the reentrancy lock of several Curve pools.

## How the attack works

1. A compiler version has a bug: a lock that does not lock, a wrong storage slot, a wrong optimization.
2. The code passed review, because reviewers read the source, not the bytecode.
3. An attacker who knows the bug finds the contracts that were built with that version, and uses the bug as if it were a normal code flaw.

## Vulnerable code

```solidity
# Vyper 0.2.15, 0.2.16 and 0.3.0
@external
@nonreentrant("lock")
def remove_liquidity(...):
    ...   # the lock used a different storage slot per function,
          # so cross-function reentrancy was possible
```

## Fixed code

```solidity
// Pin a compiler version that has no known bug that affects your code.
pragma solidity 0.8.28;   // exact version, not ^0.8.0

// Read the list of known bugs for that version:
// https://docs.soliditylang.org/en/latest/bugs.html
// For Vyper: https://github.com/vyperlang/vyper/security/advisories
```

## Review checklist

- Pin an exact compiler version. Do not use a floating pragma in deployed code.
- Read the known-bugs list of the compiler version before deployment.
- Do not use the newest compiler release for high-value code on its first weeks. Do not use very old versions either.
- Keep a list of your deployed contracts and their compiler versions, so you can check them when a new advisory comes out.

## How to test for it

- Test the behaviour of the deployed bytecode, not only the source: run your reentrancy tests against the compiled artifact.

## Real exploits (1)

- 2023-07-30 Curve Finance (alETH, msETH, pETH, CRV/ETH pools; affecting JPEG'd, Alchemix, Metronome) ($69.3M): Curve pools and partner protocols (JPEG'd, Alchemix, Metronome) lost about $69M because a 0-day bug in older Vyper versions broke the nonreentrant guard. [rekt.news](https://rekt.news/curve-vyper-rekt) [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2023-07/Curve_exp01.sol)

## References

- [Solidity: List of known bugs](https://docs.soliditylang.org/en/latest/bugs.html)
- [Vyper: Security advisories](https://github.com/vyperlang/vyper/security/advisories)
