Coinsult

Request your audit at coinsult.net

Advanced Manual
Smart Contract Audit

September 15, 2022

Audit requested by

CryptoSwaps

0xc5d9325e6D06854EEb4a878ca906284E28BC6673

CryptoSwaps / Security Audit

Table of Contents

1. Audit Summary

1.1 Audit scope

1.2 Tokenomics

1.3 Source Code

2. Disclaimer

3. Global Overview

3.1 Informational issues

3.2 Low-risk issues

3.3 Medium-risk issues

3.4 High-risk issues

4. Vulnerabilities Findings

5. Contract Privileges

5.1 Maximum Fee Limit Check

5.2 Contract Pausability Check

5.3 Max Transaction Amount Check

5.4 Exclude From Fees Check

5.5 Ability to Mint Check

5.6 Ability to Blacklist Check

5.7 Owner Privileges Check

6. Notes

6.1 Notes by Coinsult

6.2 Notes by CryptoSwaps

7. Contract Snapshot

8. Website Review

9. Certificate of Proof

CryptoSwaps / Security Audit

Audit Summary

Audit Scope

Project Name

CryptoSwaps

Blockchain

Binance Smart Chain

Smart Contract Language

Solidity

Contract Address

0xc5d9325e6D06854EEb4a878ca906284E28BC6673

Audit Method

Static Analysis, Manual Review

Date of Audit

15 September 2022

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.

CryptoSwaps / Security Audit

Tokenomics

Rank Address Quantity (Token) Percentage
1 0x7f0f14b2ec480423e1fd89772bdd558dafde00c9 57,000,000 57.0000%
2 0x2d223adaa7c64d3118738d7e9c13054cc772afcd 34,300,000 34.3000%
3 0x7d000ee93b72cb8c1a69003720b7ff66c60fb8fb 4,900,000 4.9000%
4 0x77258bc014554c32df6ddb48166a45ce9274d775 2,940,000 2.9400%
5  0xc5d9325e6d06854eeb4a878ca906284e28bc6673 860,000 0.8600%

Source Code

Coinsult was comissioned by CryptoSwaps to perform an audit based on the following code:
https://bscscan.com/address/0xc5d9325e6D06854EEb4a878ca906284E28BC6673#code

CryptoSwaps / Security Audit

Disclaimer

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.

CryptoSwaps / Security Audit

Global Overview

Manual Code Review

In this audit report we will highlight the following issues:

Vulnerability Level

Total

Pending

Acknowledged

Resolved

0

0

0

0

7

0

7

0

0

0

0

0

1

0

1

0

Privilege Overview

Coinsult checked the following privileges:

Contract Privilege

Description

Owner can mint?

Owner can blacklist?

Owner can set fees > 25%?

Owner can exclude from fees?

Owner can pause trading?

Owner can set Max TX amount?

More owner priviliges are listed later in the report.

CryptoSwaps / Security Audit

Contract contains Reentrancy vulnerabilities

Additional information: This combination increases risk of malicious intent. While it may be justified by some complex mechanics (e.g. rebase, reflections, buyback). 

More information: Slither

				
					function _transferFrom(address sender, address recipient, uint256 amount) internal returns (bool) {
        uint256 burnFeeAmount = amount.mul(burnFee).div(feeDenominator);
        uint256 amountWithFee = amount.sub(burnFeeAmount);

        if(inSwap){
            if (burnFeeAmount > 0) { _burn(sender, burnFeeAmount); }
            return _basicTransfer(sender, recipient, amountWithFee); 
        }
        
        checkTxLimit(sender, amount);
        
        if(shouldSwapBack()){ swapBack(); }
        
        if(shouldAutoBuyback()){ triggerAutoBuyback(); }
        
        if(!launched() && recipient == pair){ require(_balances[sender] > 0); launch(); }
        
        _balances[sender] = _balances[sender].sub(amountWithFee, "Insufficient Balance");
        if (burnFeeAmount > 0) { _burn(sender, burnFeeAmount); }
        
        uint256 amountReceived = shouldTakeFee(sender) ? takeFee(sender, recipient, amountWithFee) : amountWithFee;
        _balances[recipient] = _balances[recipient].add(amountReceived);
        
        if(!isDividendExempt[sender]){ try distributor.setShare(sender, _balances[sender]) {} catch {} }
        
        if(!isDividendExempt[recipient]){ try distributor.setShare(recipient, _balances[recipient]) {} catch {} }
        
        try distributor.process(distributorGas) {} catch {}
        
            if (sender == pair &&
            buyCooldownEnabled &&
            !isTimelockExempt[recipient]) {
            require(cooldownTimer[recipient] < block.timestamp,"Please wait for cooldown between buys");
            cooldownTimer[recipient] = block.timestamp + cooldownTimerInterval;
        }
        
        emit Transfer(sender, recipient, amountReceived);
        return true;
    }
				
			

