Despite the recent downturn in the crypto market, there are still some extremely interesting and worthwhile projects that are undergoing development. For every Dogecoin and Elon Musk-related headline that questions the legitimacy of blockchain as a truly innovative force, there is an exciting venture that receives less attention.
While some projects inevitably don't get off the ground, there are some that show us what blockchain can be capable of in the right hands. One such example is the Worldcoin project, which aims to equitably distribute wealth through cryptocurrencies to citizens around the world. Other projects gaining attention are Ethereum 2.0, TrueFi, and PolkaFoundry.
A Developing DeFi Ecosystem -- Innovation and Risk
What we have seen so far in 2021 is:
- There is a great amount of development occurring, regardless of the volatility in the crypto market.
- Much of this development is occurring in the DeFi and NFT space.
- It is becoming easier to create DeFi applications with the help of third-party development environments and services.
The DeFi space, running on smart contracts, has indeed gone from strength to strength, and while we can be happy that there is so much fertile ground for development, the rush to release new products before competitors can result in vulnerabilities. From Hegic's $48k to Bancor's $23.5 million in losses, smart contract vulnerabilities can be devastating -- they not only damage or sink a project, but also scare off investment in the wider DeFi ecosystem.
What Is a Smart Contract Audit?
Despite smart contracts being in the crosshairs of cybercriminals, there is frequently still a "test in production" mindset that developers adopt.
A smart contract audit involves a specialized team looking for bugs in a smart contract's code, analyzing areas that could be manipulated by hackers, or examining code that goes against common convention. While we often think of smart contract audits in terms of security, they can also be beneficial in terms of diagnosing areas that can be made more efficient.
Whether you are a newcomer to the DeFi development market or an experienced team that needs a fresh set of eyes, a smart contract security audit can be a lifesaver, protecting your smart contracts from critical vulnerabilities.
Smart Contract Auditing -- Things to Consider
Creating a functional application on a blockchain is not such a simple task. There are lots of different factors to consider, from the blockchain and language used, to the development environment and workflow.
Preventing Code Vulnerabilities
Looking for code vulnerabilities is one of the main functions smart contract audit companies will undertake. DeFi's public-facing code can be scrutinized and exploited by bad actors, leading to oracle manipulations, reentrancy attacks, and other bug exploits. Here are some ways safety can be improved before it gets to the auditors:
- Do the basic checks -- Logic and numerical errors to do with incorrect calculations are common.
- Ensure proper access control -- Make sure all authorized parties have the correct access and unauthorized parties can't slip through.
- Use security tools to test throughout development -- Security testing tools are everywhere and often free. Run tests throughout the entire development process.
- Keep the code simple -- Write the simplest code possible to achieve the aim. Needlessly complex code increases the risk of a security incident.
Smart Contract Auditing Steps
Depending on the complexity, the time estimate for a security audit can be anywhere from 1 day to 2 weeks.
Project Familiarization
Auditors review the white paper and often ask the development team to explain their architecture.
Code Freeze
Auditors request the date when the code will be at the stage where it can be tested.
Code Review
Reviewers understand certain aspects of the code, such as the design and libraries used. The closer to 100% the test coverage is, the fewer bugs will make their way through testing.
Automated Analysis
Before manual testing begins, a quick automated check can resolve some of the more obvious issues early on.
Manual Analysis
Manual analysis requires not only technical skills, but also an understanding of the project and developer's intentions. A manual reviewer can uncover problems with the code and also test for desired functionality.
Known Vulnerability Analysis
A line by line audit of code against vulnerabilities is essential, testing against things such as:
- Denial of Service (DOS) Attacks
- Gas Limit Issues
- Insecure Random Number Generation
- Overflows and Underflows
- Reentrancy Attacks
- Timestamp Dependencies
- Variable Shadowing
The best practice is to list the vulnerabilities in order of seriousness: critical, high importance, medium priority, low priority.
Live Testing
Deploying code on a local testnet, with white-hat hackers trying to manipulate the smart contract.
Audit Reports / Code Adjustments / Final Audit Report
Following extensive testing, auditors write a detailed report with findings and recommendations. Depending on the number of bugs, this process may be repeated 3 or 4 times before the final audit is issued.
Securing Your NFT
NFTs run on smart contracts as well, so the need for an audit is just as important. The smart contract auditing steps can be applied but customized to simulate the payment and transfer of NFTs. Auditors can also provide advice on regulatory compliance when assets are transferred across borders.
Final Thoughts
While smart contracts are powering the DeFi and NFT sectors to new heights of innovation, it is important to remember that each attack erodes trust. A smart contract audit makes sure your code is not just secure, but can run at optimum efficiency. INC4 has been working with blockchain, DeFi, and smart contracts since 2014, helping over 90 projects realize their potential.