TIKI token smart contracts audit report
By: Polly Traore
Tags: Binance Smart Chain, Audit, Hashex, Security, Report

HashEx was commissioned by the TIKI team to perform an audit of their smart contracts. The audit was conducted between June 14 and June 17, 2021.

The audited code was provided in .sol files without any documentation.

The purpose of this audit was to achieve the following:

Identify potential security issues with smart contracts.

Formally check the logic behind given smart contracts.

Information in this report should be used to understand the risk exposure of smart contracts, and as a guide to improving the security posture of smart contracts by remediating the issues that were identified.

Update: TIKI team has responded to this report. Individual responses were added after each item in the section. The Whitepaper is available here. The updated code is deployed to Binance Smart Chain (BSC): 0x9b76D1B12Ff738c113200EB043350022EBf12Ff0.

Contracts overview

DividendPayingToken.sol

ERC20-like token with blocked transfers. The modified version of DividendPayingToken by Roger-Wu [1]. Further referred to as DPT.

TIKI.sol

ERC20 token with the 5% liquidity fee and 10% dividends to token holders. Further referred to as TIKI.

ERC20.sol

Implementation of ERC20 token standard with the possibility of increase/decrease allowance.

IterableMapping.sol

Library for iterable mapping from address to uint.

SafeMath.sol, SafeMathInt.sol, SafeMathUint.sol

SafeMath libraries for int and uint variables. Different from OpenZeppelin’s ones.

Various interfaces

Found issues

#01 ERC20: unsafe math: High severity

mint() and increaseAllowance() functions use unchecked addition. We recommend using the OpenZeppelin libraries.

The issue was fixed in the update. The functions in the update use SafeMath for addition.

#02 SafeMathInt: division requires b>0: High severity

div() function of a/b requires b>0. We recommend using the OpenZeppelin libraries.

The issue was fixed in the update. Updated code uses SafeMathInt from Ampleforth.

#03 TIKI: swapTokensForEth uses 100% slippage: Medium severity

swapTokensForEth() function calls PancakeRouter with 100% slippage. That makes flash loan attacks possible (actually any Safemoon fork should be susceptible to these attacks). Limiting the max transaction amount should reduce the attack probability.

#04 TIKI: hardcoded addresses: Medium severity

Hardcoded uniswapV2Router address makes it impossible to migrate to a new version of DEX in case of future upgrades of PancakeSwap periphery.

The issue was fixed in the update. Setter for uniswapV2Router address was added.

#05 TIKI: BEP20 token standard violation: Medium severity

Implementation of transfer() function in TIKI token does not allow to input zero amount as it’s demanded in the ERC-20 [2] and BEP-20 [3] standards. This issue may break the interaction with smart contracts that rely on full ERC20 support. The BEP20 standard isn’t fully supported as the token lacks the getOwner() function.

The issue was partially fixed in the update. Zero transfers made valid, getOwner() function is still absent.

#06 TIKI: update of DPT balances with try method: Medium severity

_transfer() function of TIKI token calls for dividendTracker.setBalance() via try method which makes a successful transfer with unchanged balances of dividends tokens possible. The current dividendTracker implementation should not fail on setting balances. It must be noted that dividendTracker can be updated and in case the function setBalance fails, discrepancies in token balances can take place.

#07 TIKI: tx is limited only for WETH pair: Medium severity

Transaction amount limit is enabled only for sells in PancakeSwap pair with WETH. This doesn’t prevent selling a large number of tokens on other dexes.

The issue was fixed in the update. A mapping for pair addresses was added in the updated code.

#08 DPT: BNB transfers with a low gas limit: Medium severity

_withdrawDividendOfUser() function of DividendPayingToken contract transfers ETH/BNB via .call{value, gas} method with 3000 of gas limit. This relatively small constant may cause problems with future ETH/BSC updates as operation gas costs may change with forks.

#09 TIKI: unindexed events: Low severity

All the events are completely unindexed.

The issue was fixed in the update. Parameters were set as indexed where needed.

#10 TIKI: fees should be constants: Low severity

Fee variables aren’t changed after creation and therefore should be declared constant or immutable. Setting fees as constant/immutable will save gas on reading values from the blockchain.

The issue was fixed in the update. The parameters were set as immutable.

#11 TIKI: multiple checks amount>0 in transfers: Low severity

Transaction amount limit is enabled only for sells in PancakeSwap pair with WETH. This doesn’t prevent selling on other dexes.

The issue was fixed in the update. Mitigation of the #05 issue has also fixed this issue.

#12 TIKI: taxFee name is misleading: Low severity

We believe that the TIKI token is inspired by the SafeMoon model and adopts some variable names. However, taxFee naming is misleading as unlike SafeMoon it doesn’t increase balances of TIKI holders (but used for paying dividends).

The issue was fixed in the update. Variable taxFee was renamed to BNBRewardsFee.

#13 DPT: transfers are denied: Low severity

All the transfers of DividendPayingToken are blocked which makes it non-ERC20. It may be slightly confusing as many explorers will show TIKI_Dividend_Tracker as ERC20 token.

#14 IterableMapping: inserted[] isn’t needed: Low severity

IterableMapping library could save gas by getting rid of inserted[] mapping and use indexOf[] instead.

#15 General recommendations: Low severity

We strongly recommend using original OpenZeppelin contracts as they are widely used and well audited. If some changes are needed to the original contracts, implement them via inheritance.

We also recommend following Solidity naming conventions [4], i.e. UPPERCASE for constants/immutable.

Conclusion

2 high severity issues were found. The issues are brought by not using the well-tested and audited library contracts but using custom implementations of ERC20 token and SafeMathInt libraries.

Audit includes recommendations on the code improving and preventing potential attacks.

Update: TIKI team has responded to this report. All high severity issues were fixed among most of the medium and low severity issues. Individual responses to the issues were added after each item in the section. The updated code is deployed to BSC: 0x9b76D1B12Ff738c113200EB043350022EBf12Ff0.

References

HashEx website: https://hashex.org

LinkedIn https://www.linkedin.com/in/dmitrymishunin/