# 1. Introduction
iosiro was commissioned by [Synthetix](https://www.synthetix.io) to conduct a smart contract audit of the implementation of [SIP-116](https://sips.synthetix.io/sips/sip-116), [SIP-117](https://sips.synthetix.io/sips/sip-117), and [SIP-118](https://sips.synthetix.io/sips/sip-118) for the Alnair Release. The audit was performed as follows:
* SIP-116: one auditor on 04 March to 05 March and one auditor on 22 April 2021 to 28 April 2021, consuming a total of seven resource days.
* SIP-117: one auditor on 01 March 2021 to 05 March 2021 and one auditor on 01 March to 04 March 2021 consuming a total of nine resource days.
* SIP-118: one auditor on 05 March 2021 consuming a total of one resource day.
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.
# 2. Executive summary
This report presents the findings of the audit performed by iosiro of the smart contract implementation of [SIP-116](https://sips.synthetix.io/sips/sip-116), [SIP-117](https://sips.synthetix.io/sips/sip-117), and [SIP-118](https://sips.synthetix.io/sips/sip-118).
The purpose of [SIP-116](https://sips.synthetix.io/sips/sip-116) was to update the Optimism bridge to conform to the new standard bridge interface being adopted by the community, as well as improving the upgrade mechanism to remove the need to wait for withdrawals to finalize.
Two informational issues were discovered, relating to backwards incompatibility and improper event emission; the latter has been remediated.
Overall, the implementation was of a high standard and accorded with the specification provided.
[SIP-117](https://sips.synthetix.io/sips/sip-117) was introduced to allow users to exchange synths on Optimism. No issues were identified during the audit. Overall, the implementation was of a high standard and accorded with the specification provided.
The purpose of [SIP-118](https://sips.synthetix.io/sips/sip-117) was to skip fee reclamation if the waiting period is 0, which will be the case on Layer 2. This was done to take advantage of the reduced risk of frontrunning on Optimistic Ethereum. No issues were identified during the audit. Overall, the implementation was of a high standard and accorded with the specification provided.
# 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-116 smart contracts
**Project name:** Synthetix<br/>
**Files:** BaseSynthetixBridge.sol, SynthetixBridgeEscrow.sol, SynthetixBridgeToBase.sol, SynthetixBridgeToOptimism.sol
### 3.1.2 Synthetix SIP-117 smart contracts
**Project name:** Synthetix<br/>
**Files:** BaseDebtCache.sol, BaseSynthetix.sol, Collateral.sol, CollateralManager.sol, DebtCache.sol, Exchanger.sol, Issuer.sol, RealtimeDebtCache.sol, Synthetix.sol
### 3.1.3 Synthetix SIP-118 smart contracts
**Project name:** Synthetix<br/>
## 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.
# 4. Design specification
The following section outlines the intended functionality of the system at a high level.
## 4.1 SIP-116
The specification of SIP-116 was based on commit hash [1aeae51](https://github.com/Synthetixio/SIPs/blob/1aeae51204883e6a0f36fed601976bb232d6b089/sips/sip-116.md).
## 4.1 SIP-117
The specification of SIP-117 was based on commit hash [86cd7a0](https://github.com/Synthetixio/SIPs/blob/86cd7a0b6f8cc6954c86d9b416cfc20a712bb5d4/sips/sip-117.md).
## 4.1 SIP-118
The specification of SIP-118 was based on commit hash [86a8fce](https://github.com/Synthetixio/SIPs/blob/86a8fcef0dab66e9c516030ad5a997a9f69c15be/sips/sip-118.md).
# 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 Backwards incompatiblity
*SIP-116: SynthetixBridgeToBase.sol, SynthetixBridgeToOptimism.sol*
In `SynthetixBridgeToBase`, the function name `initiateWithdrawal` was changed to `withdraw`, and in `SynthetixBridgeToOptimism`, the function name `initiateDeposit` was changed to `deposit`. As these are external functions, this change will break backwards compatibility with any existing external contracts. Such contracts would need to be modified and redeployed to account for the changed function signatures.
To maintain backwards compatibility, functions with the previous names which passed all parameters to the new functions could be included in the contracts.
## 5.5 Closed
### 5.5.1 Proxy emit pattern not used (informational)
A subset of functions in `SynthetixBridgeToBase` emitted events directly instead of through the proxy, as was done in most functions. This would prevent events from being recorded against the expected contract.
To ensure correct emission of all events, the `proxy._emit` pattern should be used in place of the following direct event emissions:
Remediated in [327dfea](https://github.com/Synthetixio/synthetix/pull/1212/commits/327dfea50c357970a859d3b4ffdd279bbbcc2191) and [df8e997](https://github.com/Synthetixio/synthetix/pull/1212/commits/df8e99777f5382462414d4ea83559baf77f3186d).