iosiro was commissioned by Synthetix (formerly Havven) to conduct an audit on their Synthetix stablecoin smart contracts. The audit was performed between 23 October 2018 and 23 November 2018.
Note: At the time of the audit, Synthetix was referred to as Havven. The table below can be used to interpret the results of this report in the context of the current implementation.
|Havven Drawing Rights (HDRs)||Synthetix Drawing Rights (XDRs)|
|Nomins (e.g. nUSD)||Synths (e.g. sUSD)|
This report is organised into the following sections.
The information in this report should be used to understand the risk exposure of the smart contracts, and as a guide to improve 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.
This report presents the findings of an audit performed by iosiro on the Havven platform smart contracts. The purpose of the audit was to achieve the following.
Assessing the economics, game theory, and underlying business model of the platform were 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.
At the conclusion of the audit, two low risk issues, and several informational level and design comments remained open. One low risk issue could result in dramatic spikes in the Havven Drawing Rights (HDRs) exchange rate. The other low risk issue could result in an incorrect maximum exchange fee being enforced in future implementations of the system. The informational level findings included excessive owner privileges, as well as minor deviations from best practice and suggestions that may improve the functionality or readability of the code.
Despite the findings presented in this report, the code was found to be of a very high standard. This was evident in the use of modularised, well-documented code, using defensive programming, as well as general adherence to best practices.
A number of critical components were explicitly removed from the scope of this assessment, as they had been tested in prior security audits. This could result in blind spots that emerge as a result of individual components operating superficially as expected, but the system as a whole not integrating correctly. Specific areas of concern include the following.
The risk posed by the smart contracts can be further mitigated by using the following controls prior to releasing the contracts in a production environment.
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 security vulnerabilities for the purposes of this audit.
Project Name: Havven
Files: ExchangeRates.sol, FeePool.sol, Havven.sol, Nomin.sol, ReentrancyPreventer.sol, SafeDecimalMath.sol, TokenFallbackCaller.sol
A variety of techniques were used while conducting the audit. These techniques are briefly described below.
The source code was manually reviewed to identify potential security flaws. Code review is useful for detecting business logic flaws and high risk areas of the code.
The contracts were compiled, deployed, and tested in a Ganache test environment, both manually and through the Truffle test suite provided. Manual analysis was used to confirm that the code operated at a functional level, and to verify any potential security issues identified. The coverage report generated by solidity-coverage of the Truffle tests included in the project is given below.
|File||% Statements||% Branch||% Functions||% Lines|
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 analysed to remove false positive results. True positive results would be indicated in this report.
Static analysis was conducted using Mythril, Securify, and Oyente. Tools such as the Remix IDE, compilation output, and linters were also used to identify potential areas of concern.
Each issue identified during the audit is assigned a risk rating. The rating is determined based on the criteria outlined below.
The following section outlines the intended functionality of the system at a high level.
The Havven contract is described below.
The token should be ERC-20 compliant with the following values.
A user should be able to lock havvens within the Havven system in order to issue a proportionate number of nomins, up to the issuance ratio (initially 20%). The user should then earn fees from transactions of nomins within the system, relative to their percentage stake in the system as a whole.
If the price of havvens increases such that the collateralisation ratio for a user goes below the minimum specified amount (also initially 20%), a portion of their locked tokens should be unlocked up to the point where the collateralisation ratio reaches the minimum required collateralisation ratio again.
Alternatively, if the price of havvens drops, then the user’s havvens should be locked within the contract and be penalised on fees withdrawn from the system until either the price corrects itself or the user purchases enough havvens to correct their collateralisation ratio.
Fees collected through transfers and exchanges of nomins should be tracked through a fee pool. The fee pool should track when havvens are locked within the system to provide collateral for the nomins and should pay out fees proportionately to users depending on the amount of havvens locked and when they locked their tokens. If a user’s collateralisation ratio goes above an amount specified in the contract, the user should be penalised when trying to withdraw fees. The structure of the penalty should be as indicated in the following table.
|0% - 20%||No reduction in fees.|
|20% - 30%||25% reduction in fees.|
|30% - 40%||50% reduction in fees.|
|> 40%||75% reduction in fees.|
It should be possible for the Havven system to integrate with an escrow system.
Note: This functionality was beyond the scope of this assessment.
It should be possible for the owner of the Havven contract to add and remove nomins to the Havven system.
It should be possible for an owner of havvens to burn or issue nomins from the Havven contract. Additionally, a holder of nomins should be able to exchange their nomins held in one currency key into another currency denominated Nomin flavour for a small exchange fee.
It should be possible for the Havven system to integrate with an exchange rate contract, which should control the various exchange rates within the system. The rates should be set by an oracle contract. Rates should be considered stale if they have not been updated in more than a specified time.
Note: Oracle functionality was beyond the scope of this assessment.
It should be possible for users to set a preferred currency, automatically converting any funds that they receive in nomins to their preferred currency. If no preferred currency is set for a receiving address, the default currency should be the original currency. No fee should be charged on this exchange, as the user should be charged a fee for the transfer.
The Havven Drawing Rights is a flavour of nomins that is loosely based on Special Drawing Rights. Its exchange rate is based on a basket aggregate of currencies to minimise exposure towards any particular fiat currency. Fees are stored in this currency, and users can hold these nomins if they want to lessen their exposure to any particular fiat currency.
It should be possible to store the token balances in an external state contract to allow for seamless upgrades to the main functionality while preserving the state of the tokens and the Havven ecosystem.
Note: This functionality was beyond the scope of this assessment.
The functionality of the Nomin token smart contract is described below.
The token should be ERC-20 compliant with the following values.
It should be possible to store token balances in an external state contract to allow for seamless upgrades to the main functionality while preserving the state of the tokens and the Havven ecosystem.
Note: This functionality was beyond the scope of this assessment.
It should be possible to perform ERC-20 transfers with tokens, however, a fee should be reserved on each transfer. It should be possible for either the sender or receiver to pay the fee. Additionally, the token should implement functionality similar to the ERC-223 standard, in that it should trigger a token fallback function in a smart contract that supports the functionality. However, unlike ERC-223, the transfer should not revert if the receiving contract does not support token fallback functionality.
The following section includes in depth descriptions of the findings of the audit.
No high risk issues were present at the conclusion of the audit.
No medium risk issues were present at the conclusion of the audit.
The HDR exchange rate was found to spike when adding or removing currencies from the basket. This could result in inconsistencies in the system.
The HDR exchange rate was calculated as the summation of the exchange rates within the basket, e.g.
nUSD = 1, nEUR = 1.25, nAUD = 0.5 HDR = 1+1.25+0.5 = 2.75
While the HDR currencies were hardcoded in ExchangeRates.sol, the basket could be modified through a system upgrade or by calling
For example, if in an early version of the exchange rates contract 1,000 HDRs were issued with an exchange rate of 2.75, there would be 2,750 USD worth of HDRs in the system. Then an upgrade to the exchange rate contract adds nGBP to the basket with an exchange rate of 1.25, resulting in the HDR rate being 4. The existing holding of HDR would then suddenly become worth 4,000 USD, increasing the value represented by HDRs in the system by 1,250 USD.
This example highlights the point that it should not be possible to at any stage change the basket given the current method for calculating the HDR exchange rate. This includes adding or removing a currency.
While the impact of this issue is severe, it would be possible to incorporate logic in the new contract handling exchange rates to scale the existing HDR holdings proportionately. However, this would introduce additional complexity into the system for a one-time operation that could pose a substantial risk to the integrity of the system.
It is recommended that the HDR algorithm be modified to use weighting factors to better accommodate changes in the HDR basket to avoid potential future functional or security issues.
Our plan for upgrading the XDR rate is to introduce a replacement XDR Synth with its own rate, then allow people to exchange between these tokens using existing mechanisms. FeePool would need to handle balances in both for a transition period.
The owners of the contracts in the system were found to hold a substantial amount of control over the system. This was a design decision that allows for maintenance, upgradeability, and administration of the system. While this decision might be necessary for a certain stage of the project, it does introduce risk in the form of single points of failure throughout the system. Examples of this include being able to arbitrarily update and control the states of tokens (e.g. modifying the balances of accounts holding havvens and nomins) and changing the way that the mechanics of the system work.
This functionality could be exploited by a rogue actor (e.g. a Havven team member with malicious intent) or by a compromised private key and is noted as it extends the potential attack surface of the system. Ideally, the extent of owner capabilities should be limited over time and eventually removed. While the Havven team could conspire against their users, it would undermine the integrity of the system and would act against their best interests in ensuring the stability and long-term viability of the network.
As a user of the Havven system, it is important to keep in mind that this increases the risk of real-world influence, as a centralised system is more likely to be affected by legislative or political events. Recent examples of this include IDEX and ShapeShift introducing Know Your Customer (KYC) requirements for their users.
The risk of a single rogue actor or a compromised private key can be mitigated by ensuring that a high standard of security is observed by the owner account. For example, the owner account should be a multi-signature wallet, signed by properly secured hardware backed addresses.
In order to support the upgradability of the contracts the owner requires these privileges, once the system is stable these capabilities will be removed.
Actions to improve the functionality and readability of the codebase are outlined below.
currencyKeysshould be required to match the length of
ExchangeRates.sol: Line 83
It was found that the constructor of ExchangeRates could contribute to predictable spikes in the HDR rate value if not correctly initialised with all the currencies in
currencyKeys. By not validating the length of
currencyKeys against the length of
hdrParticipants, it opens the possibility for the HDR rate to incorrectly reflect the HDR price until the missing value is added. This problem is apparent when we consider line 169 of ExchangeRates.sol where each
hdrParticipant currency is totalled. In the case when the missing
currencyKey rate is finally added, after initially being un-initialised, the rate of HDR spikes as a result of
total now accounting for the newly added
currencyKey rate. It is recommended that the
require on line 83 of ExchangeRates.sol be changed to also verify the initial value of each constituent
currencyKey is present upon initialisation:
require(_currencyKeys.length == _newRates.length, "Currency key length and rate length must match.");
require(_currencyKeys.length == hdrParticipants.length, "Currency key length and HDR participants length must match");
We have decided not to action this feedback because even if we specified an opening rate for each one of the XDR currencies, they can always go stale, which would impact that rate in any case. The oracle protects against this, but we can’t enforce this in the constructor, so we felt like it would add additional complexity to the deployment without providing a benefit.
SafeMath.sol: Line 1
removeNomin(...) function required the total supply of the Nomin being removed to be zero. This was presumably a protective measure to prevent a Nomin from being removed if user funds were stored in it. However, on a practical level, this would likely prevent a Nomin from ever being removed once it was in use by users. One potential workaround to this problem would be to exploit the
burn(...) functionality to manually exchange a user’s tokens, however, this could be deemed as an abuse of power. While this is not a security issue, it is noted as it may introduce functional issues down the line.
The idea behind this code was to give us a way to remove a Synth as long as it was only being tested, once people hold it, we no longer have the ability to remove it. The code prevents removal of a synth from the network without a larger contract upgrade.
It was found that the implicit type
uint was used consistently throughout the project. It is suggested that these
uint type declarations be replaced with the more explicit
uint256 type declaration, where appropriate, in order to adhere to best practice.
While the size of default uint could change between solidity versions, it would be a significant breaking change. At this stage we have quite a few of these around the code base, so rather than changing it, we believe the best approach is to leave it for the time being, changing it to a more specific type if required (e.g. if uintchanges in a breaking solidity version).
The pragma version was not fixed to a specific version, as it specified
^0.4.24, which would result in using the highest non-breaking version (highest version below
0.5.0). According to best practice, where possible, all contracts should use the same compiler version, which should be fixed to a specific version. This helps to ensure that contracts do not accidentally get deployed using an alternative compiler, which may pose the risk of unidentified bugs. An explicit version also helps with code reuse, as users would be able to see the author’s intended compiler version. It is recommended that the pragma version is changed to a fixed value, for example
As the SafeMath.sol contract is a dependency managed via NPM, it’d be best to feed this back up to the OpenZeppelin team. I suspect they would want to manage it more comprehensively for their whole library. The rest of our contracts use a hard 0.4.25 peg, so it wouldn’t be possible to compile and deploy these without using 0.4.25, so we didn’t see any specific action to take other than to suggest feeding this back to OpenZeppelin.
Version 0.4.25 of the Solidity compiler was used throughout the project. At the time of writing, no publicly available security reviews of the target version were available. A comprehensive security review was performed by the Zeppelin team on version 0.4.24 with several issues being identified and rectified in 0.4.25. As a result, no change is recommended. However, it is worth noting that there is a possibility that new, unknown vulnerabilities exist in the version used.
Noted, we’ll keep an eye out for audits / future versions.
FeePool.sol: Line 124
It was found that the
setExchangeFeeRate(...) function incorrectly used
MAX_TRANSFER_FEE_RATE for validation rather than
MAX_EXCHANGE_FEE_RATE. As the constants were set to the same value it did not present a security or functional risk in this version of the contract. If in future contract upgrades or versions these rates are not equal, this incorrect validation may inadvertently impact the functionality of the contract.
It is recommended that the
MAX_EXCHANGE_FEE_RATE be used to determine the maximum fee exchange rate.
Fixed in 65c9169.
decimalsdoes not match ERC-20 standard
ExternStateToken.sol: Line 54 Havven.sol: Line 151 Nomins.sol: Line 47
It was found that the
decimals variable was defined using an implicit
uint (an alias for
uint256) type as opposed to the
uint8 type as in the ERC-20 standard. Although not strictly a security or functional issue, it is recommended that the type be changed to adhere to the ERC-20 standard and as a minor optimisation.
Fixed in fc436da.
Havven.sol: Line 261
It was found that the
sethavvenState(...) function did not match the case conventions of other function names. While not a functional or security issue, it is recommended that the function name be changed to
setHavvenState(...) to be more consistent with the function case convention present elsewhere.
Fixed in ca772fd.
Certain comments in the code were found to incorrectly describe the intended functionality of the codebase, these are detailed below.
address(0)or the message sender incur no fee. However, calls to
exchange(...)always incur a fee, and if
exchange(...)is called with a destination of
address(0), the destination is changed to the message sender.
While most of the codebase contained high-quality comments, some portions of the code had no comments. While in some cases the intention of the code was apparent in the naming conventions (e.g.
transferSenderPaysFee(...)), in other instances the code was highly complex and had no supporting comments. In order to improve the readability, maintainability, and extensibility of the codebase, it is recommended that comments are added to the affected areas. These areas are listed below.
FeePool.sol: missing module description.
Havven.sol: missing function description for
FeePool.sol: missing function description for
ExchangeRates.sol: Line 139
While validation logic was included to ensure that the oracle did not set values too far into the future, no validation was performed to ensure that the rate was, in fact, a more recent exchange rate than the current one. This would allow an oracle to potentially update the exchange rate with an older exchange rate. A mitigating factor was that the old rate would still require that the older rate be more recent than the stale period specified in the contract.
Fixed in b20b75f.
Review of the code coverage results revealed several critical operations in the smart contract logic that were untested in what was otherwise a relatively comprehensive test suite. It is recommended that the test suite be expanded to cover the remaining uncovered branches:
truein the function
Havven.sol: Line 265
Lines 266 through 268 of Havven.sol mentioned that an event indicating that the Havven State had been changed was removed to reduce the contract size. However, it is recommended that this functionality be included if possible. From a transparency perspective, it would be helpful for users to be able to track when the Havven State is updated given the amount of trust placed in the Havven team for governance and maintenance of the project.
Fixed in 4876fd3.
Typos were identified within certain comments in the codebase, these are outlined below.
75% reduction in feesshould read as
75% reduction in feesin order to follow the format of the lines that preceed it.
... fee period
does is not
yet ready...should be
... fee period
currencyKeysarray as ‘rates’ instead of ‘keys’.
Interested in getting your smart contracts audited? Request a Quote
This is a limited report on our findings based on our analysis, in accordance with good industry practice as at the date of this report, in relation to: (i) cybersecurity vulnerabilities and issues in the smart contract source code analysed, the details of which are set out in this report, (Source Code); and (ii) the Source Code compiling, deploying and performing the intended functions. In order to get a full view of our findings and the scope of our analysis, it is crucial for you to read the full report. While we have done our best in conducting our analysis and producing this report, it is important to note that you should not rely on this report and cannot claim against us on the basis of what it says or doesn’t say, or how we produced it, and it is important for you to conduct your own independent investigations before making any decisions. We go into more detail on this in the below disclaimer below – please make sure to read it in full.
DISCLAIMER: By reading this report or any part of it, you agree to the terms of this disclaimer. If you do not agree to the terms, then please immediately cease reading this report, and delete and destroy any and all copies of this report downloaded and/or printed by you. This report is provided for information purposes only and on a non-reliance basis, and does not constitute investment advice. No one shall have any right to rely on the report or its contents, and Zenoic Proprietary Limited trading as “Iosiro” and its affiliates (including holding companies, shareholders, subsidiaries, employees, directors, officers and other representatives) (Iosiro) owe no duty of care towards you or any other person, nor does Iosiro make any warranty or representation to any person on the accuracy or completeness of the report. The report is provided "as is", without any conditions, warranties or other terms of any kind except as set out in this disclaimer, and Iosiro hereby excludes all representations, warranties, conditions and other terms (including, without limitation, the warranties implied by law of satisfactory quality, fitness for purpose and the use of reasonable care and skill) which, but for this clause, might have effect in relation to the report. Except and only to the extent that it is prohibited by law, Iosiro hereby excludes all liability and responsibility, and neither you nor any other person shall have any claim against Iosiro, for any amount or kind of loss or damage that may result to you or any other person (including without limitation, any direct, indirect, special, punitive, consequential or pure economic loss or damages, or any loss of income, profits, goodwill, data, contracts, use of money, or business interruption, and whether in delict, tort (including without limitation negligence), contract, breach of statutory duty, misrepresentation (whether innocent or negligent) or otherwise under any claim of any nature whatsoever in any jurisdiction) in any way arising from or connected with this report and the use, inability to use or the results of use of this report, and any reliance on this report.