Audit Report
Synthetix Pollux Release Smart Contract Audit

# 1. Introduction
iosiro was commissioned by [Synthetix](https://www.synthetix.io) to conduct a smart contract audit on the Pollux release, including [SIP-63](https://sips.synthetix.io/sips/sip-63), [SIP-64](https://sips.synthetix.io/sips/sip-64), [SIP-75](https://sips.synthetix.io/sips/sip-75), [SIP-76](https://sips.synthetix.io/sips/sip-76), and [SIP-78](https://sips.synthetix.io/sips/sip-78). The audit was performed between 13 August 2020 and 28 August 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.

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 [Pollux release](https://blog.synthetix.io/the-pollux-release/).  

#### SIP-63

[SIP-63](https://sips.synthetix.io/sips/sip-63) introduced functionality to track the trading fees paid by each address during each fee period. This was introduced to allow for the distribution of trading incentives in the form of SNX.

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

#### SIP-64

The purpose of [SIP-64](https://sips.synthetix.io/sips/sip-64) was to generalize the `EternalStorage` contract pattern, allowing storage to be maintained for several Synthetix contracts. This SIP included the addition of a `SystemSettings` contract which was used to control various SCCP configurable settings.

Two informational issues were identified during the audit. These issues were open at the conclusion of the audit. Overall, the implementation was of a high standard and accorded with the specification provided.

#### SIP-75

The purpose of [SIP-75](https://sips.synthetix.io/sips/sip-75) was to introduce a publicly callable function to freeze any inverse Synth that was out of bounds. This was the first phase of introducing Keeper Synths, as detailed in [SIP-61](https://sips.synthetix.io/sips/sip-61).

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

#### SIP-76

The purpose of [SIP-76](https://sips.synthetix.io/sips/sip-76) was to integrate Chainlink's warning flags into Synthetix. This was used to prevent mutative action against a Synth with an invalid price.

One low risk issue relating to a potential overflow was identified during the audit. This issue was open at the conclusion of the audit. The implementation was of a high standard.

#### SIP-78

[SIP-78](https://sips.synthetix.io/sips/sip-78) modified existing functionality to ensure that inverse Synth repricing would not trigger the decentralized circuit breaker. An additional function to modify the last rate of a Synth was added. This SIP included the implementation of [SIP-36](https://sips.synthetix.io/sips/sip-36), which transitioned all remaining Synths to Chainlink pricing networks.

No issues were identified at the conclusion of the audit. The implementation was found to be of a high standard.


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

**Project Name:** Synthetix<br/>
**Commits:** [7b50bab](https://github.com/Synthetixio/synthetix/commit/7b50bab5a8156222aae065fb60a31a51080c4816)<br/>
**Files:** Exchanger.sol, MixinSystemSettings.sol, Synthetix.sol, SystemSettings.sol, TradeRewards.sol

### 3.1.2 Synthetix SIP-64 Smart Contracts

**Project Name:** Synthetix<br/>
**Commits:** [cbd5c87](https://github.com/Synthetixio/synthetix/commit/cbd5c87c0bffc3fab345ffc0905b5e5b9b62f7b3)<br/>
**Files:** ContractStorage.sol, Exchanger.sol, FeePool.sol, FlexibleStorage.sol

**Project Name:** Synthetix<br/>
**Commits:** [6125f58](https://github.com/Synthetixio/synthetix/commit/6125f587a7e6c22989e1a239ed3d3932bce79fcf)<br/>
**Files:** ExchangeRates.sol, Exchanger.sol, FeePool.sol, Issuer.sol, Liquidations.sol, MixinSystemSettings.sol, SynthetixState.sol, SystemSettings.sol

### 3.1.3 Synthetix SIP-75 Smart Contracts

**Project Name:** Synthetix<br/>
**Commits:** [bf8829e](https://github.com/Synthetixio/synthetix/commit/bf8829e9c33fbfd745aa076accee28f741c9712a)<br/>
**Files:** ExchangeRates.sol

### 3.1.4 Synthetix SIP-76 Smart Contracts

**Project Name:** Synthetix<br/>
**Commits:** [bf5ea7a](https://github.com/Synthetixio/synthetix/commit/bf5ea7a433aaab83b9fbaca92f152a52b07b20c5)<br/>
**Files:** Depot.sol, EtherCollateral.sol, ExchangeRates.sol, Exchanger.sol, FeePool.sol, Issuer.sol, Liquidations.sol, MixinSystemSettings.sol, Synthetix.sol, SystemSettings.sol

### 3.1.5 Synthetix SIP-78 Smart Contracts

**Project Name:** Synthetix<br/>
**Commits:** [50a2879](https://github.com/Synthetixio/synthetix/commit/50a2879127facda1ea716007873b5be162d13df6)<br/>
**Files:** ExchangeRates.sol, Exchanger.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-63

The specification of SIP-63 was based on commit hash [b70084b](https://github.com/Synthetixio/SIPs/blob/b70084b7e2ec91e82b3ea566cd9c334eccd31cf5/SIPS/sip-63.md).

## 4.2 SIP-64

The specification of SIP-64 was based on commit hash [99fdcbe](https://github.com/Synthetixio/SIPs/blob/99fdcbe879d3034952b4af601657598a32be5823/SIPS/sip-64.md).

## 4.3 SIP-75

The specification of SIP-75 was based on commit hash [b76ec6a](https://github.com/Synthetixio/SIPs/blob/b76ec6af91fd84fe3e83efad5eef335c64ab9e8f/SIPS/sip-75.md).

## 4.4 SIP-76

The specification of SIP-76 was based on commit hash [ce8cd6e](https://github.com/Synthetixio/SIPs/blob/ce8cd6eaa3c7c9b85c44b5c013c66e871cd74492/SIPS/sip-76.md).

## 4.5 SIP-78

The specification of SIP-78 was based on commit hash [376c795](https://github.com/Synthetixio/SIPs/blob/376c795dfa4a17278502381a7ddfa0c16b77f34e/SIPS/sip-78.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

### 5.3.1 Potentially Unsafe Arithmetic Used
*SIP-76: [ExchangeRates.sol#L498](https://github.com/Synthetixio/synthetix/blob/bf5ea7a433aaab83b9fbaca92f152a52b07b20c5/contracts/ExchangeRates.sol#L498), [ExchangeRates.sol#L520](https://github.com/Synthetixio/synthetix/blob/bf5ea7a433aaab83b9fbaca92f152a52b07b20c5/contracts/ExchangeRates.sol#L520)*

The `_getRateAndUpdatedTime` and `_getRateAndTimestampAtRound` functions made use of the `*` operator instead of a function that prevented overflows, such as the SafeMath `mul` function. It was unlikely that this would result in an overflow given the use of `AGGREGATOR_RATE_MULTIPLIER` with oracle prices; however, in the event that the oracle was used to issue a new price feed or provided a faulty value, it may result in unexpected consequences.

#### Remedial Action

A SafeMath library for `uint216` should be investigated, with the corresponding multiplication used in place of `*`.

## 5.4 Informational  

### 5.4.1 Design Comments (Informational)

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

#### `SystemSettings` Setters Missing Validation

*SIP-64: [SystemSettings.sol](https://github.com/Synthetixio/synthetix/blob/6125f587a7e6c22989e1a239ed3d3932bce79fcf/contracts/SystemSettings.sol)*

Two setter functions in `SystemSettings` did not validate the upper bounds for the setter argument. The setters, along with the corresponding impact, are listed below:

* **setWaitingPeriodSecs:** A high `waitingPeriodSecs` could cause users to have an unreasonable delay before settlement.
* **setRateStalePeriod:** An excessive stale period would result in a synth rate being valid for an extended period of time, which could result in outdated values being used in the system.

While SCCP configurable settings can only be set by the protocolDAO, it is recommended to add an upper bound for the above setters as a defence-in-depth measure.  

#### Fix Spelling and Grammatical Errors

Language mistakes were identified 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.

##### SIP-64

1. [SystemSettings.sol#L66](https://github.com/Synthetixio/synthetix/blob/6125f587a7e6c22989e1a239ed3d3932bce79fcf/contracts/SystemSettings.sol#L66): `raio` should be `ratio`.

#### Refactoring Suggestions

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

##### SIP-75

1. [ExchangeRates.sol#L189](https://github.com/Synthetixio/synthetix/blob/bf8829e9c33fbfd745aa076accee28f741c9712a/contracts/ExchangeRates.sol#L189): The revert message should be updated to `Rate not set or rate within bounds` to correspond with either revert condition.
2. [ExchangeRates.sol#L484](https://github.com/Synthetixio/synthetix/blob/bf8829e9c33fbfd745aa076accee28f741c9712a/contracts/ExchangeRates.sol#L484): `_rateOrInverted` should be renamed to `_rateOrInvertedRate`.

##### SIP-76

1. [ExchangeRates.sol#L343](https://github.com/Synthetixio/synthetix/blob/bf5ea7a433aaab83b9fbaca92f152a52b07b20c5/contracts/ExchangeRates.sol#L343): `rateIsInvalid` should be `isRateInvalid`.
2. [ExchangeRates.sol#L353](https://github.com/Synthetixio/synthetix/blob/bf5ea7a433aaab83b9fbaca92f152a52b07b20c5/contracts/ExchangeRates.sol#L353): `anyRateIsInvalid` should be `isAnyRateInvalid`.
3. [Exchanger.sol#L436](https://github.com/Synthetixio/synthetix/blob/bf5ea7a433aaab83b9fbaca92f152a52b07b20c5/contracts/Exchanger.sol#L436): `_isSynthRateInvalid` should be `_isSynthRateWithinRange` to distinguish between an invalid rate (i.e. stale or flagged) and an out-of-bounds rate that will trigger a circuit breaker.
4. [EtherCollateral.sol#L464](https://github.com/Synthetixio/synthetix/blob/bf5ea7a433aaab83b9fbaca92f152a52b07b20c5/contracts/EtherCollateral.sol#L464): `sETHRateNotInvalid` should be `sETHRateValid`.

#### Code Clean-up

*SIP-63: [TradingRewards.sol#L92](https://github.com/Synthetixio/synthetix/blob/7b50bab5a8156222aae065fb60a31a51080c4816/contracts/TradingRewards.sol#L92),[L96](https://github.com/Synthetixio/synthetix/blob/7b50bab5a8156222aae065fb60a31a51080c4816/contracts/TradingRewards.sol#L96)*

`TradingRewards.getPeriodIsClaimable` and `TradingRewards.getPeriodIsFinalized` retrieve the same value and it may not be necessary to include both getter functions unless explicitly required.

Secure your system.
Request a service
Start Now