Audit Report
Pentacore Smart Contract Audit

# 1. Introduction

iosiro was commissioned by Pentacore to conduct an audit on their token and crowdsale smart contracts for their ICO. The audit was performed between 03 April 2018 and 09 April 2018. On 16 April 2018, a review was performed to confirm that issues identified in this report had been sufficiently addressed.


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 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.


<a name="section-2"></a>

# 2. Executive Summary

This report presents the findings of an audit performed by iosiro on their token and crowdsale smart contracts. The purpose of the audit was to achieve the following.


* Ensure that the smart contracts functioned as intended.  

* Identify potential security flaws.


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 wherever possible.  


The audit originally identified several high, medium, low, and informational risk issues with the smart contracts. The majority of the issues were marked as closed at the time of the review, indicating that the issues had been sufficiently addressed. One outstanding high risk issue remained open at the end of the review, allowing the owner of the token to arbitrarily change the way that tokens are issued to users.


The code was found to be of a high quality. It was well designed and clearly written, separated token and crowdfund logic, and made use of commonly used libraries where possible.


The risk posed by the smart contracts can be further mitigated by using the following controls prior to releasing the contracts to a production environment.


* Use a public bug bounty program to identify security vulnerabilities.

* Perform additional audits using different teams.


<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 any other files are considered to be out-of-scope.

### 3.1.1 PentaFund

**Project Name:** SmartContracts<br/>

