Strengthening Solidity Invariant Generation: From Post- to Pre-Deployment

Kartik Kaushik,Raju Halder,Samrat Mondal
2024-09-18
Abstract:Invariants are essential for ensuring the security and correctness of Solidity smart contracts, particularly in the context of blockchain's immutability and decentralized execution. This paper introduces InvSol, a novel framework for pre-deployment invariant generation tailored specifically for Solidity smart contracts. Unlike existing solutions, namely InvCon, InvCon+, and Trace2Inv, that rely on post-deployment transaction histories on Ethereum mainnet, InvSol identifies invariants before deployment and offers comprehensive coverage of Solidity language constructs, including loops. Additionally, InvSol incorporates custom templates to effectively prevent critical issues such as reentrancy, out-of-gas errors, and exceptions during invariant generation. We rigorously evaluate InvSol using a benchmark set of smart contracts and compare its performance with state-of-the-art solutions. Our findings reveal that InvSol significantly outperforms these tools, demonstrating its effectiveness in handling new contracts with limited transaction histories. Notably, InvSol achieves a 15% improvement in identifying common vulnerabilities compared to InvCon+ and is able to address certain crucial vulnerabilities using specific invariant templates, better than Trace2Inv.
Software Engineering,Programming Languages
What problem does this paper attempt to address?
The problem that this paper attempts to solve is: generating invariants before the deployment of Solidity smart contracts to ensure the security and correctness of smart contracts. Specifically, existing methods rely on the transaction history after the smart - contract deployment to generate invariants, and this method has the following problems: 1. **Dependence on post - deployment transaction history**: Existing methods rely on the transaction history data of smart contracts on the Ethereum mainnet to generate invariants. This limits their application in static code verification, especially when detecting and fixing errors before smart - contract deployment. Due to the immutability of the blockchain, error fixing after deployment becomes complicated. 2. **Performance issues of newly - deployed contracts**: For newly - deployed or infrequently - used smart contracts, due to the lack of transaction history data, the invariants generated by existing methods may be inefficient and are likely to overlook specific behaviors or boundary cases, thus causing smart contracts to be prone to errors and security vulnerabilities. 3. **Insufficient support for loop invariants**: Existing tools cannot fully detect loop invariants. In Solidity, loops are used to handle repetitive tasks, and their behavior cannot be ignored. For example, during the account - balance withdrawal process, if the loop is implemented incorrectly, it may deplete the entire treasury, resulting in an irreversible situation. To solve these problems, this paper proposes a new framework, InvSol, which can generate invariants before smart - contract deployment and does not rely on transaction history. The main features of InvSol include: - **Comprehensive coverage of Solidity language structures**: In particular, it supports the detection of loop invariants. - **Custom templates**: Effectively prevent key problems such as re - entry attacks, exceeding Gas limits, and exceptions. - **Superior performance**: Evaluated by a benchmark test set, InvSol has a 15% improvement over existing tools in identifying common vulnerabilities. Therefore, this paper aims to provide a more efficient and comprehensive method to ensure the security and correctness of Solidity smart contracts.