QuillAudits
Security State Of DeFi And Risk Mitigation Ideas
It’s shocking that 97% of the cryptos lost in the first quarter were from DeFi protocols. And that says a lot about how far the DeFi has to grow from a security perspective.
Let’s touch upon the recurring hacks practised in DeFi and how to smartly tackle the security of DeFi in this article.
Flash loans are one such possibility where hackers confide in to make profits. Flash loans are borrowed from DeFi platforms without collateral but are obliged to return the funds within the same transaction. Please do so to avoid the transaction being cancelled or reverted.
Hackers utilize such loans to manipulate the prices by selling the tokens in bulk and lowering the costs in the trading exchange. With the price data fed into the smart contract from the external sources, which the hacker has manipulated, they manage to make huge gains while repaying the loan.
Here again, diversified coding for exceptional performance may have severe bugs, which, if hackers spot, would be a jackpot for them to loot away the riches from the DeFi platform. For example, mathematical logic errors, inappropriate use of functions, etc., opens the gateway for hacks.
External services like Oracles supply timely data relevant to executing the function by smart contracts. Hackers can easily modify these data, which are externally fed, by understanding the nuances of it. With this, they can make the logic crash and win millions.
Mostly– not always- these over-hyped tokens are not an ideal option for investing as they are nothing but valueless tokens circulated to be rug-pulled later. Rug-pull scams are the new trend in DeFi that is performed by exploiting the user’s unfamiliarity with the immature space.
Phishing scams are always persistent, wherein users’ lack of knowledge and attention to detail makes it easier for hackers to grab hold of sensitive information and mess up the holdings.
Recently, hackers compromised a Curve website or domain name to redirect unwitting users or their transactions to a malicious destination. Hackers made around $570,000 in ETH from the attack.
Hackers also compromise projects' social accounts, especially Discord and Twitter accounts. The attack starts with the attacker compromising the Protocols discord servers. The attacker commonly uses phishing, social engineering, bots, etc., to compromise Discord servers. After compromising the servers, scammers succeed when they can trick users into connecting wallets to their malicious websites.
DeFi projects pay a huge amount to influencers or celebrities for endorsements, helping to increase their price due to a surge in demand. Once investors start buying tokens, the price will go up. When the price reaches a certain point, the projects sell all of their shares. It causes a huge price drop, leaving all investors with nothing.
However, the security gaps can be bridged through the enforcement of critical measures.Errors are part of the blockchain experience, but it is tremendously dangerous if these events go unnoticed, as it would disrupt the project altogether. To eliminate the risk of facing such an unimaginable scenario, security audits spot the threats coming beforehand, saving smart contracts. Smart contract audits focus on code efficiency before deployment and verify that all interactions are safe. It ensures meaningful security that is uncompromisable. Projects can host their bug bounty program or integrate with Bug Bounty Platforms like Immunefi or Hackerone. It adds an extra layer of security for the projects. Even if everything seems to be fine and the contract is running smoothly, it is very much required that it is protected. Decentralized insurance protects user funds locked in DeFi protocols, and they can be assured of the security of the capital.51% of projects hacked are unaudited. Therefore, paying attention to security as a part of the development can significantly bring down DeFi’s share of fund loss and strengthen web3 security.
Smart contracts are conditions programmed and encrypted in a blockchain to execute and run transactions automatically. They will refuse transactions upon any breaches of the conditions.
Read more: How do smart contracts work?
The auditors start with defining all agreements between the business and other participants: scope, parameters, acceptance criteria, and exceptions (if any.) Moreover, they also need to deeply study project documentation which describes how the blockchain is built and tested.
Also check: Top practices of smart contracts
· Preventions against underflow and overflow
· Function visibility
· Fix nuance warnings to avoid problematic features
· Checking for all external calls such as reentrancy or short circuits
· Using trustworthy and audited dependencies
· Time manipulation within several minutes only
· Being aware of rounding errors and unexpected behaviors
· Cut down on pseudo-randomness
· Validation of public or external functions
· Preventions against unbounded loops
· Correct usage of push payments
· Frequent updates of old solidity constructs
· Change verification using the latest solidity versions
Above are high-risk areas that attackers often target.
What to check:
· Test coverage for 100% branches
· Run unit tests to cover critical edge cases
· Also, have additional tests for integrations
· Freeze recent code written under a tight deadline
Blockchain also requires resilience because of the large number of data amount and participants worldwide. The technology is also at increased risk of attacks.
Resilience testing includes endurance, compliance, load, and recovery tests to ensure that smart contracts can bounce back after interruption or disturbance of some sort.
Importantly, auditing is not all about the verification of code. During the process, auditors must also create reports including bugs, suggestions for fixing, potential changes to upgrade the smart contracts and the blockchain systems, coding practices, and documentation quality.
Smart contract auditing must also be done on a frequent basis, both manually and automatically, using tools.
Having a smart contract audit checklist is critical and good to start. However, following the checklist is not an easy task.
Never put your DeFi security down!
Besides the golden rules above, you should remember that there is hardly a comprehensive list to cover all potential vulnerabilities. The more blockchain and DeFi grow, the more sophisticated attempts hackers create to exploit the systems and steal your money.
HASHEX