A “smart contract” is a set of instructions that run on Ethereum Blockchain. To audit, an ethereum smart contract means to ensure that it is secure from potential threats and common vulnerabilities.
While in the present scenario, the hacks, and exploits related to smart contracts are at an all-time high, it’s a storm to be praised for because it’s resulting in advancements & improvements for DeFi platforms, which makes them more secure.
When we speak about the security of smart contracts, we cannot let go of the “importance of smart contract audits.” Smart contract audit is a process to cross-verify smart contract codes based on various parameters. And in the forthcoming sections, we will analyze the importance of smart contract auditing, multiple approaches to smart contract auditing, and steps involved in auditing an Ethereum smart contract.
Importance of Smart Contract Audit
To better understand why any stakeholder would require smart contract auditing, we need to look into the recent past and see the voluminous losses incurred across various DeFi platforms.
- Poly Network : $600 million loss
- Lendf.me – $25 mln loss;
- Synthetix – 37 mln sETH loss;
- bZx – $645 000 loss.
These are just a few recent hacks. As per a new report-
“DeFi Has Accounted for Over 75% of Crypto Hacks in 2021. That works out to $361 million, 2.7 times more than in 2020. ”CipherTrace
Those huge numbers are scary, but these attacks could have been mitigated easily if those DeFi platforms could have taken preventive measures. While some of the attacks may be severe, most of them could have been easily averted.
One of the best ways to keep your DeFi platform safe from potential future threats is to get yourself familiar with all the past attacks. To do so, one of the best resources is the SWC registry that presents a list of all smart contract vulnerabilities and examples to tackle them.
Source: SWC registry
So what are those golden steps of smart contract auditing that, when followed, could help various DeFi platforms save millions?
Universal Approaches to Smart Contract Auditing
There are two widely adopted methods for smart contract auditing:
- Manual Code Analysis
- Automatic Code Analysis
Manual Code Analysis
It is the process of examining the code line-by-line to identify the potential vulnerabilities. It’s a complex process that requires skill, experience, persistence, and patience. To improve the security of the DeFi project, going through the Manual code analysis is substantially the best way to identify the vulnerabilities that the Automatic code analysis may leave.
Most often, we come across a very frequent question – “How many people should make up the code review team?”. At QuillAudits, we put the security of the project first; hence we have a review team of experienced and skilled auditors to look into the dynamics of the smart contract code.
Though there are some limitations of the manual code analysis, such as Buffer overflows (especially “off-by-one” errors), dead code, and some other mistakes that may sometimes get overlooked by a human reviewer, they are better suited for automated analysis to find them.
Automatic Code Analysis
Automatic code analysis saves time and money as it uses various penetration tests to find vulnerabilities. We at QuillAudits leverage various in-house open-source tools to maximize the outcomes for security audits. Some of the best-in-class tools used by our in-house auditors are:
- MythX – A smart contract security service that examines your project based on static analysis, dynamic analysis, and symbolic execution. To use MythX requires an API key from mythx.io.
- Mythril – A security analysis tool for Ethereum smart contracts. It examines a range of security issues – integer underflows, owner-overwrite-to-Ether-withdrawal, and others.
- Slither – A static analysis framework written in Python 3, it identifies vulnerabilities & prints visual information about contract details, and provides an API for the custom analysis to be written flexibly.
- Echidna – A weird creature that eats bugs! A Haskell program developed for fuzzing/property-based testing of Ethereum smart contracts.
- Oyente – To analyze Ethereum code to find vulnerabilities.
That was just a concise list of tools leveraged by our in-house team of auditors to carry out automatic code analysis. But what are those golden steps to carry out a smart contract audit?
Steps to Audit an Ethereum Smart Contract
Though there may be more than one reason to carry out a smart contract audit, the primary motive is to secure your Defi platform. We at QuillAudits follow a comprehensive methodology to conduct a smart contract audit.
#1: Gathering Code Design Patterns
It is one of the foremost steps in carrying out a smart contract audit. For the company carrying out audits, it is important to have a clear understanding of the code and working specifications of the smart contract platform.
#2: Unit Testing
We carry out smart contract unit testing with the help of various code coverage tools. We also implement unit test cases to verify each function works coherently with the overall smart contract code.
#3: Manual Analysis
Sometimes automated analysis may result in false-positive reports; hence doing line-by-line manual research becomes necessary to find potential vulnerabilities like – race conditions, transaction-ordering dependence, timestamp dependence external calls, and denial of service attacks.
#4: Initial Report
We then present before you an initial report with all the bugs and errors that are to be fixed by your team.
#5: Code Fixed
Fix all the bugs and errors discovered in the preliminary analysis and then send it to the auditors for the final review.
#6: Static Analysis & Formal Verification
We perform code reviews using our in-house open-source automated tools to detect any loopholes, malicious codes in the smart contract.
#7: Final Audit Report
The final audit report is presented before the client and published on GitHub for anyone to refer to.
This is the comprehensive strategy that our in-house team of skilled auditors follows, though it is visible that your smart contract is being audited twice at the same price.
While auditing a DeFi project once doesn’t guarantee its security, we recommend it be audited at least twice (or) thrice. In the past, there have been incidents such as the “Popsicle Finance” hack for $20M. It was audited twice, but it was also exploited due to a common vulnerability.
Therefore, incidents like this clearly outline the importance of smart contract auditing – “the more, the better!“.
Well, if you have been with us till here, you are familiar with how an ethereum smart contract is audited.
While the rising number of DeFi hacks and exploits may alarm you, carrying out a robust smart contract audit from a trustworthy firm such as QuillAudits will save you millions of dollars.