Abstract
Smart contracts have received a lot of attention. A smart contract is a program that runs on a blockchain. Some recent studies reveal that most of the smart contracts on the Ethereum blockchain are highly similar. An inexperienced smart contract developer can refer to some existing smart contracts that is similar to their own contracts to help their development by applying the differentiated code from the existing similar contracts. How to identify similar contracts and extract differentiated code to recommend to the developers as guidance is what we aim for in this work. Differentiated code is defined as the source code excluding the repeated part in two similar smart contracts, which usually illustrates how a software feature is implemented or a programming issue is solved. Thus, differentiated code might be used to guide the update of a smart contract. In this paper, we propose a differentiated code recommendation approach, SmartDiffrec, for supporting smart contract update. Specifically, we apply syntax and semantic similarities to discover the similar contracts for a given target contract, and then recommend the differentiated code to the target contract. Moreover, we investigate three research questions to analyze the effectiveness of our approach from the whole to the specific. The results show that the differentiated codes extracted found by our approach can effectively support smart contract update.
Similar content being viewed by others
References
Atzei N, Bartoletti M, Cimoli T (2017) A survey of attacks on ethereum smart contracts (sok). In: Maffei M, Ryan M (eds) Principles of Security and Trust. Springer, Berlin Heidelberg, Berlin, Heidelberg, p 164–186
Bartoletti M, Carta S, Cimoli T, Saia R (2017) Dissecting Ponzi schemes on Ethereum: identification, analysis, and impact. ArXiv e-prints arXiv:1703.03779
Baxter ID, Yahin A, Moura L, Sant’Anna M, Bier L (1998) Clone detection using abstract syntax trees. In: Proceedings of the International Conference on Software Maintenance, IEEE Computer Society, Washington, DC, USA, ICSM ’98, p 368 http://dl.acm.org/citation.cfm?id=850947.853341
Chen T, Li X, Luo X, Zhang X (2017) Under-optimized smart contracts devour your money. In: IEEE 24th International Conference on Software Analysis, Evolution and Reengineering (SANER), p 442–446 https://doi.org/10.1109/SANER.2017.7884650
Chen T, Li X, Wang Y, Chen J, Li Z, Luo X, Au MH, Zhang X (2017) An adaptive gas cost mechanism for ethereum to defend against under-priced dos attacks. In: Liu JK, Samarati P (eds) Information Security Practice and Experience. Springer International Publishing, Cham, pp 3–24
Chen T, Zhu Y, Li Z, Chen J, Li X, Luo X, Lin X, Zhange X (2018) Understanding ethereum via graph analysis. In: IEEE Conference on Computer Communications, p 1484–1492 https://doi.org/10.1109/INFOCOM.2018.8486401
Chen T, Li Z, Zhang Y, Luo X, Wang T, Hu T, Xiao X, Wang D, Huang J, Zhang X (2019a) A large-scale empirical study on control flow identification of smart contracts. In: 2019 ACM/IEEE International Symposium on Empirical Software Engineering and Measurement (ESEM), p 1–11
Chen T, Zhang Y, Li Z, Luo X, Wang T, Cao R, Xiao X, Zhang X (2019b) Tokenscope: Automatically detecting inconsistent behaviors of cryptocurrency tokens in ethereum. In: Proceedings of the 2019 ACM SIGSAC Conference on Computer and Communications Security, p 1503–1520
Chen W, Zheng Z, Cui J, Ngai E, Zheng P, Zhou Y (2018) Detecting ponzi schemes on ethereum: Towards healthier blockchain technology. In: Proceedings of the 2018 World Wide Web Conference, International World Wide Web Conferences Steering Committee, Republic and Canton of Geneva, Switzerland, WWW ’18, p 1409–1418 https://doi.org/10.1145/3178876.3186046
Christidis K, Devetsikiotis M (2016) Blockchains and smart contracts for the internet of things. IEEE Access 4:2292–2303. https://doi.org/10.1109/ACCESS.2016.2566339
Cordy JR (2006) The txl source transformation language. Science of Computer Programming, special Issue on The Fourth Workshop on Language Descriptions, Tools, and Applications (LDTA ’04) 61(3):190–210 https://doi.org/10.1016/j.scico.2006.04.002, https://www.sciencedirect.com/science/article/pii/S0167642306000669,
Cordy JR, Roy CK (2011) The nicad clone detector. In: IEEE 19th International Conference on Program Comprehension, p 219–220 https://doi.org/10.1109/ICPC.2011.26
Dickerson T, Gazzillo P, Herlihy M, Koskinen E (2017) Adding concurrency to smart contracts. In: Proceedings of the ACM Symposium on Principles of Distributed Computing, ACM, New York, NY, USA, PODC ’17, pp 303–312 https://doi.org/10.1145/3087801.3087835
Dinh TTA, Liu R, Zhang M, Chen G, Ooi BC, Wang J (2018) Untangling blockchain: A data processing view of blockchain systems. IEEE Transactions on Knowledge and Data Engineering 30(7):1366–1385. https://doi.org/10.1109/TKDE.2017.2781227
Elmay FK, Salah K, Jayaraman R, Omar IA (2022) Using nfts and blockchain for traceability and auctioning of shipping containers and cargo in maritime industry. IEEE Access 10:124507–124522. https://doi.org/10.1109/ACCESS.2022.3225000
Feist J, Grieco G, Groce A (2019) Slither: A static analysis framework for smart contracts. In: 2019 IEEE/ACM 2nd International Workshop on Emerging Trends in Software Engineering for Blockchain (WETSEB), p 8–15 https://doi.org/10.1109/WETSEB.2019.00008
Frantz CK, Nowostawski M (2016) From institutions to code: Towards automated generation of smart contracts. In: 2016 IEEE 1st International Workshops on Foundations and Applications of Self* Systems (FAS*W), pp 210–215 https://doi.org/10.1109/FAS-W.2016.53
Gao Z, Jiang L, Xia X, Lo D, Grundy J (2020) Checking smart contracts with structural code embedding. IEEE Transactions on Software Engineering
Ghaleb A, Pattabiraman K (2020) How effective are smart contract analysis tools? evaluating smart contract static analysis tools using bug injection. In: Proceedings of the 29th ACM SIGSOFT International Symposium on Software Testing and Analysis, Association for Computing Machinery, New York, NY, USA, ISSTA 2020, p 415-427 https://doi.org/10.1145/3395363.3397385
Grossman S, Abraham I, GolanGueta G, Michalevsky Y, Rinetzky N, Sagiv M, Zohar Y (2018) Online detection of effectively callback free objects with applications to smart contracts. CoRR arxiv:1801.04032
Harris ZS (1981) Distributional Structure, Springer Netherlands, Dordrecht, pp 3–22. https://doi.org/10.1007/978-94-009-8467-7-1
Hartigan JA, Wong MA (1979) Algorithm as 136: A k-means clustering algorithm. Journal of the Royal Statistical Society 28(1):100–108
He N, Wu L, Wang H, Guo Y, Jiang X (2019) Characterizing code clones in the ethereum smart contract ecosystem. arXiv preprint arXiv:1905.00272
He X, Qin B, Zhu Y, Chen X, Liu Y (2018) Spesc: A specification language for smart contracts. In: IEEE 42nd Annual Computer Software and Applications Conference (COMPSAC), vol 01, pp 132–137 https://doi.org/10.1109/COMPSAC.2018.00025
Huang Y, Chen X, Liu Z, Luo X, Zheng Z (2017a) Using discriminative feature in software entities for relevance identification of code changes. Journal of Software: Evolution and Process 29(7):e1859. https://doi.org/10.1002/smr.1859
Huang Y, Zheng Q, Chen X, Xiong Y, Liu Z, Luo X (2017b) Mining version control system for automatically generating commit comment. In: ACM/IEEE International Symposium on Empirical Software Engineering and Measurement (ESEM), pp 414–423 https://doi.org/10.1109/ESEM.2017.56
Huang Y, Jia N, Chen X, Hong K, Zheng Z (2018a) Salient-class location: Help developers understand code change in code review. In: Proceedings of the 2018 26th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering, ACM, New York, NY, USA, ESEC/FSE, pp 770–774 https://doi.org/10.1145/3236024.3264841
Huang Y, Jia N, Zhou Q, Chen X, Xiong Y, Luo X (2018b) Guiding developers to make informative commenting decisions in source code. In: Proceedings of the 40th International Conference on Software Engineering: Companion Proceeedings, ACM, New York, NY, USA, ICSE ’18, pp 260–261 https://doi.org/10.1145/3183440.3194960
Huang Y, Kong Q, Jia N, Chen X, Zheng Z (2019) Recommending differentiated code to support smart contract update. In: IEEE/ACM 27th International Conference on Program Comprehension (ICPC), pp 260–270 https://doi.org/10.1109/ICPC.2019.00045
Jiang J, Xiong Y, Zhang H, Gao Q, Chen X (2018) Shaping program repair space with existing patches and similar code. In: Proceedings of the 27th ACM SIGSOFT International Symposium on Software Testing and Analysis, ACM, New York, NY, USA, ISSTA, pp 298–309 https://doi.org/10.1145/3213846.3213871
Juels A, Kosba A, Shi E (2016) The ring of gyges: Investigating the future of criminal smart contracts. In: Proceedings of the ACM SIGSAC Conference on Computer and Communications Security, ACM, New York, NY, USA, CCS ’16, pp 283–295 https://doi.org/10.1145/2976749.2978362
Kiffer L, Levin D, Mislove A (2018) Analyzing ethereum’s contract topology. In: Proceedings of the Internet Measurement Conference, pp 494–499
Kosba A, Miller A, Shi E, Wen Z, Papamanthou C (2016) Hawk: The blockchain model of cryptography and privacy-preserving smart contracts. In: IEEE Symposium on Security and Privacy (SP), pp 839–858 https://doi.org/10.1109/SP.2016.55
Le Q, Mikolov T (2014a) Distributed representations of sentences and documents. In: Proceedings of the 31st International Conference on International Conference on Machine Learning, JMLR.org, ICML’14, vol 32 p II-1188-II-1196
Le Q, Mikolov T (2014b) Distributed representations of sentences and documents. In: Proceedings of the 31st International Conference on International Conference on Machine Learning, JMLR.org, ICML’14, vol 32 p II-1188-II-1196
Liu H, Yang Z, Liu C, Jiang Y, Zhao W, Sun J (2018) Eclone: Detect semantic clones in ethereum via symbolic transaction sketch. In: Proceedings of the 26th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering, p 900–903
Liu H, Yang Z, Jiang Y, Zhao W, Sun J (2019) Enabling clone detection for ethereum via smart contract birthmarks. In: IEEE/ACM 27th International Conference on Program Comprehension (ICPC), IEEE, p 105–115
Luu L, Chu DH, Olickel H, Saxena P, Hobor A (2016) Making smart contracts smarter. In: Proceedings of the ACM SIGSAC Conference on Computer and Communications Security, ACM, New York, NY, USA, CCS ’16, p 254–269 https://doi.org/10.1145/2976749.2978309
Merkle RC (1980) Protocols for public key cryptosystems. In: IEEE Symposium on Security and Privacy, p 122–122 https://doi.org/10.1109/SP.1980.10006
Merlec MM, Lee YK, In HP (2021) Smartbuilder: A block-based visual programming framework for smart contract development. In: IEEE International Conference on Blockchain (Blockchain), pp 90–94 https://doi.org/10.1109/Blockchain53845.2021.00023
Mikolov T, Sutskever I, Chen K, Corrado G, Dean J (2013) Distributed representations of words and phrases and their compositionality. In: Proceedings of the 26th International Conference on Neural Information Processing Systems, Curran Associates Inc., USA, NIPS’13, pp 3111–3119. http://dl.acm.org/citation.cfm?id=2999792.2999959
Mueller B (2018) Smashing ethereum smart contracts for fun and real profit. In: in 9th Annual HITB Security Conference (HITBSecConf), p 54
Nakamoto S (2009) Bitcoin: A peer-to-peer electronic cash system. Cryptography Mailing list at https://metzdowd.com
Nick S (2008) The idea of smart contracts (1997). http://www.fonhumuvanl/rob/Courses/InformationInSpeech/CDROM/Literature/LOTwinterschool2006/szabobestvwhnet/idea.html
Norta A (2015) Creation of smart-contracting collaborations for decentralized autonomous organizations. Perspectives in Business Informatics Research. Springer International Publishing, Cham, pp 3–17
Oliva J, Serrano JI, del Castillo MD, Iglesias Á (2011) Symss: A syntax-based measure for short-text semantic similarity. Data & Knowledge Engineering 70(4):390–405
Ostrom E (1995) A grammar of institutions. American Political Science Review 89(3):582–600
Parizi RM, Amritraj Dehghantanha A (2018) Smart contract programming languages on blockchains: An empirical evaluation of usability and security. Blockchain - ICBC 2018. Springer International Publishing, Cham, pp 75–91
Ren M, Ma F, Yin Z, Fu Y, Li H, Chang W, Jiang Y (2021) Making smart contract development more secure and easier. In: Proceedings of the 29th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering, Association for Computing Machinery, New York, NY, USA, ESEC/FSE 2021, p 1360-1370 https://doi.org/10.1145/3468264.3473929
Roy CK, Cordy JR (2008a) Nicad: Accurate detection of near-miss intentional clones using flexible pretty-printing and code normalization. In: Proceedings of the 16th IEEE International Conference on Program Comprehension, IEEE Computer Society, USA, ICPC ’08, p 172-181 https://doi.org/10.1109/ICPC.2008.41
Roy CK, Cordy JR (2008b) Nicad: Accurate detection of near-miss intentional clones using flexible pretty-printing and code normalization. In: 16th IEEE International Conference on Program Comprehension, p 172–181 https://doi.org/10.1109/ICPC.2008.41
Roy CK, Cordy JR, Koschke R (2009) Comparison and evaluation of code clone detection techniques and tools: A qualitative approach. Sci Comput Program 74(7):470–495. https://doi.org/10.1016/j.scico.2009.02.007
Sapirshtein A, Sompolinsky Y, Zohar A (2017) Optimal selfish mining strategies in bitcoin. Christ Church, Barbados, vol 9603 LNCS, p 515–532
Swan M (2015) Blockchain: Blueprint for a New Economy, 1st edn. O’Reilly Media, Inc
Torres CF, Schütte J, State R (2018) Osiris: Hunting for integer bugs in ethereum smart contracts. In: Proceedings of the 34th Annual Computer Security Applications Conference, Association for Computing Machinery, New York, NY, USA, ACSAC ’18, p 664-676 https://doi.org/10.1145/3274694.3274737
Wang B, Chen S, Yao L, Liu B, Xu X, Zhu L (2018) A simulation approach for studying behavior and quality of blockchain networks. Blockchain - ICBC 2018. Springer International Publishing, Cham, pp 18–31
Wettel R, Marinescu R (2005) Archeology of code duplication: recovering duplication chains from small duplication fragments. In: Seventh International Symposium on Symbolic and Numeric Algorithms for Scientific Computing (SYNASC’05), p 8 https://doi.org/10.1109/SYNASC.2005.20
Yu L, Tsai W, Li G, Yao Y, Hu C, Deng E (2017) Smart-contract execution with concurrent block building. In: 2017 11th IEEE Symposium on Service-Oriented System Engineering (SOSE), IEEE Computer Society, Los Alamitos, CA, USA, pp 160–167 https://doi.org/10.1109/SOSE.2017.33
Yue R, Gao Z, Meng N, Xiong Y, Wang X, Morgenthaler JD (2018) Automatic clone recommendation for refactoring based on the present and the past. In: IEEE International Conference on Software Maintenance and Evolution (ICSME), pp 115–126 https://doi.org/10.1109/ICSME.2018.00021
Zheng P, Zheng Z, Luo X, Chen X, Liu X (2018) A detailed and real-time performance monitoring framework for blockchain systems. In: International Conference on Software Engineering Software Engineering in Practice - ICSE-SEIP ’18, p 134–143 https://doi.org/10.1145/3183519.3183546
Zheng Z, Xie S, Dai H, Chen X, Wang H (2017) An overview of blockchain technology: Architecture, consensus, and future trends. In: IEEE International Congress on Big Data (BigData Congress), p 557–564 https://doi.org/10.1109/BigDataCongress.2017.85
Zhu J, He P, Fu Q, Zhang H, Lyu MR, Zhang D (2015) Learning to log: Helping developers make informed logging decisions. In: Proceedings of the 37th International Conference on Software Engineering - Volume 1, IEEE Press, Piscataway, NJ, USA, ICSE ’15, p 415–425. http://dl.acm.org/citation.cfm?id=2818754.2818807
Author information
Authors and Affiliations
Corresponding author
Ethics declarations
Conflict of Competing Interests
The authors declared that they have no conflict of interest.
Additional information
Communicated by: Daivd Lo.
Publisher's Note
Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.
Rights and permissions
Springer Nature or its licensor (e.g. a society or other partner) holds exclusive rights to this article under a publishing agreement with the author(s) or other rightsholder(s); author self-archiving of the accepted manuscript version of this article is solely governed by the terms of such publishing agreement and applicable law.
About this article
Cite this article
Chen, X., Liao, P., Kong, Q. et al. Studying differentiated code to support smart contract update. Empir Software Eng 28, 119 (2023). https://doi.org/10.1007/s10664-023-10359-y
Accepted:
Published:
DOI: https://doi.org/10.1007/s10664-023-10359-y