ink! Developers Security Guideline
This guide aims at supporting ink! developers who want to deploy their project on the Aleph Zero blockchain. It has been developed as part of the partnership between Aleph Zero and Kudelski Security.
Development Environment
Use Substrate multichain framework to build and deploy programs.
Use Ink! version 4. Check ink_lang version in Cargo.toml file.
Use a stable compilation toolchain.
Set the compiler flags debug-assertion and overflow-checks to true. These can be set in Cargo.toml for profile.release.
Use rustfmt formatter. Customize your guidelines by creating a rustfmt.toml in the root of you project and perform the following commands:
cargo +nightly fmt \-- \--check cargo +nightly fmt
Design
Ensure that the design documents of your smart contract contain the following components:
Threats/Risk assessment
While designing the smart contract, a threat assessment needs to be performed with the following five steps. A threat is an element which can hurt, harm, tamper with, or attack the smart contract.
Context establishment
How will the project be used?
Who is the target audience?
Threat assessment
This includes a list of all assets used in the project and their associated risks or threats
Threat analysis & evaluation
Assets are classified by their risks/threats and their likelyhood.
Mitigation treatment
What can be done to mitigate these risks/threats?
Risk and control monitoring
Which operation can be done to conrol these risks/threats?
Conventions
Rust API Guidelines Checklist is a set of recommendations on how to design and present APIs for the Rust programming language.
Format strings using format!
Are the following elements using UpperCamelCase?
Are the following elements using snake_case?
Are the following elements using SCREAMING_SNAKE_CASE?
Is the following element using lowercase?
Input Validation
Output Encoding
Authentication
Authorization
Cryptography
Numerics
Memory management
When it comes to memory management, the following checks need to be done:
Error Handling
When it comes to memory management, the following checks need to be done:
Bad Programming practices
Token Specific issues
Testing
Pre-Audit
This part aims to help preparing for a security audit which is necessary in order to achieve the best security possible. It is important to see an audit as a partnership between you and the company performing the audit. Therefore, it is important that you prepare some documents to the good functionning of audit.
Are the following elements ready?
Audit
High-risk findings have been escalated immediately via a secure channel.
Communication with audit team are frequent enough.
Questions from the audit team have been answered.
All findings have been corrected and re-reviewed.
Maintenance
Keep monitoring new security attacks and evaluate your contracts accordingly.
Apply remedies to the smart contracts immediately if new vulnerabilities are discovered.
Contract needs to be upgratable.
Run automated code analysis tools whenever new commits are added to the repository.
Pause the smart contract when an unusual happen.
Contract needs to have a pause option.
Consider re-auditing your smart contracts if they have been significantly updated.
Feel free to contact security partners for evaluation and scoping.
Last updated
Was this helpful?
