1. Trang chủ
  2. » Luận Văn - Báo Cáo

Optimizing smart contracts on ethereum

58 2 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Nội dung

HANOI UNIVERSITY OF SCIENCE AND TECHNOLOGY MASTER THESIS IN DATA SCIENCE AND ARTIFICIAL INTELLIGENCE Optimizing smart contracts on Ethereum NGUYEN QUANG THANG thang.nq202710m@sis.hust.edu.vn Supervisor: Dr Do Ba Lam —————————————Institution: School of Information and Communication Technology HANOI, 04/2022 Declaration of Authorship and Topic Sentences Personal Information • Full name: Nguyen Quang Thang • Email: thang.nq202710m@sis.hust.edu.vn • Class: Data Science • Tel: 098 669 1647 • Program: Full-time program • This thesis is performed at: School of Information and Communication Tech-nology • This thesis is performed: from 10/04/2021 to 10/04/2022 Goals of the Thesis • Proposing optimizing rules on smart contract source codes using Solidity lan-guage • Developing a tool named GasSaver, an automatic tool for detecting the wasting-gas Solidity source codes and suggesting solutions • Conducting experiments and evaluating GasSaver Main Tasks of the Thesis • Study on the blockchain, smart contract, and optimizing smart contract gas fee on Ethereum • Collect and analyze the typical wasting gas issues on Solidity smart contract • Present seven rules for reducing the gas fee on the smart contract • Develop a tool name GasSaver, which implements the seven rules above to automatically detect the wasting-gas Solidity source codes and suggest solu-tions for these issues • Implement experiments and evaluation GasSaver efficiency • Conclude and outline future developments Declaration of Authorship I - Nguyen Quang Thang - hereby warrant that the work and presentation in this thesis are performed by myself under the supervision of Dr Do Ba Lam All results presented in this thesis are truthful and are not copied from any other works Attestation of the Supervisor on the Fulfillment of the Requirements for the Thesis: Hanoi, 10th Apr 2022 Author Supervisor Dr Do Ba Lam Nguyen Quang Thang Acknowledgements I want to acknowledge and give my warmest thanks to my supervisor, Dr Do Ba Lam He is an excellent blockchain researcher, gave me the golden opportunity to this research on optimizing gas fees on the smart contract, which also helped me a lot of research, and I came to know about so many new things Not only that, he is very kind and friendly and inspired me a lot in my research career path I would also like to give a special thanks to my girlfriend Nguyen Thi Tham and my family for their mental support during my thesis writing process Moreover, in the absence of my friends, Tong Van Vinh, Hong Ngoc, Xuan Thu, and Thanh Dat, I could hardly melt away all the tension from my work I also thank Thanks for always accompanying me through ups and downs Abstract Currently, the number of smart contracts using Solidity language in Ethereum is increasing at a breakneck speed In this context, optimizing gas fees in smart contracts becomes necessary to save costs for both developers and users who interact directly with these contracts To optimize gas, developers typically need to have deep knowledge of blockchain and programming languages, making it a significant challenge for new programmers This thesis, we introduce GasSaver – an open-source tool that analyzes Solidity-based contracts and suggests modifications to reduce transaction fees Our tool, which relies on seven rules for identifying nonoptimized codes, shows that 6,333 in a total of 10,245 top most interactive contracts on Ethereum contain at least one optimization problem and the problems are more than 30,000 Hence, the use of this tool can reduce a considerable cost for the deployment and interaction of smart contracts Author Nguyen Quang Thang Table of Contents Declaration of Authorship and Topic Sentences Acknowledgement Abstract Lists of Figures Lists of Tables 10 Lists of Listing 11 Background and related work 15 1.1 Blockchain 1.2 Ethereum and smart contracts 1.2.1 Ethereum blockchain 1.2.2 Smart contracts on Ethereum 1.2.3 Ethereum Virtual Machine (EVM) 1.2.4 Gas and payment 1.2.5 Solidity - a high-level language for developing smart contracts 1.3 Related work 1.3.1 Bytecode related work 1.3.2 High-level language related work 1.3.3 Evaluation Gas-inefficient Programming Patterns 15 17 17 18 19 20 21 23 23 26 26 27 2.1 Data Representation 2.1.1 Pattern 1: Members Arrangement in Struct (MAS) 2.1.2 Pattern 2: Data Location and Function Visibility (DLFV) 2.1.3 Pattern 3: Constant State Variables (CSV) 2.1.4 Pattern 4: Immutable State Variables (ISV) 2.2 Logic Relation 2.2.1 Pattern 5: Operator Reduction in Expression (ORE) 2.2.2 Pattern 6: Repeated Computation in Loop (RCL) 2.2.3 Pattern 7: Loop Combination (LC) 2.3 Sumnary Implementation 27 27 29 31 32 34 34 35 37 38 39 3.1 System Design 39 3.2 Rule Implementation 40 3.2.1 Members Arrangements in Struct 40 3.2.2 Data Location and Function Visibility 3.2.3 Constant State Variables 3.2.4 Immutable State Variables 3.2.5 Operator Reduction in Expression 3.2.6 Repeated Computation in Loop 3.2.7 Loop Combination Experiments and Evaluations 42 43 43 44 44 46 48 4.0.1 4.0.2 4.0.3 4.0.4 References 48 49 49 51 56 Optimization Findings Execution Time Comparison Evaluation List of Figures Opensea - the most prominent digital marketplace for crypto collectibles and non-fungible tokens [1] 1.1 Blockchain model networks 13 15 1.2 Ethereum state machine mechanism 3.1 System Overview 17 39 3.2 The example output of GasSaver with Members Arrangements in Struct issue 3.3 The example output of GasSaver with Data Location and Function Visibility issue 3.4 The example output of GasSaver with Constant State Variables issue 3.5 The example output of GasSaver with Immutable State Variables issue 3.6 The example output of GasSaver with Operator Reduction in Expression issue 3.7 The example output of GasSaver with Repeated Computation in Loop issue 3.8 The example output of GasSaver with Loop Combination issue 4.1 Distribution of Violations on the First Dataset 4.2 4.3 4.4 4.5 4.6 Distribution of Violations on the Second Dataset Time Executions on the First Dataset Time Executions on the Second Dataset Violations on the First Dataset of GasSaver and Tamara’s tool Time comparison of GasSaver and Tamara’s tool 42 43 44 45 46 46 47 49 50 50 51 52 52 List of Tables 1.1 EVM operation gas 1.2 EVM operation gas 2.1 Costs of deployment 2.2 2.3 2.4 2.5 2.6 2.7 2.8 4.1 cost overview 22 refund overview 23 and function call in Listing 2.1 29 Costs of deployment and function Call in Listing 2.2 Costs of deployment and function call in Listing 2.3 The difference in assembly code in Listing 2.3 Costs of deployment and function call in Listing 2.4 Costs of deployment and function call in Listing 2.5 Costs of deployment and function call in Listing 2.6 Costs of deployment and function call in Listing 2.7 Costs of deployment and function call in SAC Contract 10 31 32 32 34 35 36 38 54

Ngày đăng: 04/06/2023, 11:33

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w