In this audit report we will highlight the following issues:
Coinsult checked the following privileges:
More owner priviliges are listed later in the report.
This audit report has been prepared by Coinsult’s experts at the request of the client. In this audit, the results of the static analysis and the manual code review will be presented. The purpose of the audit is to see if the functions work as intended, and to identify potential security issues within the smart contract.
The information in this report should be used to understand the risks associated with the smart contract. This report can be used as a guide for the development team on how the contract could possibly be improved by remediating the issues that were identified.
Note that we only audited the code available to us on this URL at the time of the audit. If the URL is not from any block explorer (main net), it may be subject to change. Always check the contract address on this audit report and compare it to the token you are doing research for.
Note: This project uses openzeppelin imports. While we do check the full contract for vulnerabilities at the time of the audit, we can not ensure the correctness of these imported modules.
Coinsult’s manual smart contract audit is an extensive methodical examination and analysis of the smart contract’s code that is used to interact with the blockchain. This process is conducted to discover errors, issues and security vulnerabilities in the code in order to suggest improvements and ways to fix them.
Coinsult uses software that checks for common vulnerability issues within smart contracts. We use automated tools that scan the contract for security vulnerabilities such as integer-overflow, integer-underflow, out-of-gas-situations, unchecked transfers, etc.
Coinsult’s manual code review involves a human looking at source code, line by line, to find vulnerabilities. Manual code review helps to clarify the context of coding decisions. Automated tools are faster but they cannot take the developer’s intentions and general business logic into consideration.
Coinsult uses certain vulnerability levels, these indicate how bad a certain issue is. The higher the risk, the more strictly it is recommended to correct the error before using the contract.
Coinsult has four statuses that are used for each risk level. Below we explain them briefly.
The Smart Contract Weakness Classification Registry (SWC Registry) is an implementation of the weakness classification scheme proposed in EIP-1470. It is loosely aligned to the terminologies and structure used in the Common Weakness Enumeration (CWE) while overlaying a wide range of weakness variants that are specific to smart contracts.
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Passed
Contract does not use a ReEntrancyGuard
One of the major dangers of calling external contracts is that they can take over the control flow. In the reentrancy attack (a.k.a. recursive call attack), a malicious contract calls back into the calling contract before the first invocation of the function is finished. This may cause the different invocations of the function to interact in undesirable ways.
function _transfer(
address sender,
address recipient,
uint256 amount
) internal override {
if (_noBurnAddress[sender] || _noBurnAddress[recipient]) {
super._transfer(sender, recipient, amount);
} else {
uint256 burnAmount = (amount * 1) / 100; //转账的时候1%黑洞
super._burn(sender, burnAmount); // 1%销毁
uint256 marketAmount = (amount * 1) / 100; //1%市场
super._transfer(sender, marketWallet, marketAmount);
// 普通转账时LP分红回流底池
bool isNormalTransfer = !((sender == swapV2Pair ||
sender == swapV2Router) ||
(recipient == swapV2Pair || recipient == swapV2Router));
if (isNormalTransfer && uniswapV2Pair.totalSupply() > 0) {
uint256 rewardAmount = reserveLPAwardAmount;
if (rewardAmount > 0) {
//分红转给池子
reserveLPAwardAmount = reserveLPAwardAmount - rewardAmount;
super._transfer(address(this), swapV2Pair, rewardAmount);
uniswapV2Pair.sync(); //立即同步储备量
}
}
//兑换代币,换成 shib,进行分配
uint256 holderAwardAmount = (amount * 4) / 100; //持币分红
super._transfer(sender, address(this), holderAwardAmount);
swapShibTokenBalance = swapShibTokenBalance + holderAwardAmount;
if (
swapShibTokenBalance >= numTokensSellToFund &&
!inSwap &&
balanceOf(address(uniswapV2Pair)) > numTokensSellToFund &&
!(sender == swapV2Pair || sender == swapV2Router)
) {
swapTokenForFund(numTokensSellToFund);
swapShibTokenBalance =
swapShibTokenBalance -
numTokensSellToFund;
}
//
if (
recipient != address(this) &&
sender != address(this) &&
(recipient != address(0))
) {
processLP(500000); //最大gaslimt
}
//LP 分红
uint256 LPReward = (amount * 2) / 100; //回流底池
super._transfer(sender, address(this), LPReward);
reserveLPAwardAmount = reserveLPAwardAmount + LPReward;
uint256 realAmount = amount -
burnAmount -
marketAmount -
LPReward -
holderAwardAmount;
super._transfer(sender, recipient, realAmount);
}
//交易时增加到持币数组
addLpProvider(recipient);
}
uint256 private currentIndex = 0;
uint256 public lpRewardCondition;
uint256 private progressLPBlock;
Recommendation
The best practices to avoid Reentrancy weaknesses are: Make sure all internal state changes are performed before the call is executed. This is known as the Checks-Effects-Interactions pattern, or use a reentrancy lock (ie. OpenZeppelin’s ReentrancyGuard.
Avoid relying on block.timestamp
block.timestamp can be manipulated by miners.
uniswapV2Router02.swapExactTokensForTokensSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
Recommendation
Do not use block.timestamp
, now
or blockhash
as a source of randomness
Exploit scenario
contract Game {
uint reward_determining_number;
function guessing() external{
reward_determining_number = uint256(block.blockhash(10000)) % 10;
}
}
Eve is a miner. Eve calls guessing
and re-orders the block containing the transaction. As a result, Eve wins the game.
Too many digits
Literals with many digits are difficult to read and review.
processLP(500000); //最大gaslimt
Recommendation
Use: Ether suffix, Time suffix, or The scientific notation
Exploit scenario
contract MyContract{
uint 1_ether = 10000000000000000000;
}
While 1_ether
looks like 1 ether
, it is 10 ether
. As a result, it’s likely to be used incorrectly.
No zero address validation for some functions
Detect missing zero address validation.
//设置市场钱包
function setMarketWallet(address marketWallet_)
public
onlyRole(CONFIG_ADMIN)
{
marketWallet = marketWallet_;
}
Recommendation
Check that the new address is not zero.
Exploit scenario
contract C {
modifier onlyAdmin {
if (msg.sender != owner) throw;
_;
}
function updateOwner(address newOwner) onlyAdmin external {
owner = newOwner;
}
}
Bob calls updateOwner
without specifying the newOwner
, soBob loses ownership of the contract.
Missing events arithmetic
Detect missing events for critical arithmetic parameters.
function setMarketWallet(address marketWallet_)
public
onlyRole(CONFIG_ADMIN)
{
marketWallet = marketWallet_;
}
Recommendation
Emit an event for critical parameter changes.
Exploit scenario
contract C {
modifier onlyAdmin {
if (msg.sender != owner) throw;
_;
}
function updateOwner(address newOwner) onlyAdmin external {
owner = newOwner;
}
}
updateOwner()
has no event, so it is difficult to track off-chain changes in the buy price.
Conformance to Solidity naming conventions
Allow _ at the beginning of the mixed_case match for private variables and unused parameters.
_setupRole(DEFAULT_ADMIN_ROLE, msg.sender); //设置默认管理员为合约创建者
_setupRole(CONFIG_ADMIN, msg.sender);
Recommendation
Follow the Solidity naming convention.
Rule exceptions
ERC20
)._
at the beginning of the mixed_case
match for private variables and unused parameters.Code With No Effects
Detect the usage of redundant statements that have no effect.
address public immutable swapV2Pair;
address private immutable swapV2Router; //
address private immutable BUSD; //稳定币地址 usdt或BUSD
address private immutable WETH;
address private immutable shibAddress;
Recommendation
Remove redundant statements if they congest code but offer no value.
Exploit scenario
contract RedundantStatementsContract {
constructor() public {
uint; // Elementary Type Name
bool; // Elementary Type Name
RedundantStatementsContract; // Identifier
}
function test() public returns (uint) {
uint; // Elementary Type Name
assert; // Identifier
test; // Identifier
return 777;
}
}
Each commented line references types/identifiers, but performs no action with them, so no code will be generated for such statements and they can be removed.
Costly operations inside a loop
Costly operations inside a loop might waste gas, so optimizations are justified.
//最多只给列表完整分配一次,iterations < shareholderCount
while (gasUsed < gas && iterations = shareholderCount) {
currentIndex = 0;
}
shareHolder = holderProviders[currentIndex];
//持有的 LP 代币余额,LP 本身也是一种代币
myTokenBalance = balanceOf(shareHolder);
//不在排除列表,才分红
if (
myTokenBalance > minHoldCoinAmount &&
!excludeHolderProvider[shareHolder]
) {
amount = (shibBalance * myTokenBalance) / totalSupply();
//分红大于0进行分配,最小精度
if (amount > 0) {
shibToken.transfer(shareHolder, amount);
}
}
gasUsed = gasUsed + (gasLeft - gasleft());
gasLeft = gasleft();
currentIndex++;
iterations++;
}
progressLPBlock = block.number;
Recommendation
Use a local variable to hold the loop computation result.
uint256 public numTokensSellToFund; //合约卖币换shib条件阀值
uint256 public reserveLPAwardAmount; //记录LP分红回流底池的余额
uint256 public swapShibTokenBalance; //持币分红,兑换shib的本币余额
Recommendation
// 授权代币转账权限给对应的stake合约,那么授权的数量就是当前可以挖矿的数量
function approveAmountToStake(
address erc20Address,
address[] calldata toAddresss_,
uint256[] calldata values_
) public virtual onlyOwner {}
function increaseAllowanceToStake(
address erc20Address,
address[] calldata toAddresss_,
uint256[] calldata values_
) public virtual onlyOwner {}
// 查询授权
function allowance(
address erc20Address,
address owner,
address spender
) public view virtual returns (uint256) {}
// 查询当前合约的授权
function allowance(
address erc20Address,
address spender
) public view virtual returns (uint256) {}
Recommendation
Coinsult tests if the owner of the smart contract can set the transfer, buy or sell fee to 25% or more. It is bad practice to set the fees to 25% or more, because owners can prevent healthy trading or even stop trading when the fees are set too high.
Coinsult tests if the owner of the smart contract has the ability to pause the contract. If this is the case, users can no longer interact with the smart contract; users can no longer trade the token.
Coinsult tests if the owner of the smart contract can set the maximum amount of a transaction. If the transaction exceeds this limit, the transaction will revert. Owners could prevent normal transactions to take place if they abuse this function.
Coinsult tests if the owner of the smart contract can exclude addresses from paying tax fees. If the owner of the smart contract can exclude from fees, they could set high tax fees and exclude themselves from fees and benefit from 0% trading fees. However, some smart contracts require this function to exclude routers, dex, cex or other contracts / wallets from fees.
Coinsult tests if the owner of the smart contract can mint new tokens. If the contract contains a mint function, we refer to the token’s total supply as non-fixed, allowing the token owner to “mint” more tokens whenever they want.
A mint function in the smart contract allows minting tokens at a later stage. A method to disable minting can also be added to stop the minting process irreversibly.
Minting tokens is done by sending a transaction that creates new tokens inside of the token smart contract. With the help of the smart contract function, an unlimited number of tokens can be created without spending additional energy or money.
Coinsult tests if the owner of the smart contract needs to manually enable trading before everyone can buy & sell. If the owner needs to manually enable trading, this poses a high centralization risk.
If the owner needs to manually enable trading, make sure to check if the project has a SAFU badge or a trusted KYC badge. Always DYOR when investing in a project that needs to manually enable trading.
Coinsult tests if the owner of the smart contract can blacklist accounts from interacting with the smart contract. Blacklisting methods allow the contract owner to enter wallet addresses which are not allowed to interact with the smart contract.
This method can be abused by token owners to prevent certain / all holders from trading the token. However, blacklists might be good for tokens that want to rule out certain addresses from interacting with a smart contract.
Coinsult lists all important contract methods which the owner can interact with.
This is how the constructor of the contract looked at the time of auditing the smart contract.
contract ShiDToken is ERC20, AccessControl, IUserParent {
bytes32 public constant CONFIG_ADMIN = keccak256("CONFIG_ADMIN");
mapping(address => bool) public _noBurnAddress;
address _stakeAddress = address(0); // 质押合约地址
address public immutable swapV2Pair;
address private immutable swapV2Router; //
address private immutable BUSD; //稳定币地址 usdt或BUSD
address private immutable WETH;
address private immutable shibAddress;
address topAddress; // 推荐关系 顶层地址可以在没有上线的情况下进行关联关系
address public marketWallet; // 市场钱包
mapping(address => address) public _addressParentInfo; //保存推荐关系
IUniswapV2Router02 immutable uniswapV2Router02;
IUniswapV2Pair immutable uniswapV2Pair;
Coinsult checks the website completely manually and looks for visual, technical and textual errors. We also look at the security, speed and accessibility of the website. In short, a complete check to see if the website meets the current standard of the web development industry.
This audit report has been prepared by Coinsult’s experts at the request of the client. In this audit, the results of the static analysis and the manual code review will be presented. The purpose of the audit is to see if the functions work as intended, and to identify potential security issues within the smart contract.
The information in this report should be used to understand the risks associated with the smart contract. This report can be used as a guide for the development team on how the contract could possibly be improved by remediating the issues that were identified.
Coinsult is not responsible if a project turns out to be a scam, rug-pull or honeypot. We only provide a detailed analysis for your own research.
Coinsult is not responsible for any financial losses. Nothing in this contract audit is financial advice, please do your own research.
The information provided in this audit is for informational purposes only and should not be considered investment advice. Coinsult does not endorse, recommend, support or suggest to invest in any project.
Coinsult can not be held responsible for when a project turns out to be a rug-pull, honeypot or scam.