Recommendation

Apply the check-effects-interactions pattern.

Exploit scenario

				
					    function withdrawBalance(){
        // send userBalance[msg.sender] Ether to msg.sender
        // if mgs.sender is a contract, it will call its fallback function
        if( ! (msg.sender.call.value(userBalance[msg.sender])() ) ){
            throw;
        }
        userBalance[msg.sender] = 0;
    }
				
			
Bob uses the re-entrancy bug to call withdrawBalance two times, and withdraw more than its initial deposit to the contract.

CryptoSwaps / Security Audit

Too many digits

Literals with many digits are difficult to read and review.

				
					uint256 _totalSupply = 100000000 * (10 ** _decimals);
				
			

Recommendation

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.

CryptoSwaps / Security Audit

No zero address validation for some functions

Detect missing zero address validation.

				
					function transferOwnership(address payable adr) public onlyOwner {owner = adr;
        authorizations[adr] = true;
        emit OwnershipTransferred(adr);
    }
				
			

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.

CryptoSwaps / Security Audit

Functions that send Ether to arbitrary destinations

Unprotected call to a function sending Ether to an arbitrary address.

				
					function swapBack() internal swapping {
        uint256 dynamicLiquidityFee = isOverLiquified(targetLiquidity, targetLiquidityDenominator) ? 0 : liquidityFee;
        uint256 amountToLiquify = swapThreshold.mul(dynamicLiquidityFee).div(totalFee).div(2);
        uint256 amountToSwap = swapThreshold.sub(amountToLiquify);

        address[] memory path = new address[](2);
        path[0] = address(this);
        path[1] = WBNB;

        uint256 balanceBefore = address(this).balance;

        router.swapExactTokensForETHSupportingFeeOnTransferTokens(amountToSwap,0,path,address(this),block.timestamp);
        uint256 amountBNB = address(this).balance.sub(balanceBefore);
        uint256 totalBNBFee = totalFee.sub(dynamicLiquidityFee.div(2));
        uint256 amountBNBLiquidity = amountBNB.mul(dynamicLiquidityFee).div(totalBNBFee).div(2);
        uint256 amountBNBReflection = amountBNB.mul(reflectionFee).div(totalBNBFee);
        uint256 amountBNBMarketing = amountBNB.mul(marketingdevelopmentFee).div(totalBNBFee);

        try distributor.deposit{value: amountBNBReflection}() {} catch {}
        (bool success, /* bytes memory data */) = payable(marketingFeeReceiver).call{value: amountBNBMarketing, gas: 30000}("");
        require(success, "receiver rejected ETH transfer");

        if(amountToLiquify > 0){
            router.addLiquidityETH{value: amountBNBLiquidity}(address(this),amountToLiquify,0,0,developmentReceiver,block.timestamp);
            emit AutoLiquify(amountBNBLiquidity, amountToLiquify);
        }
    }
				
			

Recommendation

Ensure that an arbitrary user cannot withdraw unauthorized funds.

Exploit scenario

				
					contract ArbitrarySend{
    address destination;
    function setDestination(){
        destination = msg.sender;
    }

    function withdraw() public{
        destination.transfer(this.balance);
    }
}
				
			

Bob calls setDestination and withdraw. As a result he withdraws the contract’s balance.

CryptoSwaps / Security Audit

Unchecked transfer

The return value of an external transfer/transferFrom call is not checked.

				
					function distributeDividend(address shareholder) internal {
        if(shares[shareholder].amount == 0){ return; }

        uint256 amount = getUnpaidEarnings(shareholder);
        if(amount > 0){
            totalDistributed = totalDistributed.add(amount);
            REWARD.transfer(shareholder, amount);
            shareholderClaims[shareholder] = block.timestamp;
            shares[shareholder].totalRealised = shares[shareholder].totalRealised.add(amount);
            shares[shareholder].totalExcluded = getCumulativeDividends(shares[shareholder].amount);
        }
    }
				
			

Recommendation

Use SafeERC20, or ensure that the transfer/transferFrom return value is checked.

Exploit scenario

				
					contract Token {
    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success);
}
contract MyBank{  
    mapping(address => uint) balances;
    Token token;
    function deposit(uint amount) public{
        token.transferFrom(msg.sender, address(this), amount);
        balances[msg.sender] += amount;
    }
}
				
			

Several tokens do not revert in case of failure and return false. If one of these tokens is used in MyBankdeposit will not revert if the transfer fails, and an attacker can call deposit for free..

CryptoSwaps / Security Audit

