header-langage
简体中文
繁體中文
English
Tiếng Việt
Scan to Download the APP
Partnered With:

a16z: Smart Contract Security Guidelines for Web3 Projects

Read this article in 8 Minutes
Doing these 8 points well can maximize the prevention of hacker attacks.
Original title: "a16z: A Smart Contract Security Guide for Web3 Projects"
Original author: Andy Beal, Nassim Eddequouaq, Riyaz Faizullabhoy & Christian Seifert, a16zcrypto
Original compilation: Katie Koo, Odaily Planet Daily


Usually, hackers will find and exploit flaws in the entire process chain of software development (from design to deployment to maintenance) to break the security of blockchain projects barrier. If the relevant experience can be learned in advance, I believe that there will be much fewer safety accidents.


This article outlines the security elements that Web3 developers and security teams must consider when designing, developing and maintaining smart contracts, covering from threat modeling to emergency response The entire cycle of preparation.


Developing a secure software consists of the following five phases:


- Design: Development The person describes the required functionality and operation of the system, including important baselines and fixed properties;

- Development: The developer writes the system code;

- Testing and review: The developer puts all Modules are assembled in a test environment and evaluated for correctness, size, and other factors;

- Deployment: Developers put the system into production;

- Maintenance: Developers evaluate and modify the system to ensure it performs as intended.


The diagram below maps the security factors that need to be considered to the above stages.


a16z: Smart Contract Security Guidelines for Web3 Projects


It is important to note that the software development life cycle does not always follow a linear path: categories may overlap or extend into other phases. Steps may be repeated for each release. Some security tasks, such as testing and security reviews, may need to be followed through.


The software lifecycle steps and corresponding security considerations described above provide the basis for facilitating smart contract security. In the following, we will conduct more detailed research on three issues.


1. Smart contract security considerations in the design phase - consider threat modeling and security design


< p>Content: Clearly identifying and prioritizing potential threats to the system from the early stages of the project development life cycle is key. Smart contract developers should identify all security controls to implement during development, and threats that should be checked for during testing, auditing, and monitoring. All security assumptions, including the expected sophistication and economic means of an attacker, should be clearly defined and articulated during the design phase.


While it is very tempting for developers to focus only on the intended use of a smart contract or protocol, this sole focus may leave them "Blind spots" can be exploited by attackers.


Method: Follow known threat modeling practices. If a development team does not have security experts in-house, it should engage security consultants early in the design phase. Design systems with an "attacker" mentality and presuppose that any person, machine or service can be attacked.


2. Security considerations in the development phase - management considerations and access control


Content: Implement access controls that limit the ability to privileged accounts and smart contract calls to special functions that perform administrative tasks such as upgrading contracts and setting special parameters. Follow the "principle of least privilege" - each participant should only have the minimum amount of access needed.


Reason: Maintaining the protocol through the upgrade and governance process allows developers to improve the protocol by adding new features, patching security issues, and addressing changing conditions. This could constitute a serious security breach if upgradeability is not properly controlled.


Approach: Create a multi-signature wallet or DAO  contract to transparently manage changes on behalf of the community. Changes should go through a thorough review process and have a time-lock (deliberately delaying the enactment of regulations with the ability to cancel them) to ensure their correctness can be verified and rolled-back in the event of a governance attack. Ensure that privileged keys are securely stored and accessible in a self-custodial wallet or safekeeping service.


3. Consider reusable, battle-tested templates and integrations


Content: Leverage existing smart contract standards (such as OpenZeppelin contracts) where possible, and evaluate security assumptions that may require protocol integration with existing protocols.


Why: Using existing battle-tested, community-audited standards and implementing measures to mitigate security risks can be of great help. Assessing the risks of protocol integration helps to develop security checks to prevent attacks on external components such as oracle manipulation.


Method: Import trusted contract libraries and interfaces that have passed security audits. The focus of Web3 is on open source usage, reusability and composability. Ensure contract dependencies and their versions are documented in the codebase to minimize code footprint. For example, importing specific submodules of a large project, rather than importing everything. Know your risk exposure and monitor supply chain attacks. Use the official interface to call external protocols, and make sure to consider potential integration risks. Monitor updates and security disclosures for reused contracts.


4. Security considerations during testing and review phase - consider testing and documentation


What: Create clear, comprehensive code documentation and build a test suite that's fast, thorough, and easy to run. Where possible, establish a test environment on the test network or simulate the main network to conduct more in-depth experiments.


