Differential Testing Solidity Compiler through Deep Contract Manipulation and Mutation

Zhenzhou Tian, Fanfan Wang, Yanping Chen, Lingwei Chen · Research Square · 2024

Abstract Solidity, the language utilized for developing smart contracts, has been gainingincreased importance in blockchain system. Ensuring bug-free of its accompanying language compiler, which converts the contract source codes into executablesfinally deployed on the blockchain, is thus of paramount importance. This studypresents DeSCDT, a Deep learning-based Solidity Compiler Differential Testingapproach, to explore possible defects in solidity compiler. At the core lies a wellbehaving deep contract generator following the Transformer architecture andlearnt with diverse contract code. From an initial seed pool of contracts carefully picked through semantic encoding and clustering, the generator is capableof stably producing highly syntactic-valid and functional-rich smart contracts,with three meticulously formulated generation strategies and a set of mutationoperations. Subsequently, in the meantime of compiling these generated contractsto trigger compiler crashes, a differential testing environment is setup to exploremisoptimization bugs, by observing the inconsistencies between the outcomes and the aspects including gas consumption and opcode size of the optimized and nonoptimized bytecodes. For the experiments, the syntactic validity and diversity ofthe contracts generated with DeSCDT, as well as its ability in discovering compiler defects, are investigated. The findings indicate that DeSCDT can effectivelygenerate syntactically correct contracts with a pass rate of 90.8% alongside highdiversity. Among the contracts tested for a 24-hour running of DeSCDT, 37.4%of them expose inconsistencies across the optimized and non-optimized versionof the same contract. Six bugs that could trigger direct crashing of the compilerhave also detected.

Read the paper · More papers on PaperTik