# ink! Developers Security Guideline

### Development Environment

* Use [Substrate](https://docs.substrate.io/install/) multichain framework to build and deploy programs.
* Use [Ink!](https://github.com/paritytech/cargo-contract#installation) version 4. Check ink\_lang version in Cargo.toml file.
* Use a stable [compilation toolchain](https://use.ink/getting-started/creating-an-ink-project).
* Set the compiler flags *debug-assertion* and *overflow-checks* to true. These can be [set in Cargo.toml](https://docs.rust-lang.org/cargo/reference/profiles.html#default-profiles) for profile.release.
* Use [rustfmt](https://rust-lang.github.io/rustfmt) formatter. Customize your guidelines by creating a rustfmt.toml in the root of you project and perform the following commands:

  ```bash
  cargo +nightly fmt \-- \--check
  cargo +nightly fmt
  ```

<details>

<summary>Use a linter, such as clippy, regularly during the development of a secure application.</summary>

* Use [rust clippy](https://github.com/rust-lang/rust-clippy) which is a collection of lints to catch common mistakes and improve your Rust code.

  1. Install [Rustup](https://rustup.rs/). If you already have Rustup installed, update to ensure you have the latest Rustup and compiler:

  ```bash
  rustup update
  ```

  2. Install Clippy

  ```bash
  rustup component add clippy
  ```

  3. Run Clippy

  ```bash
  cargo clippy
  ```

  4. If necessary, fix Clippy suggestions automatically

  ```bash
  cargo clippy --fix
  ```
* Use [rustfix](https://github.com/rust-lang/rustfix) which reads and applies the suggestions made by rustc.

  1. Install rustfix

  ```bash
  cargo add rustfix
  cargo install cargo-fix
  cargo fix
  ```

  2. Open the rust files to manually verify the fixes.

</details>

<details>

<summary>Verify all dependencies are up to date.</summary>

* Use [cargo audit](https://crates.io/crates/cargo-audit) which audits your dependencies for crates with security vulnerabilities reported to the RustSec Advisory Database.

  1. Install cargo-audit

  ```bash
  cargo install cargo-audit
  ```

  2. Run cargo audit

  ```bash
  cargo audit
  ```
* Use [cargo outdated](https://github.com/kbknapp/cargo-outdated) which displays when Rust dependencies are out of date.

  1. Install cargo-outdated

  ```bash
  cargo install --locked cargo-outdated
  ```

  2. Run cargo outdated

  ```bash
  cargo outdated
  ```
* Use [cargo update](https://doc.rust-lang.org/cargo/commands/cargo-update.html) which updates dependencies as recorded in the local lock file.

  ```bash
  cargo update
  ```

</details>

### Design

Ensure that the design documents of your smart contract contain the following components:

* [ ] Architecture diagrams with all global state variables.
* [ ] Code documentation:
* [ ] We strongly ncourage developers to update the document as written in the code.
* [ ] We also encourage to include a set up guideline and simple use case examples.

### 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.

1. Context establishment
   * How will the project be used?
   * Who is the target audience?
2. Threat assessment
   * This includes a list of all assets used in the project and their associated risks or threats
3. Threat analysis & evaluation
   * Assets are classified by their risks/threats and their likelyhood.
4. Mitigation treatment
   * What can be done to mitigate these risks/threats?
5. Risk and control monitoring
   * Which operation can be done to conrol these risks/threats?

### Conventions

* [Rust API Guidelines Checklist](https://rust-lang.github.io/api-guidelines/checklist.html) is a set of recommendations on how to design and present APIs for the Rust programming language.
* Format strings using [format!](https://doc.rust-lang.org/std/macro.format.html)
* Are the following elements using *UpperCamelCase*?
  * [ ] Types
  * [ ] Traits
  * [ ] Enum variants
* Are the following elements using *snake\_case*?
  * [ ] Functions
  * [ ] Macros
  * [ ] Variables
  * [ ] Modules
* Are the following elements using *SCREAMING\_SNAKE\_CASE*?
  * [ ] Statics
  * [ ] Constants
* Is the following element using *lowercase*?
  * [ ] Lifetimes

<details>

<summary>[ ] If one of the above boxes has not been checked, we strongly encourage to change your code to follow the recommended convention.</summary>

*

```
* [ ] \[ ] Ad-hoc conversions follow as\_, to\_, into\_ conventions (\[C-CONV]\(https://rust-lang.github.io/api-guidelines/naming.html#c-conv))
```

```
* [ ] Getter names follow Rust convention ([C-GETTER](https://rust-lang.github.io/api-guidelines/naming.html#c-getter))
* [ ] Methods on collections that produce iterators follow iter, iter\_mut, into\_iter ([C-ITER](https://rust-lang.github.io/api-guidelines/naming.html#c-iter))
* [ ] Iterator type names match the methods that produce them ([C-ITER-TY](https://rust-lang.github.io/api-guidelines/naming.html#c-iter-ty))
* [ ] Feature names are free of placeholder words ([C-FEATURE](https://rust-lang.github.io/api-guidelines/naming.html#c-feature))
* [ ] Names use a consistent word order ([C-WORD-ORDER](https://rust-lang.github.io/api-guidelines/naming.html#c-word-order))

For further conventions, see [Rust API Guidelines Checklist](https://rust-lang.github.io/api-guidelines/checklist.html).
```

</details>

### Input Validation

<details>

<summary>[ ] Reentrancy: Calling external contracts gives them control over execution</summary>

* * [ ] \[ ] A malicious contract calls back into the calling contract before the first invocation of the function is finished.
  * [ ] Make sure all internal state changes are performed before the call is executed.
  * [ ] Use a reentrancy lock function if available.
  * [ ] <https://github.com/crytic/not-so-smart-contracts/tree/master/reentrancy>
  * [ ] <https://swcregistry.io/docs/SWC-107>

</details>

<details>

<summary>[ ] Forced AZERO Reception: Contracts can be forced to receive AZERO</summary>

* * \[ ] Avoid assuming how the balance of the contract increases, and implement a validation check to handle this type of edge cases.
  * <https://github.com/crytic/not-so-smart-contracts/tree/master/forced\\_ether\\_reception> (Solidity)

</details>

<details>

<summary>[ ] Insecure Oracle/Stale Price Feed - SVE1023</summary>

* * [ ] \[ ] Use the latest oracle API
  * [ ] Be aware the risk of oracle manipulation attack.
  * [ ] <https://blog.solend.fi/response-to-solana-network-issues-5c8184607283> (Solana).

</details>

### Output Encoding

<details>

<summary>[ ] Race Condition: Frontrunning attack</summary>

* * [ ] \[ ] There is a gap between the creation of a transaction and the moment it is accepted in the blockchain. Therefore, an attacker can take advantage of this gap to put a contract in a state that advantages them.
  * [ ] Be aware that all transactions may be front-run.
  * [ ] <https://github.com/crytic/not-so-smart-contracts/tree/master/race\\_condition>

</details>

<details>

<summary>[ ] Unchecked External Call</summary>

* * \[ ] Validate the result when making external calls, since operations/function calls/cross-contract calls silently fail.
  * <https://github.com/crytic/not-so-smart-contracts/tree/master/unchecked\\_external\\_call> (Solidity)

</details>

### Authentication

<details>

<summary>[ ] Zero/Test Address Check</summary>

* * [ ] \[ ] Contract ensures that each provided address is not zero or one of the default test accounts (e.g. Bob, Alice) because zero address public key has a known private key in the sr25519 and ed25519.
  * [ ] Use the ink! v4.4.0-rc or higher version where the default implementation for AccountIds by zero has been removed.
  * [ ] Tests against testnet allow the use of Zero address, but must be specified.
  * [ ] <https://substrate.stackexchange.com/questions/982/why-does-the-all-0-public-key-have-a-known-private-key-in-sr25519-and-ed25519>

</details>

<details>

<summary>[ ] Missing Signer Check - SVE1001</summary>

* * \[ ] If a function or asset should be available only to a restricted set of entities, you need to verify that the call has been signed by the appropriate entity.
  * <https://github.com/project-serum/sealevel-attacks/tree/master/programs/0-signer-authorization>
  * <https://blog.neodyme.io/posts/solana\\_common\\_pitfalls/#missing-signer-check>

</details>

<details>

<summary>[ ] Missing Owner Check - SVE1002</summary>

* * \[ ] Your contract should trust accounts owned by itself. Check the owner and return an object of a trusted type.
  * <https://github.com/project-serum/sealevel-attacks/tree/master/programs/2-owner-checks>
  * <https://blog.neodyme.io/posts/solana\\_common\\_pitfalls/#missing-ownership-check>

</details>

<details>

<summary>[ ] Unprotected Function</summary>

* * \[ ] Failure to use \`#\[ink(message)]\` decorator may allow attacker to manipulate contract
  * <https://github.com/crytic/not-so-smart-contracts/tree/master/unprotected\\_function>
  * <https://swcregistry.io/docs/SWC-100>

</details>

<details>

<summary>[ ] Unencrypted Private Data On-Chain</summary>

* * \[ ] Ensure that unencrypted private data is not stored in the contract code or state. In particular, items in the \`#\[ink(storage)]\` section should not contain passwords, private keys, etc.
  * <https://swcregistry.io/docs/SWC-136>

</details>

<details>

<summary>[ ] UnverifiedParsedAccount - SVE1007</summary>

* * \[ ] The account should be validated before parsing its data.
  * <https://github.com/project-serum/sealevel-attacks/tree/master/programs/1-account-data-matching>

</details>

### Authorization

<details>

<summary>[ ] Denial of Service</summary>

* * [ ] \[ ] Be aware that an attacker can stall contract execution by failing in a strategic way. In particular, contracts that bulk perform transactions or updates using a loop can be DoS'd if a call to another contract or transfer fails during the loop.
  * [ ] If iterating over a dynamically sized data structure, be able to handle the case where the function takes multiple blocks to execute. One strategy for this is storing iterator in a private variable and using *while* loop that exists when gas drops below certain threshold.
  * [ ] <https://github.com/crytic/not-so-smart-contracts/tree/master/denial\\_of\\_service>

</details>

<details>

<summary>[ ] Unprotected Token Withdrawal</summary>

* * \[ ] Ensure that access controls are implemented so withdrawals can only be triggered by authorized parties or according to the specs of the smart contract system.
  * <https://swcregistry.io/docs/SWC-105>

</details>

<details>

<summary>[ ] Unprotected self destruction or burning instruction(s)</summary>

* * \[ ] If the contract allows for removal of items from storage, these instructions should be properly authorized
  * <https://swcregistry.io/docs/SWC-106> (Solidity)
  * <https://github.com/Supercolony-net/openbrush-contracts/blob/main/examples/psp22\\_extensions/burnable/lib.rs> (Burnable PSP22 contract).

</details>

<details>

<summary>[ ] Cross-Contract Call to Untrusted Callee</summary>

* * \[ ] Use delegator call with caution and make sure to never call into untrusted contracts. If the target address is derived from user inputs, ensure to check it against a whitelist of trusted contracts.
  * <https://swcregistry.io/docs/SWC-112>
  * <https://use.ink/basics/cross-contract-calling>

</details>

<details>

<summary>[ ] Authorization through use of Self.env()</summary>

* * [ ] \[ ] Authorization checks by \`Self.env().caller()\` should validate the contract-only controllable values.
  * [ ] Ensure that the use of `Self.env().caller()` does not allow for manipulating sensitive values.
  * [ ] <https://swcregistry.io/docs/SWC-115> (Solidity)
  * [ ] <https://blog.neodyme.io/posts/solana\\_common\\_pitfalls/#solana-account-confusions> (Solana)

</details>

<details>

<summary>[ ] Signature Malleability: Valid signatures might be created by an attacker replaying previously signed messages.</summary>

* * \[ ] Ensure that a signature is never included into a signed message hash to check if previously messages have been processed by the contract.
  * <https://swcregistry.io/docs/SWC-117>
  * <https://eklitzke.org/bitcoin-transaction-malleability>

</details>

<details>

<summary>[ ] Write to Arbitrary Storage Location</summary>

* * \[ ] Ensure that writes to one data structure cannot inadvertently overwrite entries of another data structure.
  * <https://use.ink/basics/storing-values>
  * <https://swcregistry.io/docs/SWC-124>

</details>

<details>

<summary>[ ] Incorrect Trait Object Order</summary>

* * [ ] \[ ] Through the \*#\[ink::trait\_definition]\* \[ ] proc. macro, your own trait definitions are implementable by ink! smart contracts. This allows to define shared smart contract interfaces to different concrete implementations.
  * [ ] When defining shared smart contracts, you should carefully specify the trait definitions in the correct order.
  * [ ] <https://use.ink/basics/trait-definitions>
  * [ ] <https://swcregistry.io/docs/SWC-125>

</details>

<details>

<summary>[ ] Insufficient Gas Griefing</summary>

* * [ ] \[ ] In the case of a relayer contract, the user who executes the transaction, the 'forwarder', can effectively censor transactions by using just enough gas to execute the transaction, but not enough for the sub-call to succeed.
  * [ ] This attack is a form of "griefing": It doesn't directly benefit the attacker, but causes grief for the victim.
  * [ ] To prevent this attack, only allow trusted users to relay transactions or require that the forwarder provides enough gas.
  * [ ] <https://swcregistry.io/docs/SWC-126>
  * [ ] <https://consensys.github.io/smart-contract-best-practices/known\\_attacks/#insufficient-gas-griefing>
  * [ ] <https://ethereum.stackexchange.com/questions/73261/griefing-attacks-are-they-profitable-for-the-attacker>

</details>

<details>

<summary>[ ] Hardcoded Sensitive Values</summary>

* * [ ] \[ ] Values hardcoded in the contract lead to unexpected behavior.
  * [ ] Unexpected balance reflects some token balance or address hard-coded into a contract
  * [ ] <https://swcregistry.io/docs/SWC-134> (Message call with hardcoded gas limit)
  * [ ] <https://swcregistry.io/docs/SWC-132> (Solidity)

</details>

<details>

<summary>[ ] Bump Seed Not Validated - SVE1014</summary>

* * \[ ] The account's bump seed is not validated and may be vulnerable to seed canonicalization attacks.
  * <https://github.com/project-serum/sealevel-attacks/tree/master/programs/7-bump-seed-canonicalization>

</details>

### Cryptography

<details>

<summary>[ ] Weak Sources of Randomness</summary>

* * [ ] \[ ] Verify that there is no bad randomness: On-chain randomness may be a weak because it can be manipulated by users.
  * [ ] Use a random number generator whose randomness has been verified.
  * [ ] Use external sources of randomness via oracles if trusted oracles are available. Note that it may be reasonable to use multiple oracles, in particular for a seed of the random sequence.
  * [ ] Use the up-to-date API to get a random number.
  * [ ] <https://github.com/crytic/not-so-smart-contracts/tree/master/bad\\_randomness>
  * [ ] <https://swcregistry.io/docs/SWC-120>

</details>

<details>

<summary>[ ] Missing Protection against Signature Replay Attacks</summary>

* * [ ] \[ ] Check a new message hash and verify it has never been processed before.
  * [ ] See also signature malleability in the authorization.
  * [ ] <https://swcregistry.io/docs/SWC-121>

</details>

<details>

<summary>[ ] Lack of Proper Signature Verification and Data Authenticity</summary>

* * [ ] \[ ] Add data authentication and signature verification to your contract.
  * [ ] Use a proper API for verification funcitons.
  * [ ] <https://swcregistry.io/docs/SWC-122>

</details>

### Numerics

<details>

<summary>[ ] Integer overflow / underflow</summary>

* * \[ ] If \`doverflow-checks = false\` in \`Cargo.tolm\` file please wrap arithmetic operations with safe math functions or validate all arithmetic to prevent overflows. \* <https://github.com/crytic/not-so-smart-contracts/tree/master/integer\\_overflow> \* <https://swcregistry.io/docs/SWC-101> \* <https://medium.com/coinmonks/understanding-arithmetic-overflow-underflows-in-rust-and-solana-smart-contracts-9f3c9802dc45>

</details>

<details>

<summary>[ ] Division by zero: Contracts go to panic mode when dividing by zero</summary>

* * \[ ] Use a safe math function for division or validate the divisor not zero.
  * <https://github.com/rust-lang/rust/issues/944>

</details>

### Memory management

When it comes to memory management, the following checks need to be done:

* [ ] Uninitialized memory must not be used.
* [ ] Zero out memory of sensitive data after use.
* [ ] The forget function of std::mem (core::mem) must not be used.
* [ ] The code must not leak memory or resource in particular via Box::leak.
* [ ] Iterators are used rather than explicit indexing.
  * If indexing is necessary, explicitly check for correctness.

### Error Handling

When it comes to memory management, the following checks need to be done:

* [ ] The object are exception-safe ([RFC 1236](https://github.com/rust-lang/rfcs/pull/1236))
* [ ] The ? operator can be used to improve readability of code.
* [ ] The try! macro should not be used.
* [ ] The Result enum for explicit error handling is used instead of calling panic.
* [ ] Try to avoid using crates containing functions or instructions that can fail and cause the code to panic.

<details>

<summary>[ ] Be careful when you use the following patterns that may cause panics.</summary>

* using unwrap or expect,
* using assert,
* an unchecked access to an array,
* integer overflow (in debug mode),
* division by zero,
* large allocations,
* string formatting using format!.

</details>

### Bad Programming practices

<details>

<summary>[ ] Incorrect Interface</summary>

* * \[ ] A different type of interfaces are implemented, causing a different method ID to be created. For example, \`Alice.set(uint)\` takes an \`uint\` in Bob.rs but \`Alice.set(int)\` a \`int\` in Alice.rs. The two interfaces will produce two differents method IDs. As a result, Bob can call the fallback function of Alice rather than of \`set\`.
  * <https://github.com/crytic/not-so-smart-contracts/tree/master/incorrect\\_interface>

</details>

<details>

<summary>[ ] Wrong Constructor Name</summary>

* * [ ] \[ ] A constructor function is named correctly so that it does not cause to end up in the runtime bytecode instead of being a constructor.
  * [ ] A constructor is responsible for bootstrapping the initial contract state into the storage.
  * [ ] Use `#[ink(constructor)]` constructor instead of a named constructor.
  * [ ] <https://github.com/crytic/not-so-smart-contracts/tree/master/wrong\\_constructor\\_name> (Solidity)
  * [ ] <https://swcregistry.io/docs/SWC-118> (Solidity)
  * [ ] <https://use.ink/3.x/macros-attributes/constructor>

</details>

<details>

<summary>[ ] Variable Shadowing</summary>

* * \[ ] Don't name local variables identical to one in outer scope
  * <https://github.com/crytic/not-so-smart-contracts/tree/master/variable%20shadowing> (Solidity)
  * <https://swcregistry.io/docs/SWC-119> (Solidity)

</details>

<details>

<summary>[ ] State Variable Default Visibility</summary>

* * [ ] \[ ] Labeling the visibility explicitly for variables.
  * [ ] Variables can be specified as being `public` or `private`. Explicitly define visibility for all state variables.
  * [ ] <https://swcregistry.io/docs/SWC-108> (Solidity)

</details>

<details>

<summary>[ ] Use of Uninitialized Storage</summary>

* * [ ] \[ ] Initialized local storage variables, otherwise they can point to unexpected storage locations in the contract, which can lead to intentional or unintentional vulnerabilities.
  * [ ] Use `ink_storage::Mapping` which maps key-value pairs directly into contract storage.
  * [ ] <https://swcregistry.io/docs/SWC-109>
  * [ ] <https://use.ink/datastructures/mapping>

</details>

<details>

<summary>[ ] Assert Violation</summary>

* * [ ] \[ ] The assert function should only be used to test for internal errors, and to check invariants.
  * [ ] Consider whether the condition checked in the `assert!` is actually an invariant. If not, replace the `assert!` statement with a `require!` statement.
  * [ ] <https://swcregistry.io/docs/SWC-110> (Solidity)
  * [ ] <https://use.ink/ink-vs-solidity/#assert>

</details>

<details>

<summary>[ ] Use of Deprecated Functions</summary>

* * \[ ] Do not use the deprecated functions.
  * <https://swcregistry.io/docs/SWC-111> (Solidity)

</details>

<details>

<summary>[ ] Unhandled Revert: Use `revert` properly</summary>

* * \[ ] \`if ... { return Err(Error::SomeError) }\` should be used for \`require\` or \`revert\`. When a \`Result::Err\` is returned in ink!, then all state is reverted.
  * <https://consensys.github.io/smart-contract-best-practices/development-recommendations/solidity-specific/assert-require-revert/> (Solidity)
  * <https://use.ink/ink-vs-solidity#require-and-revert>

</details>

<details>

<summary>[ ] DoS With Block Gas Limit: The cost of executing a function exceeds the block gas limit.</summary>

* * [ ] \[ ] Be cautious when you expect to have large arrays that grow over time. Actions that require looping across the entire data structure should be avoided.
  * [ ] If you absolutely must loop over an array of unknown size, then you should plan for it to potentially take multiple blocks, and therefore require multiple transactions.
  * [ ] <https://swcregistry.io/docs/SWC-128>

</details>

<details>

<summary>[ ] Presence of Unused Variables</summary>

* * [ ] \[ ] Unused variables cause an increase in computations, indicate bugs or malformed data structures, and decrease readability of the code.
  * [ ] Remove all unused variables.
  * [ ] <https://swcregistry.io/docs/SWC-131>
  * [ ] `cargo contract build` will warn against unused variables

</details>

<details>

<summary>[ ] Code with No Effects (Dead Code)</summary>

* * [ ] \[ ] Remove dead codes.
  * [ ] Ensure that your contract works as intended without dead codes.
  * [ ] <https://swcregistry.io/docs/SWC-135>

</details>

<details>

<summary>[ ] Account Reinitialization - SVE1013</summary>

* * [ ] \[ ] Be aware that an account can be vulnerable to program re-initialization.
  * [ ] Check whether the contract is already initialized from other program before executing the initialization function.
  * [ ] <https://github.com/project-serum/sealevel-attacks/tree/master/programs/4-initialization>

</details>

<details>

<summary>[ ] Incorrect Calculation of Boundary Cases</summary>

* * \[ ] Check the edge cases e.g. \`>\` instead of \`>=\`.

</details>

<details>

<summary>[ ] The contract is upgradeable.</summary>

* * \[ ] Upgradeable contracts may change their rules over time.

</details>

<details>

<summary>[ ] The contract is pausable.</summary>

* * \[ ] Having a way to pause your contract can help to limit the damage in case of attack or security breach.

</details>

### Token Specific issues

<details>

<summary>[ ] Token Race Conditions: A transaction-ordering attack or a front running attack.</summary>

* * \[ ] An attacker who is running a node can tell which transactions are going to occur before they are finalized. A race condition vulnerability occurs when code depends on the order of the transactions submitted to it.
  * <https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA\\_jp-RLM/edit#> (ERC20)
  * <https://swcregistry.io/docs/SWC-114>
  * <https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729> (Ethereum)
  * <https://medium.com/coinmonks/solidity-transaction-ordering-attacks-1193a014884e> (Solidity)

</details>

<details>

<summary>[ ] Lost Token Transfer - Revert on Fail</summary>

* * \[ ] If a transfer fails, the function must throw an error and revert the transation, otherwise tokens will be lost by the sender.

</details>

<details>

<summary>[ ] `transfer`, `transfer_from`, and `transfer_from_to`</summary>

* * \[ ] \`transfer\`, \`transfer\_from\`, \`transfer\_from\_to\` return proper Result and Error message.
  * <https://github.com/crytic/building-secure-contracts/blob/master/development-guidelines/token\\_integration.md#erc-conformity>

</details>

<details>

<summary>[ ] `token_name`, `token_decimals`, and `token_symbol` functions</summary>

* * \[ ] Must be present, if used. Optional functions in the standard.
  * <https://github.com/crytic/building-secure-contracts/blob/master/development-guidelines/token\\_integration.md#erc-conformity>

</details>

<details>

<summary>[ ] `token_decimals` returns proper u8.</summary>

* * \[ ] Implemented tokens may incorrectly return a uint256, causing compatability issues
  * <https://github.com/crytic/building-secure-contracts/blob/master/development-guidelines/token\\_integration.md#erc-conformity>

</details>

<details>

<summary>[ ] The token has no external function call in transfer or transferFrom.</summary>

* * \[ ] External calls in the transfer functions can lead to reentrancies.

</details>

<details>

<summary>[ ] The contract has only a few non-token-related functions.</summary>

* * \[ ] Non-token-related functions increase the likelihood of an issue in the contract.

</details>

<details>

<summary>[ ] The token only has one address.</summary>

* * \[ ] Multiple addresses can result in mismatch in token supply, fees, rules, etc.

</details>

<details>

<summary>[ ] The token is not upgradeable.</summary>

* * \[ ] Upgradeable contracts may change their rules over time, therefore provide justification into your documentation about the upgradeable function.

</details>

<details>

<summary>[ ] The owner has limited minting capabilities.</summary>

* * \[ ] Malicious or compromised owners can abuse minting capabilities.

</details>

<details>

<summary>[ ] The token is not pausable.</summary>

* * \[ ] Malicious or compromised owners can trap contracts relying on pausable tokens. Identify pausable code by hand.

</details>

<details>

<summary>[ ] The owner cannot blacklist the contract.</summary>

* * \[ ] Malicious or compromised owners can trap contracts relying on tokens with a blacklist. Identify blacklisting features by hand.

</details>

### Testing

<details>

<summary>[ ] Unit Tests</summary>

* * [ ] \[ ] Ensure all edge cases are included.
  * [ ] If not implemented, red flag here. No need to go further. Please design unit Tests with edge case you can think of.

</details>

<details>

<summary>[ ] [cargo-fuzz](https://rust-fuzz.github.io/book/introduction.html)</summary>

* * [ ] \[ ] Review all findings and update your code accordingly.
  * [ ] It can be a good starting point to produce more secure code.

</details>

### 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?

<details>

<summary>[ ] Complete Documentations</summary>

* * [ ] \[ ] Explaination of the purpose of the smart contract
  * [ ] Documentation and explanation of all smart contract's functions and variables
  * [ ] Examples and use cases:
  * [ ] Machine setup, installation, deployment and testing instructions:
  * [ ] Example of helpful documents
    * [ ] architecture diagrams,
    * [ ] threat models,
    * [ ] academic papers,
    * [ ] whitepapers,
    * [ ] blog posts,
    * [ ] or any other piece of documentation relevant to the project.

</details>

<details>

<summary>[ ] Setup a communication channel with the audit team</summary>

* * \[ ] Use a secure communication channel using end-to-end encryption.

</details>

<details>

<summary>[ ] Code ready to be frozen</summary>

* * [ ] \[ ] setup the credential for auditors.
  * [ ] share the repository.

</details>

<details>

<summary>[ ] Verify that the audit team can answer the following questions</summary>

* * [ ] \[ ] What does it do?
  * [ ] Who does it do this for?
  * [ ] What kind of information will it hold/handle?
  * [ ] How does it handle entities or identities?
  * [ ] What aspects seem most concerning?

</details>

<details>

<summary>[ ] Commit Hash</summary>

* * [ ] \[ ] Get the commit hash of the frozen code
  * [ ] Inform the commit hash value to the audit team

</details>

### 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.