Missing events arithmetic

Detect missing events for critical arithmetic parameters.

				
					function setDistributionCriteria(uint256 _minPeriod, uint256 _minDistribution) external override onlyToken {
        minPeriod = _minPeriod;
        minDistribution = _minDistribution;
    }
				
			

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.

CryptoSwaps / Security Audit

Costly operations inside a loop

Costly operations inside a loop might waste gas, so optimizations are justified. 

				
					function process(uint256 gas) external override onlyToken {
        uint256 shareholderCount = shareholders.length;
        if(shareholderCount == 0) { return; }
        uint256 gasUsed = 0;
        uint256 gasLeft = gasleft();
        uint256 iterations = 0;
        while(gasUsed < gas && iterations = shareholderCount){
                currentIndex = 0;
            }
            if(shouldDistribute(shareholders[currentIndex])){
                distributeDividend(shareholders[currentIndex]);
            }
            gasUsed = gasUsed.add(gasLeft.sub(gasleft()));
            gasLeft = gasleft();
            currentIndex++;
            iterations++;
        }
    }
				
			

Recommendation

Use a local variable to hold the loop computation result.

Exploit scenario

				
					contract CostlyOperationsInLoop{

    function bad() external{
        for (uint i=0; i < loop_count; i++){
            state_variable++;
        }
    }

    function good() external{
      uint local_variable = state_variable;
      for (uint i=0; i < loop_count; i++){
        local_variable++;
      }
      state_variable = local_variable;
    }
}
				
			

Incrementing state_variable in a loop incurs a lot of gas because of expensive SSTOREs, which might lead to an out-of-gas.

Cooldown between trades without maximum
				
					        // enable cooldown between trades
    function cooldownEnabled(bool _status, uint8 _interval) public onlyOwner {
        buyCooldownEnabled = _status;
        cooldownTimerInterval = _interval;
    }
				
			

Recommendation

Owner can set cooldownTimeInterval without a constraint. Implement a require statement to prevent accidental errors, or high interval amounts.

CryptoSwaps / Security Audit

Contract Privileges

Maximum Fee Limit Check

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. 

Type of fee

Description

Transfer fee

Buy fee

Sell fee

Type of fee

Description

Max transfer fee

Max buy fee

Max sell fee

CryptoSwaps / Security Audit

Contract Pausability Check

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.

Privilege Check

Description

Can owner pause the contract?

CryptoSwaps / Security Audit

Max Transaction Amount Check

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.

Privilege Check

Description

Can owner set max tx amount?

CryptoSwaps / Security Audit

Exclude From Fees Check

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.

Privilege Check

Description

Can owner exclude from fees?

CryptoSwaps / Security Audit

Ability To Mint Check

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.

Privilege Check

Description

Can owner mint?

CryptoSwaps / Security Audit

Ability To Blacklist Check

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.

Privilege Check

Description

Can owner blacklist?

CryptoSwaps / Security Audit

Other Owner Privileges Check

Coinsult lists all important contract methods which the owner can interact with.

⚠ Owner can authorize multiple addresses

⚠ Owner can exclude addresses form dividend

⚠ Owner can exclude addresses from timelock

⚠ Owner can create cooldown period between trades

CryptoSwaps / Security Audit

Notes

Notes by CryptoSwaps

No notes provided by the team.

Notes by Coinsult

✅ No notes provided by Coinsult

CryptoSwaps / Security Audit

Contract Snapshot

This is how the constructor of the contract looked at the time of auditing the smart contract.

				
					contract CryptoSwap is IBEP20, Auth {
    using SafeMath for uint256;
   
    address WBNB     = 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c; 
    address DEAD     = 0x000000000000000000000000000000000000dEaD;
    address ZERO     = 0x0000000000000000000000000000000000000000;

    string constant _name = "Crypto Swap V2";
    string constant _symbol = "CPSP";
    uint8 constant _decimals = 18;
   
    uint256 _totalSupply = 100000000 * (10 ** _decimals);
    uint256 public _maxTxAmount = _totalSupply / 1; // 
    uint256 public _maxWallet = 100000000 * 10**_decimals;

    mapping (address =&gt; uint256) _balances;
    mapping (address =&gt; mapping (address =&gt; uint256)) _allowances;
				
			

CryptoSwaps / Security Audit

Website Review

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. 

Type of check

Description

Mobile friendly?

Contains jQuery errors?

Is SSL secured?

Contains spelling errors?

CryptoSwaps / Security Audit

Certificate of Proof

CryptoSwaps

Audited by Coinsult.net

Date: 15 September 2022

Coinsult

coinsult.net

End of report
Smart Contract Audit

Request your smart contract audit / KYC

t.me/coinsult_tg