Semantic Understanding of Smart Contracts: Executable Operational Semantics of Solidity

Jiao Jiao, Shuanglong Kan, Shang-Wei Lin, David Sanán, Yang Liu, Jun Sun

Smart contracts on the Ethereum blockchain manage billions in digital assets, yet their immutable nature makes bugs catastrophic. Solidity, the dominant language for these contracts, is notoriously complex and often counter-intuitive. This research, presented at the 2020 IEEE Symposium on Security and Privacy, introduces the first complete, executable formal semantics for Solidity. By leveraging the K-framework, the authors establish a "source of truth" that bridges the gap between high-level developer intent and low-level execution.

The Semantic Gap in Security Analysis

Existing security tools often struggle with "semantic gaps." Tools analyzing EVM bytecode lose high-level context, while those translating Solidity to intermediate languages (IL) like Boogie may misinterpret Solidity's unique quirks. These discrepancies lead to false positives—where tools "cry wolf" over non-existent bugs—and false negatives—where critical vulnerabilities like the DAO reentrancy attack are missed. A formal, high-level definition of Solidity allows for reasoning about code exactly as written, providing a more accurate foundation for verification.

Formalizing Solidity with the K-Framework

The authors utilized the K-framework, a rewrite-logic-based tool, to define Solidity's operational semantics. A central component of this model is the runtime configuration, which uses a hierarchical "cell" structure to represent the complete state of the Ethereum environment.

The hierarchical configuration of the Solidity semantics, showing cells for contracts, functions, and transactions.

As shown in Figure 4, these cells track everything from global blockchain state and contract storage to local function stacks and gas consumption. This granular representation allows the semantics to act as a formal interpreter. Beyond state management, the authors introduced a "uniform call representation" to normalize Solidity's various call types (e.g., delegatecall, constructors, and fallbacks) into a single internal format, simplifying the reasoning process.

Evaluation and Coverage

To validate the model, the authors tested it against the official Solidity compiler test suite, comprising 482 tests from the Remix IDE. The semantics successfully passed these tests, ensuring consistency with the actual language implementation.

Frequency of various Solidity language features (types, functions, statements) covered in the evaluation dataset.

The evaluation demonstrated high coverage across core Solidity features. As illustrated in Figure 6, the model handles a wide array of types (address, uint, mapping, etc.), function definitions, and complex control flow statements. This breadth ensures that the semantics are applicable to real-world contracts.

Impact: Discovering Bugs and Defining Security

The practical utility of this formal model was proven through the discovery of a compiler bug in Remix (pre-0.5.0), where missing location keywords allowed local arrays to accidentally overwrite storage slots. Furthermore, the authors used their semantics to mathematically define security properties like "Reentrancy Safety" and "Delegatecall Safety."

By applying these rigorous definitions, they demonstrated that their model could correctly identify vulnerabilities in cases where popular tools like Oyente, Zeus, and Securify failed due to semantic misunderstandings. For instance, the semantics respect actual initialization rules, avoiding the "havoc" statements in other tools that lead to fake integer underflow reports.

Conclusion

The development of executable formal semantics for Solidity marks a significant step toward more reliable smart contracts. By providing a rigorous mathematical foundation, this work enables the creation of next-generation security tools that can verify high-level properties with unprecedented precision. Future work includes integrating this model with EVM-level analysis to handle inline assembly and keeping pace with the evolving gas costs of the Ethereum network.

Summary updated

BibTeX
@inproceedings{jiao2020semantic,
  author = {Jiao Jiao and Shuanglong Kan and Shang-Wei Lin and David Sanán and Yang Liu and Jun Sun},
  title = {{Semantic Understanding of Smart Contracts: Executable Operational Semantics of Solidity}},
  booktitle = {SP},
  year = {2020},
  doi = {10.1109/sp40000.2020.00066},
}
Figure