iosiro
blockchain security

PENT Crowdsale Audit

Audit Results

 
pent-logo.png
 
 
 

Disclaimer

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.

Table of Contents

Disclaimer    
1. Introduction    
2. Executive Summary    
3. Audit Details    
  3.1 Scope    
    3.1.1 PentaFund    
  3.2  Methodology    
    3.2.1 Dynamic Analysis    
    3.2.2 Automated Analysis    
    3.2.3 Code Review    
  3.3  Risk Ratings    
4. Smart Contract Descriptions    
  4.1 PentacoreToken.sol    
  4.2 PentacoreCrowdsale.sol    
5. Detailed Findings    
  5.1 High Risk    
    5.1.1 Possible to Change Crowdsale Address    
  5.2 Medium Risk    
  5.3 Low Risk    
  5.4 Informational    
    5.4.1 Low Test Coverage    
  5.5 Closed    
    5.5.1 Minting Modifier Disabled (High)    
    5.5.2 Potential Overflow (Medium)    
    5.5.3 Token Uses No Decimals (Medium)    
    5.5.4 Unable to Burn All Funds (Low)    
    5.5.5 Design Comments (Informational)
 

Introduction

iosiro was commissioned by Pentacore to conduct an audit on their token sale smart contracts. 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: A high-level description of the findings of the audit.
  • Section 3 - Audit Details: A description of the scope and methodology of the audit.
  • Section 4 - Smart Contract Descriptions: Descriptions of the intended functionality of the smart contracts.
  • Section 5 - Detailed Findings:  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.

2. Executive Summary

This report presents the findings of an audit performed by iosiro on the Pentacore crowdfund 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.

  • Extend the coverage of the test suite.
  • Use a public bug bounty program to identify security vulnerabilities.
  • Perform additional audits using different teams.

3. Audit Details

3.1 Scope

The source code considered in-scope for the assessment is described below. Code from any other files is considered to be out-of-scope.

3.1.1 PentaFund

Project Name: SmartContracts

Files: PentacoreCrowdsale.sol, PentacoreToken.sol

Commits: 0dd770f, 29deca2, f5222a8

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. The coverage of these tests can be found in Appendix II.

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. Issues identified through these means were manually investigated to determine whether they posed any risk.

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 previously identified and has since been addressed to a satisfactory level to remove the potential risk that it posed.

4. Smart Contract Descriptions

The following section outlines the intended specification for the smart contracts based on information provided from the Pentacore team.

Note: these descriptions are based on the specification provided and does not reflect the actual state of the code. The descriptions below are used to find discrepancies between code and the intended operation, which would be highlighted in Section 5.

4.1 PentacoreToken.sol

The token used for the crowdsale. A description of the intended functionality is given below.  

ERC20 Token

The token implements the ERC20 specification.

Total Supply

The total supply is 1 billion PENT

Decimals

The token should have 18 decimals.

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 ERC20 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 PentacoreCrowdsale.sol

The crowdsale logic used for the crowdsale. A description of the intended functionality is given 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.

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 of the tests can be seen in Appendix II.

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.

Update

This issue is currently a work in progress.

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, PentacoreToken.sol line 222.

5.5.2 Potential Overflow (Medium)

PentacoreCrowdsale: line 76
PentacoreCrowdsale: line 166

Description

It was found that mathematical operations were performed using built in operators, such as + (add). 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, 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 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, 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, 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.

Implemented Action

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.

Implemented Action

Fixed in 29deca2, PentacoreCrowdsale.sol line 72.

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.

Implemented Action

Fixed in 29deca2, 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.

Implemented Action

Fixed in 29deca2, 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.

function addManyToWhitelist(address[] _beneficiaries) external onlyOwner {

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

           whitelist[_beneficiaries[i]] = true;

       }

   }

Implemented Action

Whitelisting array functions included in 29deca2.

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.

Implemented Action

Whitelisting events added in 29deca2.

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.

Implemented Action

Addressed in 29deca2.

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.

Implemented Action

No action taken.