Synthetix SIP-44 and SIP-46 Smart Contract Audit

# 1. Introduction

iosiro was commissioned by [Synthetix]( to conduct a smart contract audit on the implementation of [SIP-44]( and [SIP-46]( The audit was performed between 26 March 2020 and 1 April 2020.

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.

<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 [SIP-44]( and [SIP-46](

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.  

#### SIP-44

The purpose of SIP-44 was to add the ability to suspend and resume certain functionality within the system. Reasons for suspending the system might include system upgrades, issuance and exchange controls, disabling synths for security purposes, or potentially suspending synths during the underlying assets' out-of-trading hours.

#### SIP-46

SIP-46 provided contracts with a caching system, which allowed external contract addresses to be cached locally to reduce gas usage. In a prior version, an external resolver contract was used to query contract addresses within the system, however, this approach required a large number of external contract calls, which resulted in substantial gas fees.  

#### Audit Results

The code was found to be of a very high standard, as it was modularised, well-documented, defensive, and generally adhered to best practices. The implementations were found to strictly implement the specifications.

At the conclusion of the audit only one informational issue that did not require further action was open.

A consideration for future developments would be that the suspension controls implemented in SIP-44 were generally implemented in the external functions. Thus it is important that if new functionality is added to the system that interacts with the underlying sensitive internal functions, it be properly locked down. An example of this is `Synthetix.issueSynths(...)` which used `requireIssuanceActive`, exposing `Issuer._internalIssueSynths(...)` to potential misuse.

<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-44 Smart Contracts

**Project Name:** Synthetix<br/>

**Commits:** [8288a47](<br/>

**Files:** DappMaintenance.sol, EtherCollateral.sol, Exchanger.sol, FeePool.sol, Issuer.sol, Synth.sol, Synthetix.sol, SystemStatus.sol

### 3.1.2 Synthetix SIP-46 Smart Contracts

**Project Name:** Synthetix<br/>

**Commits:** [6275048](<br/>

**Files:** Depot.sol, EtherCollateral.sol, Exchanger.sol, FeePool.sol, Issuer.sol, MixinResolver.sol, MultiCollateralSynth.sol, PurgeableSynth.sol, Synth.sol, Synthetix.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 Truffle 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-44

The following specification was taken from [SIP-44](

The following areas can be suspended:

1. **System**: All synth and SNX transfers disabled. All exchange, issue, burn, claim, loan and mint functionality disabled. This is both for system upgrades and under possible emergency situations.

2. **Issuance**: All sUSD issuance, burning and claiming disabled, along with any loan actions.

3. **Exchange**: All synth exchanges and settlement.

4. **Synth**: For the synth in question, all transfers of, settlement of, and exchanges into or out of disabled.

Access to the above controls will be restricted to an `accessControlList`, a whitelist of addresses that for each section above, can `suspend` and/or `resume`. This whitelist will be managed by the `owner`.

Furthermore, each suspension must include a `uint reason`. Apart from the single reason `1` for `SYSTEM_UPGRADE`, these reasons are purely for dApps and scripts to indicate to users why certain parts of the system are unavailable.

## 4.2 SIP-46

The following specification was taken from [SIP-46](

1. Introduce a local `mapping(bytes32 => address)` cache into `MixinResolver` - the functionality included in all contracts that need to communicate via the address resolver

2. Ensure `MixinResolver` is instantiated with a list of `bytes32` addresses that the contract needs to know about

3. Expose a function in `MixinResolver.setResolverAndSyncCache()` to sync the cache. This is to be called each deployment whenever any new contracts are added.

<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

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

#### Potential Overflow Issue

A possible overflow existed in `SystemStatus.suspendSystem(...)` by downcasting a `uint256` parameter to `uint248`. However, the functionality was restricted to only privileged accounts and was not obviously exploitable. As this is was found to be potentially advantageous from a storage perspective, no change is recommended.

## 5.5 Closed

### 5.5.1 Design Comments (Informational)

#### For Loop Optimization

The `for` loop in the MixinResolver constructor could `break` once a null address is detected, as long as no null addresses are expected. Doing so would avoid unnecessarily iterating through the full array, which would result in saving gas during deployment.

##### Update

Implemented in [9caca24](

#### Inline Values Used Instead of Constants

- Synth.sol#L158,162,166,170 use inline strings rather than the constants variables declared in the contract.

- MixinResolver.sol#L16 uses an inline value rather than the defined `MAX_ADDRESSES_FROM_RESOLVER` constant.

##### Update

Implemented in [9caca24](

#### Deprecated Pattern Usage

FeePool.sol#L242 uses the deprecated `resolver.getAddress(..)` pattern and should be replaced with the caching pattern.

##### Update

Implemented in [9caca24](

#### Refactoring Suggestions

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

- `MixinResolver.updateAddressCache(...)` should be renamed to `appendToAddressCache(...)`, as it is intended to append another address to the address cache, instead of updating existing entries.

- `MixinResolver.getResolverAddresses()` should be renamed to `getResolverContracts()` or `getResolverAddressesRequired()` and the return variable should be renamed from `addresses` to contracts, `names`, or `addressesRequired`, as the function returns an array of contract names required by the resolver.

##### Update

Implemented in [9caca24]( and [2662222](

#### Fix Spelling and Grammatical Errors

Language mistakes were identified in the comments and revert messages in the codebase. Fixing these mistakes can help improve the end-user experience by providing clear information on errors encountered, and improve the maintainability and auditability of the codebase.

- SystemStatus.sol#L55: `Issuance` → `Exchange`

- SystemStatus.sol#L154: `INTERNL` → `INTERNAL`

##### Update

Implemented in [9caca24](

Secure your system.
Request a service
Start Now