Litecoin: Satisfying Codebase with Room for Improvements
The quality of code is essential for successful blockchain solutions. Poor code with errors is one of the biggest enemies of DLT systems. Therefore, we analyzed the codebase of Litecoin. The analysis showed an overall satisfying result. The codebase of Litecoin demonstrated a higher quality, than the previous analyzed Ethereum. Nevertheless, the code is not perfect and there is still room for improvements. — Authors: Christian Flasshoff, Philipp Sandner
The Institute for Crypto Asset Analysis (ICAA) analyzes the underlying code of cryptocurrencies and other DLT solutions. Automated algorithms determine a score about the quality of the code, which is easy to understand and comparable. In the case of Litecoin we analyzed over 600,000 lines of code and identified issues in less than 20,000 lines of code. In most cases the issues were minor and not critical but there are also sections of the code, which require improvements by developers. ICAA aims to provide an innovative approach of reviewing the code of cryptocurrencies and to help investors, analysts and other blockchain enthusiasts in the decision-making process. Prior to the details of the analysis of Litecoin, let us take a look at the blockchain technology itself. For everyone who is familiar with the concept of Litecoin, feel free to skip this section and continue reading in the next section.
The technology behind Litecoin
The cryptocurrency Litecoin was first introduced in the year 2011 by the former Google employee Charlie Lee. The Litecoin is based on the open source protocol of the Bitcoin, with several changes in the technology. By searching the Litecoin website, one can find the following definition: “Litecoin is a peer-to-peer Internet currency that enables instant, near-zero cost payments to anyone in the world.” As already known from the Bitcoin every transaction in the Litecoin network is stored on a public ledger (Blockchain) and has to be verified by a decentralized network of computers (nodes). Further, miners are rewarded by new Litecoins for verifying the transactions, until the maximum of 84 million released coins is reached. So far so good, but what makes the Litecoin different from its precursor Bitcoin?
A common critic of the Bitcoin protocol is the slow confirmation time of transactions. This time depends on the interval between each new created block (group of transactions) on the blockchain. The Litecoin network creates every 2.5 minutes a new block (compared to 10 minutes for Bitcoin blocks). As a consequence, the Litecoin can handle a higher volume of transactions than the Bitcoin, which is favorable for fast payments. In addition, the Litecoin makes use of a different mining algorithm, which is responsible for the creation of new coins. Bitcoin uses a rather processor intensive “SHA-256” algorithm, while Litecoin is powered by a memory intensive “scrypt” algorithm. This might seem trivial but can result in very different scenarios. Over the time, the mining process of Bitcoins requires more and more computing power and standard CPUs or GPUs are unable to perform the SHA-256 calculations profitably. Therefore, the mining of Bitcoins requires Application Specific Integrated Circuits (ASIC), which are specially designed for the purpose of mining and are mostly operated by larger mining facilities. The Litecoin on the other hand was designed to be mined sustainable on normal devices to make it accessible to everyone in the network. The scrypt algorithm, which is memory intensive rather than processor intensive, makes mining less efficient on ASIC devices and helps everyone to participate in the Litecoin network.
Review of the Litecoin codebase
Litecoin is equipped with peer-to-peer payment features, which are defined in the codebase of Litecoin. The Litecoin software is based on the Bitcoin protocol and is distributed across the network. The software functions as a backbone of the cryptocurrency project, which depends on the quality and security of the codebase. Analyzing the codebase of Litecoin helps to unveil code issues and to ensure the long-term success of the technology. In our innovative approach, the software automatically analyzed the C++ codebase of Litecoin and determined the quality of the code. Since the Litecoin code is published under the permissive free MIT/X11 software license, the codebase is easy accessible on GitHub.
The specialized algorithms of the system automatically define a score for cryptocurrencies on a scale from -5 (worst score) to +5 (best score). This classification makes it easy to interpret the results and to compare it to other blockchain solutions. Technical remark: Our analysis is based on the Litecoin code version from 2018–02–21 and draws comparisons to a release of the previous analyzed Ethereum code from 2018–03–12.
Analysis: Litecoin has a solid 2.54 score on a [-5,+5] scale
At this point, it is interesting to know, which score was reached by the Litecoin code. The cryptocurrency scores solid 2.54 with potential for further improvements. In order to classify this result, the second largest cryptocurrency, Ethereum, scores only 1.69 and is ranked clearly behind the Litecoin. In the following, we will examine the reasons behind this result and break down the score into four categories: design, metrics, duplications and code issues. Every category is represented by an individual score, which allows to narrow down the issues to the components of the codebase or even the exact lines of code. Figure 2 visualizes all of the subcategories of the Litecoin version from 2018–02–21. In the following, each category is explained in detail and the results will be interpreted. As always, this part might be a little bit more technical but still plausible for non-coders.
Design issues. In this category the codebase is analyzed in terms of the design of the code. A good code design is characterized by an easy to follow and efficient structure. Even though the functionality of software with well-designed code or less well-designed code might be the same, it is desirable to develop code that every programmer understands easily. As mentioned in the previous review, the algorithms automatically inspect the design of the code and can detect anti-patterns. Anti-patterns are parts of code that appear to work but are not optimal constructed. Such patterns normally arise over time when new functionalities are attached or when changing developers contribute to the code. Anti-patterns may result in errors and make maintenance of the code very difficult. There are several types of anti-patterns. In this review, we focus on the Brain class. This class is very complex and executes significant amount of system intelligence. Such a class includes also several Brain methods, which are characterized with complex functions and many lines of code. Since, this class is non-cohesive, the methods are separated and spread across the code. As a consequence, the low cohesion impacts understandability, maintainability and testability. Brain classes are undesirable and should be avoided. There are also several other anti-patterns, but this article cannot cover all of them. More important are the results of the design analysis. The Litecoin code has a total number of 1,513 anti-patterns. This sounds like a large number, but we have to evaluate this number in proportion to the over 600,000 lines of code in total. In addition, only 231 issues are ranked “high”, which relativizes the high number of issues even further. Most of the “high” design issues are located in the “qt” component (67), followed by the “wallet” (25) and the “rpc” (19) component. The evaluation of the design issues concludes with a score of 3.08. Figure 3 shows an example of anti-patterns within the “wallet” component. Here we can see several Brain methods (e.g. line 922) within this component, which together can be classified as a Brain class. It is also important to mention, that Litecoin achieved a higher score than the previous analyzed Ethereum, which scored only 2.29. In contrast to Ethereum, the design score of Litecoin increased over the course of development. The 2018–02–15 snapshot of the Litecoin’s codebase reached only a score of 2.60 compared to the 3.08 current score. We can therefore conclude that the Litecoin codebase increased in terms of design quality over the last developments and showed better results than Ethereum.
Metric violations. The next category tracks the quality of the code with software metrics. Such a metric is for example “number of methods” (NOM). This metric counts the total number of methods (functions) in one class. It is obvious that a higher number of methods makes the code more complex and increases the risk for errors. Other metrics are for example “lack of cohesion in methods” (LOCM), which measures the cohesiveness of a class or “access to foreign data” (ATFD), which measures the frequency of access to external attributes from other classes. In order to determine the quality of the code, the system we used reports when an undesirable threshold of a metric is exceeded and calculates a score for metric violations. The Litecoin code shows a total number of 6,114 metric violations, which can be translated into a score of 1.93. Compared to the Ethereum code (0.47), which showed less than 1,000 metric violations, this number seems large. However, taking into consideration that Litecoin has 20-times more lines of code than Ethereum justifies for the better score of Litecoin.
Duplications of code. As the name already implies, the category duplications searches for duplicated code. Duplicated code is usually undesirable, since it may increase the lines of code, lowers the performance or increases software vulnerability. The Litecoin codebase shows a desirable score of 4.29 and only 0.75% of the code is duplicated. This result is slightly better than the outcome of the Ethereum analysis but both cryptocurrencies show very good scores in this category.
Code Issues. The last category focuses on code issues. In contrast to design issues, code issues apply only to a local part of the code. Depending on the characteristics of the issue, the impacts on the performance of the software may vary. Therefore, it is important to classify the implications of the detected code issues. The innovative algorithm defines the criticality within the categories of low, medium, high and critical. The result of the Litecoin codebase in this category unveils 312 code issues. Even though this number is slightly smaller compared to the Ethereum code, the overall code issue score concludes at -0.07. This result can be explained by the distribution of the code issues within the Litecoin code. Almost 20% of the issues fall into the category of high or critical issues. The majority of these issues is located in the “miner.h” component, with a total number of 17 high code issues. Figure 4 represents an example of the code issue in this component (line 69 and 94). In this example the variable was not introduced in the constructor. The remaining code issues (80%) are classified as low or medium. An example for a low code issue would be an unused label within the code. Such an unused label does not interfere with the correct functionality of the software but could be removed to make the code more compact. Software with less code issues tends to run more stable and should be the goal of every programmer. The occurrence of code issues is common in computer programming and is part of the development process. Nevertheless, the removal of code issues is necessary to improve the software. Compared to earlier releases of Litecoin, the score for code issues was almost the same.
Summary: Overall the codebase of Litecoin is satisfying
The Institute for Crypto Asset Analysis analyzes the codebase of cryptocurrencies with automatic algorithms and translates the results into a score. In the case of Litecoin, we encountered an overall satisfying codebase with room for further improvements. Summarizing the results into hotspots according to the urgency of the issue, shows that 8 components of the code contain critical issues, 17 components are ranked as high and 33 components fall into the category of medium criticality. As Figure 5 shows, most of the hotspots can be located in the “wallet” and “qt” component. The majority of the issues can be traced to the category of code issues, which unveiled by far the worst score among all of the categories in Litecoin. Even though the code seems to function correctly, developers should review the critical sections of the code. The comparison of the Litecoin analysis with the previous code review of Ethereum resulted in better or similar results for the Litecoin codebase in all four categories. These findings can be confirmed with an overall better score for Litecoin.
In the future it will be interesting to monitor new developments of the Litecoin code and to see whether the code will be improved in terms of code quality. In addition, the Institute for Crypto Asset Analysis continues to compare the results to other cryptocurrencies in order to determine which blockchain solution has the highest code quality.
The results shown in this paper are based upon an automatic analysis of the code. Please note that this analysis does neither represent financial advice, nor is it supposed to be understood or interpreted as solicitation to buy or sell any securities, coins or tokens.
If you like this article, we would be happy if you forward it to your colleagues or share it on social networks. If you are an expert in the field and want to criticize or endorse the article or some of its parts, feel free to leave a private note here or contextually and we will respond or address.
Do you want to learn more about how blockchain will change our world?
- Blockchain knowledge: We wrote a Medium article on how to acquire the necessary blockchain knowledge within a workload of 10 working days.
- Our two blockchain books: We have edited two books on how blockchain will change our society (Amazon link) in general and the everything related to finance (Amazon link) in particular. Both books are available in print and for Kindle — currently in German and soon in English. The authors have been more than 20 well-known blockchain experts in startups, corporations and the government from Germany, Austria, Switzerland and Liechtenstein — all contributing their expertise to these two books.
Prof. Dr. Philipp Sandner has founded the Frankfurt School Blockchain Center (FSBC). From 2018 to 2021, he was ranked among the “top 30” economists by the Frankfurter Allgemeine Zeitung (FAZ), a major newspaper in Germany. He has been a member of the FinTech Council and the Digital Finance Forum of the Federal Ministry of Finance in Germany. He is also on the Board of Directors of FiveT Fintech Fund, 21e6 Capital and Blockchain Founders Group — companies active in venture capital financing for blockchain startups and crypto asset investment management. The expertise of Prof. Sandner includes crypto assets such as Bitcoin and Ethereum, decentralized finance (DeFi), the digital euro, tokenization of assets, and digital identity. You can contact him via mail (email@example.com) via LinkedIn or follow him on Twitter (@philippsandner).
Christian Flasshoff is research fellow at the Frankfurt School Blockchain Center and Alumni of the Frankfurt School of Finance & Management. You can connect with him on LinkedIn (www.linkedin.com/in/christian-flasshoff) or contact him via mail (firstname.lastname@example.org).