Synthetix Grants DAO v2 Smart Contract Audit

# 1. Introduction
iosiro was commissioned by [Synthetix](https://www.synthetix.io) to conduct a smart contract audit of the GrantsDAO v2 as part of [SIP-141](https://sips.synthetix.io/sips/sip-141). The audit was performed by one auditor on 21 May 2021, and a review was performed on 26 May 2021 consuming a total of 2 resource days.

This report is organized into the following sections.

* **[Section 2 - Executive summary:](#section-2)** A high-level description of the findings of the audit.
* **[Section 3 - Audit details:](#section-3)** A description of the scope and methodology of the audit.
* **[Section 4 - Design specification:](#section-4)** An outline of the intended functionality of the smart contracts.
* **[Section 5 - Detailed findings:](#section-5)** Detailed descriptions of the findings of the audit.

The information in this report should be used to understand the risk exposure of the smart contracts, and as a guide to improving the security posture of the smart contracts by remediating the issues that were identified. The results of this audit are only a reflection of the source code reviewed at the time of the audit and of the source code that was determined to be in-scope.

The purpose of this audit was to achieve the following:

* Ensure that the smart contracts functioned as intended.  
* Identify potential security flaws.

Assessing the market effect, economics, game theory, or underlying business model of the platform were strictly beyond the scope of this audit.

Due to the unregulated nature and ease of transfer of cryptocurrencies, operations that store or interact with these assets are considered very high risk with regards to cyber attacks. As such, the highest level of security should be observed when interacting with these assets. This requires a forward-thinking approach, which takes into account the new and experimental nature of blockchain technologies. There are a number of techniques that can help to achieve this, some of which are described below.

* Security should be integrated into the development lifecycle.
* Defensive programming should be employed to account for unforeseen circumstances.
* Current best practices should be followed when possible.

<a name="section-2"></a>
# 2. Executive summary

This report presents the findings of the GrantsDAO v2 smart contract audit performed by iosiro.  

The purpose of the GrantsDAO v2 contracts was to facilitate payments for different purposes, such as grants, initiatives, and competitions. One medium risk and several informational issues were identified and fixed by the end of the audit.

<a name="section-3"></a>
# 3. Audit details

## 3.1 Scope
The source code considered in-scope for the assessment is described below. Code from all other files is considered to be out-of-scope. Out-of-scope code that interacts with in-scope code is assumed to function as intended and introduce no functional or security vulnerabilities for the purposes of this audit.

### 3.1.1 GrantsDAO v2 Smart Contracts

**Project name:** snx-grants-dao-v2<br/>
**Commits:** [478b0db](https://github.com/Synthetixio/snx-grants-dao-v2/commit/478b0dbbcbef56312b154f790b48c0b94bde6c72), [1490671](https://github.com/Synthetixio/snx-grants-dao-v2/commit/14906711f97016930467df518d8c799e47d1ccab)<br/>
**Files:** GrantsDAOV2.sol

## 3.2  Methodology

A variety of techniques were used in order to perform the audit. These techniques are briefly described below.

### 3.2.1 Code review

The source code was manually inspected to identify potential security flaws. Code review is a useful approach for detecting security flaws, discrepancies between the specification and implementation, design improvements, and high risk areas of the system.

### 3.2.2 Dynamic analysis

The contracts were compiled, deployed, and tested in a test environment, both manually and through the test suite provided. Manual analysis was used to confirm that the code operated at a functional level, and to verify the exploitability of any potential security issues identified.

### 3.2.3 Automated analysis

Tools were used to automatically detect the presence of several types of security vulnerabilities, including reentrancy, timestamp dependency bugs, and transaction-ordering dependency bugs. The static analysis results were manually analyzed to remove false-positive results. True positive results would be indicated in this report. Static analysis tools commonly used include Slither, Securify, and MythX. Tools such as the Remix IDE, compilation output, and linters are also used to identify potential issues.

## 3.3  Risk ratings

Each issue identified during the audit has been assigned a risk rating. The rating is determined based on the criteria outlined below.

* **High risk** - The issue could result in a loss of funds for the contract owner or system users.
* **Medium risk** - The issue resulted in the code specification being implemented incorrectly.
* **Low risk** - A best practice or design issue that could affect the security of the contract.
* **Informational** - A lapse in best practice or a suboptimal design pattern that has a minimal risk of affecting the security of the contract.
* **Closed** - The issue was identified during the audit and has since been addressed to a satisfactory level to remove the risk that it posed.

<a name="section-4"></a>
# 4. Design specification
The following section outlines the intended functionality of the system at a high level.

## 4.1 GrantsDAO v2 Smart Contracts

The GrantsDAO was intended to manage grants, initiatives, and competitions. All the functions were restricted by the `onlyOwner` modifier, which was controlled by the GrantsDAO multi-signature wallet.

#### Grants

- Create: create a grant.
- Reassign: reassigns a grant to a new address to receive payouts.
- Progress: pays out the current milestone and progresses the grant to the next milestone.
- Complete: pays out the remaining milestone and marks the grant as completed.
- Cancel: allows the owner to cancel a grant.

#### Initiatives

- Create: allows the owner to create an initiative.
- Assign: assigns an initiative to an address that will receive the payouts.
- Progress: pays out the current milestone and progresses the initiative to the next milestone.
- Complete: pays out the remaining milestone and marks the initiative as completed.
- Cancel: allows the owner to cancel an initiative.

#### Competitions

- Create: allows the owner to create
- Complete: pays out each of the competition winners.
- Cancel: allows the owner to cancel a competition.

#### Admin

- Withdraw: allows the owner to withdraw ERC-20 tokens from the contract.

<a name="section-5"></a>
# 5. Detailed findings
The following section includes in-depth descriptions of the findings of the audit.

## 5.1 High risk

No high-risk issues were present at the conclusion of the audit.

## 5.2 Medium risk

No medium-risk issues were present at the conclusion of the audit.

## 5.3 Low risk

No low-risk issues were present at the conclusion of the audit.

## 5.4 Informational  

No informational issues were identified.

## 5.5 Closed

### 5.5.1 Possible to overwrite states (medium risk)

#### Description

When creating a grant, initiative or competition, the mapping was not validated to determine whether the hash was currently empty. As a result, it was possible to overwrite existing entries by creating a new instance with the same hash.  

The risk was mitigated by the fact that the transaction was restricted to the owner role, which would be the GrantsDAO multi-signature wallet.

#### Recommendation

Before adding a mapping during the creation functions, the existing value should be validated to ensure that it is empty.

The risk was mitigated by the fact that the transaction was restricted to the owner role, which would be the GrantsDAO multi-signature wallet.

#### Update

Implemented in [1490671](https://github.com/Synthetixio/snx-grants-dao-v2/commit/14906711f97016930467df518d8c799e47d1ccab).

### 5.5.2 Design comments (informational)

Actions to improve the functionality and readability of the codebase are outlined below.

#### Events are not indexed

None of the event parameters were found to be indexed. Indexing helps to easily and quickly retrieve information to display on front-ends.

#### Update

Implemented in [1490671](https://github.com/Synthetixio/snx-grants-dao-v2/commit/14906711f97016930467df518d8c799e47d1ccab).

#### Use of `now`

[In Solidity version 0.7.0, the `now` keyword was deprecated.](https://solidity.readthedocs.io/en/v0.7.0/070-breaking-changes.html) Developers are encouraged to use `block.timestamp` instead, to ensure forward compatibility.

#### Update

Implemented in [1490671](https://github.com/Synthetixio/snx-grants-dao-v2/commit/14906711f97016930467df518d8c799e47d1ccab).

#### Consistent emission of `MilestoneReleased`

It is recommended that the `MilestoneReleased` event is emitted in the `for` loops in the `complete` functions, so as to be consistently emitted whenever a milestone is released.

#### Update

Implemented in [1490671](https://github.com/Synthetixio/snx-grants-dao-v2/commit/14906711f97016930467df518d8c799e47d1ccab).

Secure your system.
Request a service
Start Now