PGF500 Smart Contract Audit

# 1. Introduction
iosiro was commissioned by [PGF500](https://ico.pgf500.com/) to conduct an audit on their token and crowdsale smart contracts. The audit was performed between 19 October 2018 and 22 October 2018.

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

At the conclusion of the audit, one low risk issue was open, as well as informational findings and design recommendations. The low risk issue allowed contributors to bypass the maximum contribution limit of the crowdsale. The informational findings included minor deviations from best practice and suggestions that may improve the functionality of the code.

Despite the findings, the code was of a relatively high standard. This was evident in the use of modularized code, as well as making use of commonly used libraries where reasonable.

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.
* Extending the test suite coverage.

<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 PGF500 Smart Contracts
**Project Name:** PGF500Crowdsale <br/>
**Commits:** [4bdcefd](https://github.com/PGF500Crowdsale/Crowdsale/tree/4bdcefd656a9cc91df7b5b83344515f039633fbe)<br/>
<!-- **Files:**  -->

## 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. No test suite was included in the supplied project code.

### 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 PGF500 Token
The PGF500 token is described below.

#### ERC-20 Token

The token should implement the ERC-20 standard.

|Field        | Value
|:------------ |:-------------
|Symbol       | PGF7T
|Name         | PGF500 Token
|Decimals     | 18

#### Lockable

Tokens should be unable to be transferred until the owner of the token calls a one-way unlock function. It should be possible for the token owner to add and remove addresses from a whitelist, allowing whitelisted addresses to transfer tokens before the token has been unlocked. The token owner should automatically be whitelisted. When ownership of the token is transferred, the old owner should be removed from the whitelist and the new owner should be added to it.

#### Burnable

It should be possible for tokens to be removed from the total supply by using the built-in token burn functionality.

#### Airdrop

It should be possible to call an airdrop function that distributes a static number of tokens to each supplied address. The function should accept up to 200 addresses per function call.

#### Multi-Transfer

It should be possible to call an airdrop function that distributes a different number of tokens to each supplied address. The function should accept up to 200 addresses per function call.

## 4.2 PGF500 Crowdsale Smart Contracts
The functionality of the PGF500 crowdsale smart contract is described below.

#### Initialization

The token should be supplied with the following values upon initialization of the contract.

* The wallet address where crowdsale funds should be forwarded.
* The address of the token being sold.
* The address holding the tokens for the crowdsale.

#### Periods

It should be possible for sales periods to be added to the crowdsale. Each period should have a start and end date, as well as a default rate of tokens per ether for the period. Contributions made outside of any valid period should be rejected.  

#### Contribution Limits

Contributions should be greater than 0.5 ether and less than 20 ether per transaction, unless the address is whitelisted, in which case any amount of ether can be contributed provided it exceeds the minimum contribution limit.

#### Whitelist

It should be possible for the crowdsale owner to add and remove addresses from a whitelist. Whitelisted addresses should be able to contribute in excess of 20 ether and can also have a custom rate set, which would allow for a different rate to the default rate specified in the period.

#### Pausable

It should be possible to pause and unpause the crowdsale, rejecting all contributions when paused.

<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

No high risk issues were present at the conclusion of the audit.

## 5.2 Medium Risk

No medium risk issues were present at the conclusion of the audit.

## 5.3 Low Risk

### 5.3.1 Possible to Bypass Maximum Contribution Limit

*PGFSale.sol: Line 221*

#### Description

The audit identified an issue with the way that maximum contribution limits were handled for contributors that were not whitelisted. Since the address of the contributor was not checked for their existing contributions, it was possible for the contributor to simply repeat the transaction, thus bypassing the maximum contribution limit imposed. For example a contributor might contribute 30 ether by sending three transactions of 10 ether each.

#### Remedial Action

It is recommended that the contributions received by each address or contributor be recorded in a mapping to ensure that they do not exceed the maximum contribution limit. Additionally, since a contributor may simply transfer funds from another address, it is recommended that only whitelisted addresses be permitted to make contributions, otherwise it would be possible to trivially bypass the maximum limit.

## 5.4 Informational

### 5.4.1 Design Comments

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

#### Variable total supply
As the total supply of the token was set through a constructor argument, it was not possible to verify whether the total supply of the token would adhere to the number specified in the specification (284,000,000 PGF7T).

#### Fixed contribution limits
It was found that the contract code contained fixed minimum and maximum contributions for participants. Although not strictly a functional or security issue, setting dynamic contribution limits may provide a method for allowing smaller contributions to take place should they be deemed necessary.

#### Defining constructors as functions with the same name as the contract

In several cases it was found that contract constructors used the deprecated convention of being declared as functions with the same name as the contract. Although, there were no cases where this would contribute to a security or functional issue. It is recommended that the `constructor(..)` format is used in place of the deprecated format.

#### No `require` validation failure messages provided

It was found that no `require` validation calls made use of the optional error message parameter. Although strictly not a security or functional issue, it should be resolved to provide better feedback in cases where validation fails.

#### Use of implicit integer sizes in contract implementations

*PGF500Token.sol*

It was found that several properties and functions contained implicit `uint` type declarations. It is suggested that these `uint` type declarations be replaced by the `uint256` type declaration instead in order to adhere to best practice.

#### Inexact solidity compiler version used

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

## 5.5 Closed

No issues were closed at the conclusion of the audit.

Secure your system.
Request a service
Start Now