Back to Blog
Best Practices

Solidity Attack Vector #24: Floating Pragma

SecurityInfinity Research4 min read

Solidity Attack Vector #24: Floating Pragma

The pragma line is often the first thing you write, and the first thing you get wrong.

Understanding the Floating Pragma

A floating pragma (using ^) tells the compiler to use any version higher than the specified one. While this is great for libraries, it is dangerous for final contract deployments.

The Risk:

Contracts should be tested and audited with a specific compiler version. Newer versions of the compiler might introduce:

- Optimization bugs.

- Breaking changes in how opcodes are handled.

- Different gas costs that could break your logic.

Recommendation

Always lock your pragma. Use pragma solidity 0.8.20; instead of ^0.8.20;. This ensures that the code you tested is exactly the code that gets deployed.

Share this security research