Why: Writing out assumptions about the expected behavior of the codebase helps ensure that risks in the threat model are addressed and understandable to the development team by users and external auditors intention of. Creating test suites for code helps to prove (or disprove) development assumptions and encourages deeper thinking about threat models. This test suite should include mechanism design tests that check the project's token economy in extreme market scenarios, as well as unit tests and integration tests.


Approach: Implement known testing frameworks and security checkers like Hardhat, Mythril, Slither, Truffle, etc. which provide different testing techniques like fuzzing , property checking, and even formal verification. Use NatSpec comments to extensively document your code, specifying expected side effects, parameters, and return values. Generate real-time documentation using documentation generation tools as well as high-level design instructions.


5. Consider internal review and security audit


Content: Take the time to pass internal and external code inspections to find vulnerabilities.


Reason: Shifting from feature development to focusing on security issues gives developers time to spot potentially obscure issues. External audits are especially useful here, as they can bring outside perspective and expertise that the development team doesn't have.


Approach: At an appropriate point in project development, freeze a feature to allow time for an internal review followed by an external audit. This should be done before any actual deployments and upgrades.


Check out the guidelines from ConsenSys, Nassent, OpenZeppelin, and Trail of Bits, which provide developers with a checklist of considerations, including timing, for any A reference for those preparing for an audit. Also make sure to check deployment transactions to make sure they use audited code versions and have appropriate parameters, especially when upgrading software.


6. Security Considerations in Deployment and Maintenance Phases——Incentivize White Hat Community Participation


< p>Content: Create programs that encourage community participation in the security improvement of open source code bases. One way to do this is by creating bug bounties. Another approach is to encourage the community to develop protocols to monitor and detect bots.


Why: Development teams can benefit from a wide range of knowledge and experience (this is also the role of open source in the field of encryption). Such a program can help spark enthusiasm for a project, essentially turning the community and white hat hackers into evangelists. They can also help turn would-be attackers into secure assets by giving hackers a way to become defenders.


Method: Use a bug bounty platform such as Code4rena, HackenProof, mmunef, or Secureum to incentivize skilled hackers to securely disclose vulnerabilities.


Note: Some of the authors in this article work for Forta, a company that owns a network that provides a network for decentralized creation of high-quality security surveillance robots Token Incentive structure. Development teams can encourage their protocol communities to leverage both traditional and Web3-native approaches to incentivize bug bounties and potentially benefit participants through enhanced security, a win-win situation.


7. Real-time monitoring security considerations


Content: Implement monitoring smart contracts and key operating components (such as oracles and cross-chain bridges), and report suspicious activities to the development team and community based on known threat models.


Why: Early detection of issues enables teams to respond quickly to breaches, potentially preventing or mitigating any damage.


Method: Use a monitoring platform or a distributed node to run a robot to monitor smart contract events in real time. Plug in data dashboards and alert notifications for development teams and the wider community as needed.


8. Safety Considerations for Accident and Emergency Response Operations


Content: Tools and processes to respond immediately to any security issues.


Reason: Even with the best pre-deployment safeguards, real-time issues with smart contracts and key components such as oracles and cross-chain bridges are still possible. Dedicated personnel, clear processes, and appropriate automation ensure incidents can be investigated quickly and resolved as quickly as possible.


Approach: Prepare for worst-case scenarios, plan how to respond to incidents or emergencies, and automate response capabilities to the greatest extent possible. This includes assigning responsibility for investigation and response, who can be contacted publicly about security concerns via distributed security mailing lists, instructions in code repositories, or smart contract registries. Based on the agreement's threat model, develop a set of processes that can include scenario rehearsals and expected response times needed to take urgent action. Integration of automation into emergency incident response can be considered.


Security considerations should be an integral part of successful development, not just an afterthought or addition. While this framework shares some quick guidelines for building Web3 protocols and applications that facilitate security throughout the development process, there isn't any short overview that can discuss smart contract security in its entirety. Teams that lack in-house security expertise should contact qualified Web3 security experts who can guide and help apply to their specific situation.


Remember, security is not an easy problem. Security will always be a never-ending, ongoing set of best practices. We are still in the early stages of establishing these practices, and now is the time to create and share them collaboratively for all developers.


Original link


Welcome to join the official BlockBeats community:

Telegram Subscription Group: https://t.me/theblockbeats

Telegram Discussion Group: https://t.me/BlockBeats_App

Official Twitter Account: https://twitter.com/BlockBeatsAsia

举报 Correction/Report
Choose Library
Add Library
Cancel
Finish
Add Library
Visible to myself only
Public
Save
Correction/Report
Submit