Synthetix Mimosa Release Smart Contract Audit

# 1. Introduction
iosiro was commissioned by [Synthetix](https://www.synthetix.io) to conduct a smart contract audit on changes introduced in the [Mimosa release](https://blog.synthetix.io/the-mimosa-release/), including [SIP-89](https://sips.synthetix.io/sips/sip-89), [SIP-91](https://sips.synthetix.io/sips/sip-91) and [SIP-92](https://sips.synthetix.io/sips/sip-92). The audit was performed between 23 October 2020 and 11 November 2020.  

**UPDATE (14 November 2020): due to a bug discovered in the settlement logic post-audit, [SIP-94](https://sips.synthetix.io/sips/sip-94) was implemented in [1c34a59](https://github.com/Synthetixio/synthetix/commit/1c34a5986ebbc97844a234e725fd2a47c4a188b1).**

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 audit performed by iosiro on the smart contract implementation of the Synthetix Mimosa Release.  

#### SIP-89

[SIP-89](https://sips.synthetix.io/sips/sip-89) introduced a virtual synth token (vSynth) representing a claim to an unsettled exchange. This allowed the proceeds of exchanges to be immediately transferable, enabling composition between different DeFi protocols.

No issues were identified during the audit. Overall, the implementation was of a high standard and accorded with the specification provided.

#### SIP-91

The purpose of [SIP-91](https://sips.synthetix.io/sips/sip-91) was to refactor the debt cache logic out of the `Issuer` contract into its own `DebtCache` contract. The refactor was necessary as the size of the `Issuer` contract was too large to be deployed on the L2 OVM.

This SIP also introduced a new contract, `RealtimeDebtCache`, which is to be deployed on the L2 OVM. Given the efficency of L2 over L1, the current SNX issued debt is used instead of the debt cache.

One informational issue was identified and open at the conclusion of the audit. Overall, the implementation was of a high standard.

#### SIP-92

[SIP-92](https://sips.synthetix.io/sips/sip-92) implemented a bug fix relating to inverse synths incorrectly locking the settlement price according to whether the synth was currently frozen, and not whether the synth was frozen at the time that the exchange occured.

The implementation was found to correctly address the issue.    

<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 Synthetix SIP-89 Smart Contracts

**Project Name:** Synthetix<br/>
**Commit:** [46ea741](https://github.com/Synthetixio/synthetix/commit/46ea7415cef97b86dfb4ab75d26c47d965107eee)<br/>
**Files:** Exchanger.sol, ExchangerWithVirtualSynth.sol, Synthetix.sol, VirtualSynth.sol

### 3.1.2 Synthetix SIP-91 Smart Contracts

**Project Name:** Synthetix<br/>
**Commit:** [424bb61](https://github.com/Synthetixio/synthetix/commit/424bb619c3685128da244d14f3cd91bba37770e4)<br/>
**Files:** DebtCache.sol, Exchanger.sol, Issuer.sol, RealtimeDebtCache.sol


### 3.1.2 Synthetix SIP-92 Smart Contracts

**Project Name:** Synthetix<br/>
**Commit:** [3c3be35](https://github.com/Synthetixio/synthetix/commit/3c3be359edb2b12ee4dc5a873af464c569753522)<br/>
**Files:** ExchangeRates.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 Ganache 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 SIP-89

The specification of SIP-89 was based on commit hash [0932b0a](https://github.com/Synthetixio/SIPs/blob/0932b0afcac0eaab8a68533aad28fd976806b8c7/sips/sip-89.md).

## 4.2 SIP-91

The specification of SIP-91 was based on commit hash [8ca5e18](https://github.com/Synthetixio/SIPs/blob/8ca5e1820f94ee2aa2bad169c146dbcf83ef8428/sips/sip-91.md).

## 4.2 SIP-92

The specification of SIP-92 was based on commit hash [1ca12dc](https://github.com/Synthetixio/SIPs/blob/1ca12dc8da1cdd6c2e37eda6c211a02d1465a69a/sips/sip-92.md).

<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  

### 5.4.1 Design Comments (Informational)

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

#### Possible to lock tokens in token contract

It was found that vSynths could be transferred into the token contract. This made it possible for users to accidentally lock their tokens in the contract if they were to assume that it was possible to redeem synths in this manner. It is recommended that the `transfer` function be overriden to prevent transfers to the contract, as at no stage would the contract need to hold its own tokens.

#### Refactoring suggestions

It is recommended that certain portions of the code be refactored to improve readability and consistency, as indicated below.

##### SIP-91

1. [Issuer.sol#L416](https://github.com/Synthetixio/synthetix/blob/424bb619c3685128da244d14f3cd91bba37770e4/contracts/Issuer.sol#L416): The `Issuer.synthAddresses` function should be renamed to `Issuer.getSynths` or similar to indicate that Synths and not Synth addresses are being returned.
2. [Issuer.sol#L418](https://github.com/Synthetixio/synthetix/blob/424bb619c3685128da244d14f3cd91bba37770e4/contracts/Issuer.sol#L418): The `addresses` variable should be renamed to `synthArray` or similar to indicate that it contains an array of Synths and not addresses.

## 5.5 Closed

No issues were closed at the conclusion of the audit.

Secure your system.
Request a service
Start Now