WIN Token Smart Contract Audit

# 1. Introduction

iosiro was commissioned by [WAWLLET](https://www.wawllet.com/) to conduct an audit on their token smart contract. The audit was performed between 13 March 2018 and 16 March 2018. On 4 April 2018 issues in this report were addressed and documented herein.


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 token 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 no issues were open. The smart contracts were found to use standard libraries, such as OpenZeppelin and TokenMarket, with slight modifications for custom functionality. The use of these libraries led to good design patterns, including highly modularized code that prioritized readability.

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 Win Token

**Address:** [0x899338b84d25ac505a332adce7402d697d947494](https://etherscan.io/address/0x899338b84d25ac505a332adce7402d697d947494#readContract)<br/>

**Files:** WINCrowdSaleToken.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 Win Token

The token was implemented in WINCrowdSaleToken.sol. The token code was largely based on the popular OpenZeppelin and TokenMarket libraries, however, some custom functionality was also included.

Notable design decisions of the smart contracts are outlined below.


#### ERC20 Token

The token implements the ERC20 standard, with the following attributes.


Field        | Value
------------ | -------------
Symbol       | WCOIN
Name         | WIN
Decimals     | 8


#### Mintable

Tokens were mintable, meaning that tokens were created when required, rather than creating a lump sum of initial tokens that were then distributed.


#### Burnable

Tokens were burnable, meaning that the tokens could be destroyed and removed from the total supply.


<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

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


## 5.4 Informational

No informational issues were present at the conclusion of the audit.


## 5.5 Closed

### 5.5.1 No Ability to Control Minting Process (High)

*WINCrowdSaleToken.sol*

#### Description

It was found during the audit that no functionality was included in the smart contract to control the token minting process. As a result, any amount of new tokens could be created at any time, including after the crowdsale had ended. If this were to be exploited, WIN token holders could see their stake in the token diluted by newly created tokens. Additionally, the original token allocations described in the white paper could be bypassed, as entities could be assigned additional tokens at a later stage.

The variable `mintingFinished`, which was used in the modifier canMint to determine whether new tokens could be minted, was found to have no method of being changed in code. As a result, `mintingFinished` was always set to `false` and `canMint` always returned `true`.

In the original TokenMarket implementation of CrowdsaleToken.sol, a function titled `releaseTokenTransfer` was used to both release the token and prevent any new tokens from being minted once the crowdsale had finished. This function is given below.

<pre>

<code class="language-solidity" >

 function releaseTokenTransfer() public onlyReleaseAgent {

   mintingFinished = true;

   super.releaseTokenTransfer();

 }

</code>

</pre>


This would stop the minting process once the token had been released at the end of a crowdsale. In the WIN token, no such functionality was present.

An example of how one may exploit this vulnerability is outlined below.

1. Owner of the token calls `setMintAgent(attackerAddress, true)` with a new address `attackerAddress`.

2. `attackerAddress` can then call `mint(attackerAddress, numTokens)` to send themselves numTokens  number of tokens, as both `onlyMintAgent` and `canMint` will return true.

#### Remedial Action

As the token had already been deployed at the time of testing and there being no ability to upgrade the token, there are limited options to address this issue. One approach would be to ensure that all addresses are set to not be minting agents at the end of the crowdsale, and then transfer ownership of the token to 0x0 or another address that is known to not be controlled by the company - preventing any new minting agents from being set. The risk with this approach is that there is a large assumption that no one will ever be able to control that address. Additionally, once ownership is transferred, it won’t be possible to transfer ownership back, losing the ability to perform operations such as updating the token name and symbol.

Any minting of new tokens will be publicly seen on the blockchain through the transfer event with a from address of 0x0. Using this information token holders would be able to see whether this has been exploited after the crowdsale has ended.


#### Implemented Action

All of the minting agents were disabled and ownership of the token contract was transferred to the contract itself, resulting in the inability to mint new tokens.


### 5.5.2 Tokens Immediately Transferable (Low)

*WINCrowdSaleToken.sol*

#### Description

The [white paper](https://www.wawllet.com/assets/pdf/WAWLLET-WHITE-PAPER-2.0-EN.pdf) stated in Section 9.3 that “no Tokens may be transferred or traded until completion of the Token Sale Session”, however, no functionality was available in the token smart contract to enforce this behaviour. As such, holders of WIN tokens could immediately transfer tokens.  

#### Remedial Action

As the token had already been deployed at the time of testing and there being no ability to upgrade the token, there are limited options to address this issue. However, the impact of this issue is relatively low and marked as medium risk as it contradicts the information provided in the white paper.

If the token had not yet been deployed to a live environment, it would be possible to use the OpenZeppelin releasable mixin to prevent holders from transferring tokens until the crowdsale had ended, unless they were explicitly whitelisted to do so.

#### Implemented Action

No action was required.

Secure your system.
Request a service
Start Now