# 1. Introduction
iosiro was commissioned by [Synthetix](https://www.synthetix.io) to conduct a smart contract audit of their Izar Release, which included [SIP-2011](https://sips.synthetix.io/sips/sip-2011). Two auditors performed the audit between 21 April 2023 and 25 April 2023, consuming 5 audit 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.
# 2. Executive summary
This report presents the findings of a smart contract audit performed by iosiro of Synthetix's Izar release.
[SIP-2011](https://sips.synthetix.io/sips/sip-2011) resolved issues in perps V2, including
* The execution of pending orders could no longer be controlled and abused by traders.
* Pending orders for underwater positions could not delay the flagging and liquidation of a position.
* A helper function used to return market summaries was updated to accommodate legacy and V2 markets.
One medium risk, one low risk, and one informational issue were identified during the audit. All of the issues were appropriately addressed by the end of the audit.
# 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-2011 smart contracts
**Project Name:** Synthetix<br/>
**Commits:** [0125eec](https://github.com/Synthetixio/synthetix/pull/2065/commits/0125eecc11538a2d2670a4db4b5aa517836aff42), [566a85b](https://github.com/Synthetixio/synthetix/pull/2071/commits/566a85b4dc6691f9aff56fb9f1bf37664c2500db), [b358aac](https://github.com/Synthetixio/synthetix/pull/2066/commits/b358aacafc61b287b0d99aa39325585a079a7ac8)<br/>
**Files:** PerpsV2Market.sol, PerpsV2MarketLiquidate.sol, PerpsV2MarketData.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.
# 4. Design specification
The following section outlines the intended functionality of the system at a high level.
## 4.1 SIP-2011
The specification of SIP-2011 was based on commit hash [f5e26cb](https://github.com/Synthetixio/SIPs/blob/f5e26cba9355469ebcfbd3f9c24e5447dcd52bb2/content/sips/sip-2011.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 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
No informational issues identified during the audit were present at the conclusion of the audit.
## 5.5 Closed
### 5.5.1 Restrict functions that could affect positions with pending delayed orders (medium risk)
To thoroughly protect the system from users being able to control the execution of their delayed orders, all user-controlled functions that could impact the execution of a pending delayed order should be protected. In addition to restricting the `_transferMargin()` function when there is a pending delayed order, the `_modifyPosition()` and `_closePosition()` functions should be restricted similarly.
Implemented in [0125eec](https://github.com/Synthetixio/synthetix/pull/2065/commits/0125eecc11538a2d2670a4db4b5aa517836aff42).
### 5.5.2 Accrue funding for flagged positions with commit deposits (low risk)
When flagging a position for liquidation that has a pending delayed order with a commit deposit, the margin does not accrue funding and recompute the margin.
The margin is recomputed at the time of liquidation, and as such, the difference in accrued time should be relatively small and the case should be fairly unlikely as commit deposits have been deprecated. Accounts flagged with a commit deposit could incorporate accrued funding to correctly track the margin; however, the change may be deemed unnecessary.
The Synthetix team accepted the risk.
### 5.5.3 Missing events (informational)
1. When flagging a position, an event should be emitted to indicate that the commit deposit is returned to the account’s margin.
2. The `emitPositionFlagged` event should include the price to facilitate tracking price movements between flagging and liquidation.
1. Implemented in [6f8a4ea](https://github.com/Synthetixio/synthetix/commit/6f8a4eaf6800d4e2d7486f47dbbab822f99a5b96).
2. Implemented in [6f8a4ea](https://github.com/Synthetixio/synthetix/commit/6f8a4eaf6800d4e2d7486f47dbbab822f99a5b96).