Penetration Test Report (Consensys): vega vegatoken audit 2020 01

Vega Vegatoken Audit
1 Summary Date January 2020
2 Audit Scope
Lead Auditor Martin Ortner
3 System Overview
Co-auditors Gonçalo Sá
4 Key Observations/Recommendations
5 Security Specification
5.1 Actors
5.2 Trust Model
5.3 Important Security Properties
6 Issues
6.1 ERC20Lockable - inconsistent locking status Minor ✓ Fixed
7 Tool-Based Analysis
7.1 MythX
7.2 Ethlint
7.3 Surya
Appendix 1 - Disclosure
1 Summary
ConsenSys Diligence conducted a security audit on the Vega token, an ERC20 compliant
token for the Vega protocol, a protocol for creating and trading derivatives on a fully
decentralized network.
Audit Changelog Date
2020-01-
Initial report delivery.
29
Diff highlighting fixes of the issues raised in the report was provided by the Vega 2020-02-
team. 10
Audit Changelog Date
2020-02-
Fixes acknowledged by the audit team and final report delivery.
12
2 Audit Scope
This audit covered the following files:
Source repository commit# : vega-
protocol/vega_token.git#672d747e2f38cd9f51ee7b4cd99ceb02a3573bfb
File Name SHA-1 Hash
contracts/Vega_Token.sol b92b3c54b2f47a88fa9e84534046b462dbaee9aa
contracts/Address.sol 1213b0f150dd5e3f694c3721c44cb5cc3202b743
contracts/ERC20Detailed.sol 7e4d00c[PII_REDACTED]01f28361b29201d1bfe0a34
contracts/IERC20.sol 72c15b6a16b7dc92e69ff97ccfe1958d9948e200
contracts/ERC20Lockable.sol[PII_REDACTED]44beee2b3c5342bfa9b1bbc1d08356
contracts/SafeMath.sol c8bda5eb19c16d34bc48bf115229a9b967feb6ef
contracts/ERC20StaticSupply.sol bf3e66af74470eed08d0e0f82b9a98705a745c7c
contracts/Ownable.sol 12ec51ec8a3b4eed6326434fd0f5926b40602778
contracts/Roles.sol 2c85acf184ae36f96ebafd8f6e26232ea459a711
contracts/SafeERC20.sol ebd65ea9a0cdcb29bbbbf651a1076d51be031443
contracts/Roles.sol
is an unmodified copy of OpenZeppelin/contracts/access/Roles.sol#67bca85.
is the latest version available to date.
is not referenced throughout the codebase.
contracts/Address.sol
is an unmodified copy of OpenZeppelin/contracts/utils/Address.sol#18d7e24.
is not the latest version available to date.
contracts/SafeERC20.sol
is an copy of OpenZeppelin/contracts/token/ERC20/SafeERC20.sol#5d34dbe
with minor modifications (adjusted import pragma).
is not referenced throughout the codebase
contracts/Ownable.sol
is a copy of OpenZeppelin/contracts/ownership/Ownable.sol#f095b62 with no
logic changing modifications to the contract.
contracts/SafeMath.sol
is a copy of OpenZeppelin/contracts/math/SafeMath.sol#c4bb7b7 with no logic
changing modifications to the contract.
contracts/IERC20.sol, contracts/ERC20Detailed.sol
are a unmodified copies of
OpenZeppelin/contracts/token/ERC20/IERC20.sol#7552af9 and
OpenZeppelin/contractstoken/ERC20/ERC20Detailed.sol#7552af9
The audit activities can be grouped into the following three broad categories:
1. Security: Identifying security related issues within the contract.
2. Architecture: Evaluating the system architecture through the lens of established
smart contract best practices.
3. Code quality: A full review of the contract source code. The primary areas of focus
include:
Correctness
Readability
Scalability
Code complexity
Quality of test coverage
3 System Overview
This section describes the top-level contracts, their inheritance structure, actors,
permissions and contract interactions. Please refer to section 5 - Security Specification for
a security-centric view on the system.
Inheritance Structure
Vega_Token Address SafeMath Roles SafeERC20
ERC20StaticSupply
Ownable ERC20Detailed ERC20Lockable
IERC20
Inheritance graph
Call Graph
Legend
UnDdeefifi Enn I exn edd ttee CC rrnn oo aa nn ll tt CC rraa aa cc ll tt ll
Vega_Token
<Constructor>
unlock_token
is_tradable
ERC20StaticSupply
<Constructor>
issue
ERC20Lockable
onlyUnlocked
_unlock
totalSupply
balanceOf
transfer
allowance _transfer
transferFrom
approve
increaseAllowance _approve
decreaseAllowance SafeMath (lib)
_burnFrom _burn sub
_mint add
Ownable mul
<Constructor>
owner div
onlyOwner isOwner mod
renounceOwnership
transferOwnership _transferOwnership
ERC20Detailed
<Constructor>
name
symbol
decimals
IERC20 (iface)
totalSupply
balanceOf
transfer
allowance
approve
transferFrom
Function call graph and contract interaction
Vega Token
Vega_Token
Ownable
ERC20StaticSupply
__constructor__()
account recipient owner unlock_token()
is_tradable()
ERC20StaticSupply
ERC20Detailed
Ownable
ERC20Lockable
spender sender newOwner __constructor__()
issue()
ERC20Lockable
IERC20
SafeMath foruint256
ERC20Detailed address=>uint256_balances
address=>mapping address=>uint256_allowances
Ownable uint256_totalSupply
IERC20
uint256unlock_date
address_owner bool_is_locked
__constructor__() string_name _unlock()
owner() string_symbol totalSupply()
isOwner() uint8_decimals balanceOf()
renounceOwnership() transfer()
__constructor__()
t
_
r
t
a
ra
n
n
sf
s
e
fe
rO
rO
w
w
n
n
e
e
rs
r
h
sh
ip
ip
()
()
name()
a