**Commit:** [0dd770f](https://github.com/PentaFund/SmartContracts/tree/0dd770fa5d137bb8d4bdc8bf4189cfdc1abfc9fb), [29deca2](https://github.com/PentaFund/SmartContracts/commit/29deca2033a6e230723c6210b5362e201328acb2), [f5222a8](https://github.com/PentaFund/SmartContracts/tree/f5222a8505d8f27562d725e7c4cef526ad7075a9#diff-5d7f7210fd696913c52f34a06a7c8438)<br/>

**Files:** PentacoreCrowdsale.sol, PentacoreToken.sol


## 3.2  Methodology


A variety of techniques were used to perform the audit, these are outlined below.


### 3.2.1 Dynamic Analysis


The contracts were compiled, deployed, and tested using both Truffle tests and manually on a local test network. A number of pre-existing tests were included in the project.


### 3.2.2 Automated Analysis


Tools were used to automatically detect the presence of potential vulnerabilities, such as reentrancy, timestamp dependency bugs, transaction-ordering dependency bugs, and so on. Static analysis was conducted using Mythril and Oyente. Additional tools, such as the Remix IDE, compilation output and linters were used to identify potential security flaws.


### 3.2.3 Code Review

Source code was manually reviewed to identify potential security flaws. This type of analysis is useful for detecting business logic flaws and edge-cases that may not be detected through dynamic or static analysis.


## 3.3  Risk Ratings


Each Issue identified during the audit is assigned a risk rating. The rating is dependent on the criteria outlined below..


* **High Risk** - The issue could result in a loss of funds for the contract owner or users.

* **Medium Risk** - The issue results in the code specification operating incorrectly.

* **Low Risk** - A best practice or design issue that could affect the security standard of the contract.

* **Informational** - The issue addresses 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.


<a name="section-4"></a>

# 4. Design Specification


The following section outlines the intended functionality of the smart contracts.


## 4.1 Token


The token is described below.


#### ERC20 Token


The token implements the ERC20 standard.


Field        | Value
------------ | -------------
Symbol       | PENT
Name         | PentacoreToken
Decimals     | 18
Total Supply | 1,000,000,000


#### NAV/Token

A Net Asset Value (NAV) per token ratio can be set by the NAV Admin.


#### Wei/USD

A wei per USD price can be set by the NAV Admin.


#### Mintable

Rather than creating an initial total supply of tokens, tokens are created through a manual minting process called by the crowdsale contract.


#### Pausable

Pentacore has the ability to pause and unpause transfers of the token.


#### Whitelist

All ERC-20 functionality, including transferring tokens, is restricted to whitelisted addresses, except for the `decreaseApproval` function. This allows users who are removed from the whitelist to remove their tokens from a decentralized exchange.


*Commit f5222a8 introduced the ability to control whether the whitelist was enforced. If the `isFreeTransferAllowed` boolean was disabled, tokens could be transferred to and from non-whitelisted addresses.*


#### Burnable

It is possible for a contract, deemed the redemption contract, to burn tokens. This is intended to be used when token holders would like to exchange their PENT tokens for ETH.


#### Access Control

An access control list is maintained within the contract to restrict specific actions to specific roles. These different roles are outlined below.


* Owner - has the ability to set the address of each role and pause the token.

* KYC Admin - has the ability to add and remove users from the whitelist.

* NAV Admin - has the ability to set the NAV/USD and ETH/USD rates.

* Crowdsale - has the ability to pause the token and mint new tokens.

* Redemption - has the ability to burn tokens.

* Distributed Autonomous Exchange - has no special permissions in the token contract.


## 4.2 Crowdsale


The crowdsale is described below.


#### Duration


The initial duration of the ICO is 4 weeks, however, a post-ICO phase allows the ICO to run in perpetuity at the discretion of Pentacore.


#### Cap


During the ICO, a total of 50 million tokens are available. There is no cap in the post-ICO phase other than the 1 billion token cap of the token.


#### Minimum Purchase


The crowdsale allows a minimum of 100 PENT tokens to be purchased.


#### Centralized Distribution


There are two ways of purchasing PENT tokens from the crowdsale.


1. Purchase tokens directly from the crowdsale at a variable rate set by Pentacore.

2. Purchase tokens through an off-chain system. The owner of the crowdsale has the ability to call an `externalPurchase(...)` function, which allocates tokens to a specified address, bypassing any on-chain checks for a valid transfer of value.


<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


### 5.1.1 Possible to Change Crowdsale Address

*PentacoreToken.sol: line 109 - 111*


#### Description


It was possible to change the crowdsale address of the token at any stage through a function `setCrowdsaleContract(address _address)`. As the crowdsale address is the only address permitted to mint new PENT tokens, the ability to control the address also allows the ability to set new rules that govern how the token can be minted. From an investor’s perspective, this effectively allows Pentacore to arbitrarily control the way that new tokens are minted in the future.


#### Remedial Action


It is recommended that the ability to change the crowdsale contract address is only permitted before the ICO has started. In order to effectively apply this change, it would be necessary to have a reliable way of tracking when the ICO has started. One implementation of this is described in Section 5.5.5.


#### Update


No action taken. The ability to change the crowdsale smart contract is included by design. The team’s justification for this is that if regulations are changed for securities for any reason, they may need to change the way that distribution works.


## 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 Low Test Coverage

*General*


#### Description


Tests, if correctly written, provide assurance that code is performing as expected. In this instance, the tests were Truffle framework tests that would deploy and execute the code locally via ganache-cli.


The coverage was low for a number of the contracts, as ideally one would have complete coverage across all the files used. While testing should not be used as the only measure of functionality, it can be helpful in identifying faults in logic, both at a data flow and business level.


#### Remedial Action


It is recommended that the test suite is extended to achieve a higher level of coverage.


## 5.5 Closed


### 5.5.1 Minting Modifier Disabled (High)


*PentacoreToken.sol: line 202*


#### Description


The audit revealed that the modifier used to restrict who was able to mint new tokens was commented out. As such, any address would be able to call the `mint()` function, creating new tokens.


#### Remedial Action


It is recommended that the `onlyBy(crowdsale)`modifier be uncommented, correctly restricting access to the function to only the crowdsale address.


#### Implemented Action


Fixed as proposed in [29deca2](https://github.com/PentaFund/SmartContracts/commit/29deca2033a6e230723c6210b5362e201328acb2), PentacoreToken.sol line 222.


### 5.5.2 Potential Overflow (Medium)


*PentacoreCrowdsale: line 76*<br/>

*PentacoreCrowdsale: line 166*


#### Description


It was found that mathematical operations were performed using built in operators, such as `+`. Performing operations in this fashion can be unsafe as it can lead to potential underflow and overflow conditions that would result in incorrect values being returned.


#### Remedial Action


It is recommended that mathematical operations are performed using the SafeMath equivalent.


#### Implemented Action


Fixed as proposed in [29deca2](https://github.com/PentaFund/SmartContracts/commit/29deca2033a6e230723c6210b5362e201328acb2), PentacoreCrowdsale.sol line 78 and 169.


### 5.5.3 Token Uses No Decimals (Medium)


*PentacoreToken: General*


#### Description


While the specification defined the number of token decimals to be 18, no decimals were found to be used. This can cause problems when interacting with other smart contracts as tokens with 0 decimals can cause rounding errors. For example, many exchanges charge a small fee based on the tokens exchanged. As such, using no decimals will either make it impossible to list the token on these exchanges or it will result in having expensive fees compared to other tokens.


#### Remedial Action


It is recommended that one of the following actions is taken.


* The specification is updated to reflect that no decimals are being used.

* That the token values are correctly calculated using decimals. An example of how to do this can be found in the [SimpleToken](https://github.com/OpenZeppelin/zeppelin-solidity/blob/master/contracts/examples/SimpleToken.sol) OpenZeppelin sample token, which also happens to inherit from StandardToken. As this change needs to be applied consistently and can affect calculations, it is recommended that extensive testing it done to ensure that it does not introduce errors in the code.  


#### Implemented Action


Fixed in [29deca2](https://github.com/PentaFund/SmartContracts/commit/29deca2033a6e230723c6210b5362e201328acb2), README.md line 9. The specification has been changed to describe the token as having 0 decimals.


### 5.5.4 Unable to Burn All Funds (Low)


*PentacoreToken.sol: line 220, 221*


#### Description


The assertions used in the `burn()` function were found to require a balance of at least 1 to remain after performing the burn. As such, it would not be possible to burn all funds stored by the redemption contract, which is presumably undesirable.


#### Remedial Action


It is recommended that the identified lines are changed from `>` (greater than) to `>=` ( greater than or equal to).


#### Implemented Action


Fixed as proposed in [29deca2](https://github.com/PentaFund/SmartContracts/commit/29deca2033a6e230723c6210b5362e201328acb2), PentacoreToken.sol lines 240 and 241.


### 5.5.5 Design Comments (Informational)


*General*


Actions that may improve the functionality and readability of the codebase are outlined below.


#### Unnecessary differentiation of states


The crowdsale had three distinct states:


1. Before the ICO

2. During the ICO

3. Post ICO


The only distinctions between States 2 and 3 were:


* A cap of 50 million tokens was set on the number of tokens available in State 2.

* State 2 was time restricted to a 4 week period.


As can be seen, no functional differences separated the two states, for example there was no difference in pricing, purchasing limits, whitelisting requirements, etc. Additionally, State 3 was intended to be used as a switch to control additional sales rounds. As such, one of the following is recommended.


* If token and time cap abilities are a requirement for the initial crowdsale, this functionality should be abstracted to allow future post ICO sales rounds the same functionality. This would still likely reduce the attack surface, as the initial crowdsale would be a single instance of this abstracted implementation, rather than a completely separate type of sale.

* If these features are not a requirement, it is recommended that State 2 be removed entirely and that there be only two states. The initial crowdsale can be manually controlled via a flag, in the same way that the post ICO phase operated.


*Update: No action taken.*


#### No restriction on `startICO()`


It was found that that `startICO()` function in PentacoreCrowdsale could be called at any stage, including during or after the initial crowdsale. As such, the crowdsale state could run indefinitely. It is recommended that a boolean is used to determine whether the ICO has started and that if it has that `startICO()` can not be called again. The post ICO phase would not be affected by this change, as it could still continue indefinitely.


*Update: Fixed in [29deca2](https://github.com/PentaFund/SmartContracts/commit/29deca2033a6e230723c6210b5362e201328acb2), PentacoreCrowdsale.sol line 72.*


#### Unspecified variable visibility


Some state variables, including the variables storing the state of access control, were found to have have an unspecified visibility. As such, they defaulted to `internal` visibility. As these values were used to determine who had access to specific functionality, it is highly recommended that these variables are made `public` to avoid confusion. It is still possible to view internal variables, as all the information on the Ethereum network, including private state variables are publicly available. However, it simply makes the process of determining these values unnecessarily complicated.


It is recommended that the following changes are made.


* PentacoreCrowdsale: line 21 should be set to public.

* PentacoreToken: lines 37 - 42 should be set to public.


*Update: Fixed in [29deca2](https://github.com/PentaFund/SmartContracts/commit/29deca2033a6e230723c6210b5362e201328acb2), PentacoreCrowdsale.sol line 21, PentacoreToken.sol 37 - 42.*


#### External purchases


The `externalPurchase()` function could be used to mint new tokens at the discretion of the contract owner. As such, users place a large amount of trust in Pentacore that token purchases are reliably made. One method that could be used to increase user trust for purchases made on other chains would be to include a respective transaction hash for the specific allocation. For example, if bitcoin is used to purchase PENT tokens, the `ExternalTokenPurchase` event could emit not only the currency and amount, but also the transaction hash of the transaction, which users could verify themselves.


*Update: Fixed in [29deca2](https://github.com/PentaFund/SmartContracts/commit/29deca2033a6e230723c6210b5362e201328acb2), a parameter for transaction IDs has been included in the `ExternalTokenPurchase` event.*


#### Whitelist array functions


A common practice is to have array based whitelist functions, e.g. `addManyToWhitelist(address[])` and `removeManyToWhitelist(address[])`. When it is anticipated that a large number of addresses will need to be added to a whitelist, this can help expedite the process. An example implementation is given below.

<pre>

<code class="language-solidity" >

function addManyToWhitelist(address[] _beneficiaries) external onlyOwner {

   for (uint256 i = 0; i < _beneficiaries.length; i++) {

       whitelist[_beneficiaries[i]] = true;

   }

}

</code>

</pre>


*Update: Whitelisting array functions included in [29deca2](https://github.com/PentaFund/SmartContracts/commit/29deca2033a6e230723c6210b5362e201328acb2).*


#### Whitelist data structure


A mapping was used to maintain a list of whitelisted addresses. While this provides a simple way of keeping track of which addresses are whitelisted, it does not provide a way to retrieve a complete list of all the currently whitelisted addresses. It may be useful to consider an alternative or additional data structure in order to achieve this functionality, as whitelisting forms an important part of this token. An in-depth discussion of alternatives data structures can be found [here](https://ethereum.stackexchange.com/questions/13167/are-there-well-solved-and-simple-storage-patterns-for-solidity).


*Update: Whitelisting events added in [29deca2](https://github.com/PentaFund/SmartContracts/commit/29deca2033a6e230723c6210b5362e201328acb2).*


#### Inexact solidity compiler version used


The pragma version was not fixed to a specific version, as it specified `^0.4.18`, 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 `0.4.18`.


*Update: Addressed in [29deca2](https://github.com/PentaFund/SmartContracts/commit/29deca2033a6e230723c6210b5362e201328acb2).*


#### Use of timestamp


The `now` keyword (an alias for `block.timestamp`) is used to determine the current time. This value can be marginally affected by miners (by up to 900 seconds), so a common best practice is to rather use `block.number` to determine the time. However, the risk posed in this circumstance is inconsequential, and it is simply listed for completeness. No action is required.


*Update: No action taken.*


Secure your system.
Request a service
Start Now