Penetration Test Report (Hacken): audit report

SMART CONTRACT CODE
REVIEW AND SECURITY
ANALYSIS REPORT
Customer: Tosdis
Date: December 16th, 2020
This document may contain confidential information about IT
systems and the intellectual property of the Customer as well as
information about potential vulnerabilities and methods of their
exploitation.
The report containing confidential information can be used
internally by the Customer, or it can be disclosed publicly after
all vulnerabilities fixed - upon a decision of the Customer.
Document
Name Smart Contract Code Review and Security Analysis Report for Tosdis
Finance (22 pages).
Approved by Andrew Matiukhin | CTO Hacken OU
Type Staking protocol
Platform Ethereum / Solidity
Methods Architecture Review, Functional Testing, Computer-Aided
Verification, Manual Review.
Repository
Commit
Deployed
contract
Timeline Dec, 10th 2020 – Dec, 16th 2020
Changelog Dec, 10th 2020 – Dec, 12th 2020 Initial audit
Dec, 14th 2020 – Remediation check
Dec, 15th 2020 – Remediation check
Dec, 16th 2020 – Remediation check
Table of contents
Introduction.............................................................. 4
Scope..................................................................... 4
Executive Summary......................................................... 5
Severity Definitions...................................................... 6
AS-IS overview............................................................ 7
Conclusion............................................................... 21
Disclaimers.............................................................. 22
Introduction
Hacken OÜ (Consultant) was contracted by Tosdis (Customer) to
conduct a Smart Contract Code Review and Security Analysis. This
report presents the findings of the security assessment of
Customer's smart contract and:
▪ Smart contract audit conducted between December 10th, 2020 –
December 16th, 2020.
▪ Remediation check was done December 14th, 2020;
▪ 2nd Remediation check was done December 15th, 2020;
▪ 3nd Remediation check was done December 16th, 2020.
Scope
The scope of the project is smart contracts in the repository:
Contract deployment address:
Repository
Commit
Files:
ERC20Basic.sol
Migrations.sol
Ownable.sol
StakingPool.sol
StakeMaster.sol
We have scanned this smart contract for commonly known and more
specific vulnerabilities. Here are some of the commonly known
vulnerabilities that are considered:
Category Check Item
Code review ▪ Reentrancy
▪ Ownership Takeover
▪ Timestamp Dependence
▪ Gas Limit and Loops
▪ DoS with (Unexpected) Throw
▪ DoS with Block Gas Limit
▪ Transaction-Ordering Dependence
▪ Style guide violation
▪ Costly Loop
▪ ERC20 API violation
▪ Unchecked external call
▪ Unchecked math
▪ Unsafe type inference
▪ Implicit visibility level
▪ Deployment Consistency
▪ Repository Consistency
▪ Data Consistency
Functional review ▪ Business Logics Review
▪ Functionality Checks
▪ Access Control & Authorization
▪ Escrow manipulation
▪ Token Supply manipulation
▪ Assets integrity
▪ User Balances manipulation
▪ Kill-Switch Mechanism
▪ Operation Trails & Event Generation
Executive Summary
According to the assessment, the Customer's smart has issues that
should be fixed. The code quality should be increased.
Insecure Poor secured Secured Well-secured
You are here
Our team performed an analysis of code functionality, manual
audit, and automated checks with Mythril and Slither. All issues
found during automated analysis were manually reviewed, and
important vulnerabilities are presented in the Audit overview
section. A general overview is presented in AS-IS section, and
all found issues can be found in the Audit overview section.
Security engineers found 1 critical 0 high, 0 medium, 0 low and 5
lowest issues during the first audit.
Update: Most contract’s vulnerabilities were fixed after the audit
was done. One low lowest severities left in contract and this risk
is acceptable. For details check “Audit overview” section.
Graph 1. The distribution of vulnerabilities after remediation check.
Low, 0, 0% Critical, 0, 0%
High, 0, 0%
Lowest, 1,
100%
Severity Definitions
Risk Level Description
Critical Critical vulnerabilities are usually straightforward to
exploit and can lead to assets loss or data
manipulations.
High High-level vulnerabilities are difficult to exploit;
however, they also have a significant impact on smart
contract execution, e.g., public access to crucial
functions
Medium Medium-level vulnerabilities are important to fix;
however, they can't lead to assets loss or data
manipulations.
Low Low-level vulnerabilities are mostly related to
outdated, unused, etc. code snippets that can't have
a significant impact on execution
Lowest / Code Lowest-level vulnerabilities, code style violations,
Style / Best and info statements can't affect smart contract
Practice execution and can be ignored.
AS-IS overview
ERC20Basic.sol
Description
Basic contract ERC20. The basic functions are defined:
totalSupply, transfer, approve, allowance and transferFrom. Used
as an ERC20 token in StakingPool and StakeMaster contracts. Used
in scripts for deploying StakingPool and StakeMaster contracts.
Used in tests.
Imports
ERC20Basic contract hasn’t the imports.
Usages
ERC20Basic contract has the following custom usages:
• SafeMath for uint256
Variables:
• string public constant name = "ERC20Basic";
• string public constant symbol = "BSC";
• uint8 public constant decimals = 18;
• mapping(address => uint256) balances;
• mapping(address => mapping (address => uint256)) allowed;
• uint256 totalSupply_;
Structs
ERC20Basic contract has the following data structures:
• It is not possible to define name, symbol and decimals in
the constructor.
Enums
ERC20Basic contract has no custom enums.
Events
ERC20Basic contract has the following events:
• event Approval(address indexed tokenOwner, address indexed
spender, uint tokens);
• event Transfer(address indexed from, address indexed to, uint
tokens);
Modifiers
ERC20Basic has no custom modifiers.
Fields
ERC20Basic contract has following constants:
• string public constant name = "ERC20Basic";
• string public constant symbol = "BSC";
• uint8 public constant decimals = 18;
Functions
ERC20Basic has following public functions:
• constructor
Visibility
public
Input parameters
o uint256 total
Constraints
None
Events emit
None
Output
None
• totalSupply
Visibility
Public view
Input parameters
None
Constraints
None.
Events emit
None
Output
Uint256
• transfer
Visibility
public
Input parameters
o address receiver,
o uint numTokens
Constraints
None
Events emit
None
Output
Bool
• approve
Visibility
public
Input parameters
o address delegate
o uint numTokens
Constraints
None
Events emit
None
Output
Bool
• allowance
Visibility
Public view
Input parameters
o address owner
o address delegate
Constraints
None
Events emit
None
Output
uint
• transferFrom
Visibility
public
Input parameters
o address owner,
o address buyer,
o uint numTokens
Constraints
None
Events emit
None
Output
Bool
Migrations.sol
Description
Used in deployment scripts.
Variables
o address public owner = msg.sender;
o uint public last_completed_migration;
Functions
Ownable has following public functions:
o setCompleted(uint completed) public restricted.
Ownable.sol
Description
Ownable the contract has an owner's address and provides basic
authorization control, making it easier to implement user
permissions.
Inheritance
Ownable contract is StakingPool, StakeMaster.
Variables
o address private _owner
Events
Ownable contract has the following custom events:
o event OwnershipTransferred(address indexed previousOwner,
address indexed newOwner)
Functions
Ownable has following public functions:
o constructor () internal;
o owner() public view returns (address);
o isOwner() public view returns (bool);
o renounceOwnership() public onlyOwner;
o transferOwnership(address newOwner) public onlyOwner;
o _transferOwnership(address newOwner) internal.
StakingPool.sol
Description
StakingPoo is contract for staking tokens stakingToken.
I