pp
a
r
ll
o
o
v
w
e
a
(
n
)
ce()
symbol()
transferFrom()
decimals()
increaseAllowance()
decreaseAllowance()
_transfer()
_mint()
_burn()
_approve()
_burnFrom()
for uint256
IERC20
SafeMath
  tran b to a s t f l a a e l n S r( c u ) e p O p f l ( y ) ()   a su d b d ( ( ) )

app
a
r
ll
o
o
v
w
e
a
(
n
)
ce()  d m iv u ( l ) ()
transferFrom()
mod()
Vega Token Outline
4 Key Observations/Recommendations
The following libraries are part of the project workspace but not referenced by the
Vega Token:
and therefore also which is only referenced
by
Acknowledged and fixed by the development team.
SWC-103: The codebase sets compiler flags ( ) that
allows compilation with any soldity 0.5.x compiler potentially allowing to fall back to
untested versions or compiler versions with known bugs, vulnerabilities or fewer
security checks. It is recommended to lock the version to the solidity compiler version
the codebase has been thoroughly tested.
Please note that the latest solidity compiler version released is v0.6.2.
Acknowledged and fixed by the development team.
should be declared and all
uppercase .
Acknowledged and fixed by the development team. (v. Issue 6.1)
could use
instead of duplicating code.
Acknowledged and fixed by the development team.
The contract should be named using CapWords as recommended by
the solidity style guide.
Acknowledged and fixed by the development team.
5 Security Specification
This section describes the behavior of the system under audit from a security perspective.
It is best combined with the overview given in section 3 - System Overview. Please note
that this document is not a substitute for documentation. The purpose of this section is to
identify specific security properties that were validated by the audit team. Furthermore, the
information contained in this section can be used for internal security activities and we
recommend documenting and building-upon the trust model that has been established.
Vega_Token
- initially assigned to contract deployer
Ownable
- can transfer ownership
ERC20StaticSupply
- can renounce ownership
__constr__
- is initially in control of all tokens
Owner - issues tokens to users at will (completely centralized) owner unlock_token
- can issue while locked
(v) is_tradeable
ERC20StaticSupply
ERC20Detailed
- can transfer tokens Ownable
- if contract is unlocked ERC20Lockable
- or time past unlock_time (auto unlock)
__constr__
- can set allowance even before that
owner issue()
user
ERC20Lockable
IERC20
(v) totalSupply
(v) balanceOf
onlyUnlocked transfer
(v) allowance
approve
onlyUnlocked transferFrom
increaseAllowance
decreaseAllowance
ERC20Detailed
IERC20
__constr__
(v) name
(v) symbol
(v) decimals
Ownable
__constr__
(v) owner
(v) isOwner
owner renounceOwnership
owner transferOwnership
Permission and Actors overview
5.1 Actors
The relevant actors are as follows:
Deployer - initially deploys the system.
Owner - privileged account that is used to distribute tokens.
Token Holder - address with a token balance > 0.
Any Ethereum Account - address with no token balance.
5.2 Trust Model
In any smart contract system, it’s important to identify what trust is expec