Executable Operational Semantics of Solidity

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

Smart contracts are high-stakes software. Once deployed on a blockchain like Ethereum, they are typically immutable—meaning a single bug can lead to permanent financial loss. While most security tools analyze the low-level bytecode (EVM) that actually runs on the network, developers write and reason in Solidity. This research introduces the first formal, executable operational semantics for Solidity, bridging the gap between high-level code and formal verification.

The Challenge: High-Level Logic Errors

Developing smart contracts is notoriously error-prone. Unlike traditional programming in C++ or Java, Solidity introduces unique concepts like Storage (permanent data on the blockchain) versus Memory (temporary data during execution).

A dangerous "gotcha" exists in certain versions of Solidity: declaring a local array without specifying its location defaults it to storage. If uninitialized, this local variable might point to storage slot 0, silently overwriting global state variables. Because most existing verification tools focus on EVM bytecode, these high-level logic errors are hard for developers to diagnose. There was a clear need for a formal definition of Solidity itself, not just the machine code it compiles into.

Solidity contract demonstrating potential storage corruption via uninitialized local variables.

Methodology: Formalizing the "Rulebook"

The researchers developed a formal mathematical "rulebook" (Structural Operational Semantics) for the Solidity programming language and implemented it in the K framework. This approach rests on two technical pillars:

  1. Structural Operational Semantics (SOS): A set of formal rules describing exactly how state changes when a Solidity statement is executed. This includes complex models for types (mappings, dynamic arrays), state transitions, and function calls.
  2. The K Framework: By implementing these SOS rules in K—a rewrite-logic-based framework—the semantics become executable. This allows developers to "run" a Solidity contract through the K-framework toolset to verify behavior or prove specific security properties using reachability logic.

The implementation is substantial, involving over 200 rules and 2,000 lines of K definition, using the official Solidity documentation as the ground truth.

Key Insights: Tracking the Storage Trap

The formal model explicitly tracks how variables map to specific storage slots, making "hidden" overwrites visible. By formalizing Solidity rather than EVM bytecode, the authors enable tools that provide feedback in the language the programmer actually uses. This makes it easier to identify why a design choice, such as a fallback function, is problematic.

Formal representation of storage layouts and variable packing in the K framework model.

As shown in the figures above, the model correctly predicts how Solidity packs variables into 32-byte storage slots. In subfigure (a), state variable a occupies slot 0x0. However, in subfigure (b), an uninitialized local storage array d incorrectly maps its first element d[0] to slot 0x0, highlighting the potential for silent state corruption.

Results and Vulnerability Detection

The framework achieved high coverage of Solidity syntax, including elementary types, mappings, arrays, and complex function behaviors like modifiers and internal/external calls. Its correctness was validated against the official Remix compiler.

Crucially, the framework successfully detected the DAO reentrancy attack. By observing the state of "cells" in the K-framework configuration, the researchers could see malicious recursive calls draining a contract's balance before the credit was deducted. This demonstrates that executable semantics can serve as a powerful "reference interpreter" for finding bugs that deviate from developer intent.

Limitations and Future Outlook

While a major step forward, the work currently excludes some features like inline assembly and certain state mutability specifiers. Furthermore, the model focuses on language semantics rather than the broader blockchain context, such as gas costs or the mining process.

Future work aims to expand the tool to identify a wider variety of vulnerabilities beyond reentrancy and to move toward full-scale automated verification of complex, multi-contract systems. By providing a formal foundation for Solidity, this research paves the way for more robust and secure smart contract development.

Summary updated

BibTeX
@misc{jiao2018executable,
  author = {Jiao Jiao and Shuanglong Kan and Shang-Wei Lin and David Sanán and Yang Liu and Jun Sun},
  title = {{Executable Operational Semantics of Solidity}},
  year = {2018},
  eprint = {1804.01295},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1804.01295},
}
Figure