# 1. Introduction
iosiro was commissioned by [Synthetix](https://www.synthetix.io) to conduct a smart contract audit of their Hamal Release, which included the following component:
* [SIP-202](https://sips.synthetix.io/sips/sip-202) on 17 February 2022 with one auditor, consuming 1 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 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 Hamal release.
[SIP-202](https://sips.synthetix.io/sips/sip-202) updated how inflation was calculated in the Synthetix system, allowing for the inflation rate to change depending on whether the target staking ratio was met. Phase one of the implementation, which was in scope for this audit, relied on a privileged role to update the inflation rate on a weekly basis. Only informational issues were raised during the audit, which included an issue with conformance to the ERC-20 standard and a gas optimization.
# 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-202 smart contracts
**Commit:** [a99c341](https://github.com/Synthetixio/synthetix/pull/1700/commits/a99c3415cf01f9522cd3d9be2deebefb85d5845e) </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 test environment, both manually and through the test suite provided. Manual analysis was used to confirm that the code was functional and discover 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-202
The specification of SIP-202 was based on commit hash [9af7898](https://github.com/Synthetixio/SIPs/blob/9af7898edb0bdbe3d660334cf09f5b8fa229d3f4/content/sips/sip-202.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 identified informational issues were present at the conclusion of the audit.
## 5.5 Closed
### 5.5.1 Incorrect `Transfer` events (informational)
According to the [ERC-20 standard](https://eips.ethereum.org/EIPS/eip-20), when tokens are minted a transfer event should be emitted with the `from` address as the zero address. When calling `Synthetix.mint(...)`, which minted new tokens to various contracts, no such events were being emitted. As a result, event data for the SNX token may not match on-chain data, and applications consuming the data may display incorrect information, such as double counting tokens or indicating an incorrect total supply.
It is recommended that the relevant events are added to track the movement of tokens properly.
Implemented in [dde7e38](https://github.com/Synthetixio/synthetix/pull/1700/commits/dde7e3839419d1468f3561640431c1cb0e436447#diff-5bbf09cd847d4ed14d35c43ae0a053883df0033f6f324fc250f00c4648e38d4eR167) and [a60f376](https://github.com/Synthetixio/synthetix/pull/1700/commits/a60f376e456a08571fa17aba41f417765af74bfe#diff-5bbf09cd847d4ed14d35c43ae0a053883df0033f6f324fc250f00c4648e38d4eR142).
### 5.5.2 Gas optimization (informational)
As the boolean return value of `_supplySchedule.recordMintEvent(...)` is currently not validated, it would be more gas efficient to return the `minterReward` from the function to avoid the extra external call on [Synthetix#L147](https://github.com/Synthetixio/synthetix/blob/a99c3415cf01f9522cd3d9be2deebefb85d5845e/contracts/Synthetix.sol#L147).
Implemented in [31590d2](https://github.com/Synthetixio/synthetix/pull/1700/commits/31590d2af3c021a117a89bf64ead9b5a95aad921#diff-6b2064d05247b942c1beac2007da18b7e869aa6292189138893b0a7fe6ac4bdfR104).