Abstract
Solidity is an object-oriented and high-level language for writing smart contracts that are used to execute, verify and enforce credible transactions on permissionless blockchains. In the last few years, analysis of smart contracts has raised considerable interest and numerous techniques have been proposed to check the presence of vulnerabilities in them. Current techniques lack traceability in source code and have widely differing work flows. There is no single unifying framework for analysis, instrumentation, optimisation and code generation of Solidity contracts. In this paper, we present SIF, a comprehensive framework for Solidity contract analysis, query, instrumentation, and code generation. SIF provides support for Solidity contract developers and testers to build source level techniques for analysis, understanding, diagnostics, optimisations and code generation. We show feasibility and applicability of the framework by building practical tools on top of it and running them on 1838 real smart contracts deployed on the Ethereum network.
Introduction
As smart contracts manage increasingly large sums of capital on blockchains like Ethereum, the need for robust analysis tools has skyrocketed. However, a significant gap exists in the current ecosystem: most existing tools operate on low-level bytecode or translate Solidity into intermediate representations (like LLVM bitcode). While effective for finding certain vulnerabilities, these approaches suffer from two major flaws: loss of traceability and lack of generality. When a bug is found in bytecode, it is often difficult to map it back to the specific line of high-level Solidity code. Furthermore, existing tools are often "one-off" solutions for specific security checks, lacking a unified framework similar to LLVM/Clang for C++.
The SIF Framework
SIF (Solidity Instrumentation Framework) is a comprehensive, "Clang-like" framework that allows developers to programmatically query, modify, and regenerate Solidity smart contract source code. By providing a high-level C++ interface to the Abstract Syntax Tree (AST), SIF enables the creation of custom analysis and instrumentation tools that maintain full traceability back to the original source code.
Methodology
SIF bridges the gap between high-level code and analysis by providing a three-phase pipeline for source-to-source transformation:
- AST Representation: SIF takes the AST produced by the standard Solidity compiler and maps its nodes (structs, functions, variables, etc.) into a hierarchy of C++ classes. This makes the contract structure programmatically accessible.
- Query and Instrumentation: The framework uses a "Visitor" pattern. Developers write a
visitfunction that traverses the AST. Within this function, they can use SIF’s helper methods to query node properties or modify them (e.g., renaming a variable or injecting new logic). - Code Generation: SIF can perform "round-tripping," using code templates to translate the modified AST back into valid, human-readable Solidity source code.
Tool Implementation
To demonstrate SIF's versatility, the authors implemented seven distinct tools. These tools are categorized into Contract Query (e.g., Function Listing, AST Diff, CG/CFG Generators) and Contract Instrumentation (e.g., Sif Rename, Assertion Analyser, Fault Seeder).
Evaluation and Results
The authors evaluated SIF using a dataset of 1,838 real-world smart contracts deployed on the Ethereum network. These contracts were used to test the framework's ability to handle diverse coding styles and the full range of Solidity syntax (up to version 0.5.3).
Key Findings
- Robustness: SIF successfully processed and regenerated code for all 1,838 contracts in the dataset, confirming it supports the entire Solidity syntax of the time.
- Usability: In a small user study with PhD and undergraduate students, SIF received an average ease-of-use rating of 4.3 out of 5. Users were able to implement new tools, such as a loop counter, with minimal effort.
- Performance: For 90% of the dataset (contracts under 1,000 lines), SIF finished the entire analysis and code generation process in under 4 seconds.
- Scalability: Very large contracts (e.g., 6,000+ lines) took significantly longer (up to 85 seconds), primarily due to the overhead of parsing large JSON-formatted ASTs.
Discussion
Operating at the source level is crucial for developers. By working at the AST level rather than bytecode, SIF ensures that the output of any analysis or transformation is immediately actionable. The power of "round-tripping"—modifying an AST and then generating valid source code—separates SIF from simple static analyzers. This allows for "active" tools like the Assertion Analyser, which automatically injects safety checks directly into the code.
Furthermore, SIF lowers the barrier to entry for building security tools. The framework abstracts away the complexities of compiler internals, allowing engineers with basic C++ knowledge to write custom instrumentation tools by interacting with high-level AST objects.
Limitations and Future Work
The primary technical bottleneck identified is the JSON parsing speed for the AST, which accounts for nearly half of the processing time in large contracts. Future versions aim to optimize these queries. Additionally, the authors acknowledge the need for more granular command-line options and more detailed documentation for every AST node type to further improve the developer experience.
Summary updated