Synthetix Mirarch Release Smart Contract Audit

# 1. Introduction
iosiro was commissioned by [Synthetix]( to conduct a smart contract audit of their Mirarch Release, which included the following components:
* [SIP-198]( - audited from 23 to 29 March 2022 by one auditor, consuming 5 resource days.
* [SIP-222]( - audited on 4 March by one auditor, consuming a total of 1 resource day.
* [SIP-229]( - audited from 27 April to 5 May by two auditors, consuming a total of 7 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 smart contracts' risk exposure better and as a guide to improving the security posture of the smart contracts by remediating issues identified. The results of this audit reflect the in-scope source code reviewed at the time of the audit.

The purpose of this audit was to achieve the following:

* Identify potential security flaws.
* Ensure that the smart contracts function according to the documentation provided.

Assessing the off-chain functionality associated with the contracts, for example, backend web application code, was outside of 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 high risk from 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. Strategies that should be used to encourage secure code development include:

* Security should be integrated into the development lifecycle, and the level of perceived security should not be limited to a single code audit.
* Defensive programming should be employed to account for unforeseen circumstances.
* Current best practices should be followed where possible.

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

This report presents the findings of a smart contract audit performed by iosiro of Synthetix's Mirarch release.  

[SIP-198]( was introduced to update the atomic exchange functionality to allow trading at pure Chainlink prices for certain synths, as well as to remove the restriction of requiring the source or destination synth to be sUSD.

Two design comments were made, one of which related to adding a slippage control to protect users in the case of a volatile spot price. Both comments were closed by the end of the audit. Overall, the code was found to be of a high standard.

[SIP-222]( updated the calculation of exchange fees to be the sum of fees for source and destination synths. This was done to account for the different levels of volatility between synths, so an appropriate fee can be charged during an exchange.

No issues were identified during the audit. Overall, the code was found to be of a high standard.

[SIP-229]( introduced a method for transferring Synths between layers using the Optimism Bridge. One high-risk and one low-risk issue were identified and closed during 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 was considered to be out-of-scope. Out-of-scope code that interacts with in-scope code was assumed to function as intended and not introduce any functional or security vulnerabilities for the purposes of this audit.

### 3.1.1 Synthetix SIP-198 smart contracts
**Project Name:** Synthetix<br/>
**Commits:** [10c683b](, [3dc2d38](<br/>
**Files:** contracts/BaseSynthetix.sol, contracts/ExchangeRatesWithDexPricing.sol, contracts/Exchanger.sol, contracts/ExchangerWithFeeRecAlternatives.sol, contracts/MixinSystemSettings.sol, contracts/Synthetix.sol, contracts/Synthetix.sol, contracts/SystemSettings.sol, contracts/SystemSettingsLib.sol

### 3.1.2 Synthetix SIP-222 smart contracts
**Project Name:** Synthetix<br/>
**Commits:** [9a3862d](<br/>
**Files:** contracts/Exchanger.sol, contracts/ExchangerWithFeeRecAlternatives.sol

### 3.1.3 Synthetix SIP-229 smart contracts
**Project Name:** Synthetix<br/>
**Commits:** [b4f5b97](<br/>
**Files:** contracts/BaseSynthetixBridge.sol, contracts/Issuer.sol, contracts/MixinSystemSettings.sol, contracts/SystemSettings.sol, contracts/SystemSettingsLib.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 was functional and to identify security issues that could be exploited.

### 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. Static analysis results were reviewed manually and any false positives were removed. Any true positive results are included in this report.

Static analysis tools commonly used include Slither, Securify, and MythX. Tools such as the Remix IDE, compilation output, and linters could also be used to identify potential areas of concern.

## 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 satisfactorily addressed, removing the risk 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-198

The specification of SIP-198 was based on commit hash [adbe570](

## 4.2 SIP-222

The specification of SIP-222 was based on commit hash [adbe570](

## 4.3 SIP-229

The specification of SIP-229 was based on commit hash [adbe570](

<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 identified during the audit were present at the conclusion of the audit.

## 5.2 Medium risk

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

## 5.3 Low risk

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

## 5.4 Informational  

### 5.4.1 Throttle rate of synth transfer

To mitigate the risk of a bug or exploit in either the Synthetix code or the Optimism messenger, a control can be put in place to throttle the rate of issuance of synths. For example, either side of the bridge can issue up to some maximum USD value every 24 hours. This does come with a trade-off for user experience, as traders who wish to transfer large sums across the bridge may need to wait a significant amount of time to move the funds across. Additionally, when the cap is hit other users of the system will not be able to use the bridge.

#### Update
Synthetix acknowledged the issue.

## 5.5 Closed

### 5.5.1 No settlement prior to transfer (high risk)

#### Description
Users should be forced to settle before being able to burn synths when calling `initiateSynthTransfer()`.

#### Recommendation
The `exchanger.settle()` function should be called when calling `initiateSynthTransfer()`.

#### Update
Implemented in [8721efd](

### 5.5.2 System-wide controls ignored (low risk)

#### Description
When calling `initiateSynthTransfer()` and `finalizeSynthTransfer()` the status of `synthActive` and `issuanceActive` should be checked to ensure that the synth can be transferred and that the system is allowing the issuance of synths.

#### Update
Implemented in [8721efd]( and [8721efd](

### 5.5.3 Atomic swap slippage control (informational)

As per SIP-120, the synth rates for atomic exchanges is the worst price between a buffered Chainlink price, the Uniswap V3 TWAP price, and the Uniswap V3 spot price. The spot price is taken as the prior block's observed price rather than the current block price to prevent flashloan style attacks. However, a large legitimate trade may swing the price to the downside, leaving the spot price to be chosen as the worst price between the three available options. For this reason, a slippage control mechanism was suggested to ensure that users receive at least a minimum amount out of their destination synth.

#### Update
Implemented in [3ed5350](

### 5.5.4 Function name refactoring (informational)

[dexPrice]( and [chainlinkPriceWithBuffer]( should be renamed to `dexValue` and `chainlinkValueWithBuffer` to indicate that the returned value is the value of the exchange, not the price or rate of a synth.

#### Update
Implemented in [42726f0](

Secure your system.
Request a service
Start Now