Coinsult

Request your audit at coinsult.net

Advanced Manual
Smart Contract Audit

April 24, 2022

Audit requested by

MIM Machine (Staking)

Not deployed yet

MIM Machine (Staking) / 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 MIM Machine (Staking)

7. Contract Snapshot

8. Website Review

9. Certificate of Proof

MIM Machine (Staking) / Security Audit

Audit Summary

Audit Scope

Project Name

MIM Machine (Staking)

Blockchain

Binance Smart Chain

Smart Contract Language

Solidity

Contract Address

Not deployed yet

Audit Method

Static Analysis, Manual Review

Date of Audit

24 April 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.

MIM Machine (Staking) / Security Audit

Tokenomics

Source Code

Coinsult was comissioned by MIM Machine (Staking) to perform an audit based on the following code:

Contract not yet deployed

MIM Machine (Staking) / 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.

MIM Machine (Staking) / 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

8

0

0

0

0

0

0

0

0

0

0

0

MIM Machine (Staking) / 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 claimToken_M() public {
        User storage user = users[msg.sender];

        updateStakeBUSD_IP(msg.sender);
        uint256 tokenAmount = user.sM.unClaimedTokens;
        user.sM.unClaimedTokens = 0;

        _mint(msg.sender, tokenAmount);
        emit TokenOperation(msg.sender, "CLAIM", tokenAmount, 0);
    }

    function claimToken_T() public {
        User storage user = users[msg.sender];

        updateStakeToken_IP(msg.sender);
        uint256 tokenAmount = user.sT.unClaimedTokens;
        user.sT.unClaimedTokens = 0;

        _mint(msg.sender, tokenAmount);
        emit TokenOperation(msg.sender, "CLAIM", tokenAmount, 0);
    }
				
			

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.

MIM Machine (Staking) / Security Audit

Avoid relying on block.timestamp

block.timestamp can be manipulated by miners.

				
					    function getContractLaunchTime() public view returns (uint256) {
        return minZero(startTime, block.timestamp);
    }
				
			

Recommendation

Do not use block.timestampnow 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.

MIM Machine (Staking) / Security Audit

Too many digits

Literals with many digits are difficult to read and review.

				
					    function SET_SELL_LIMIT(uint256 value) external {
        require(msg.sender == ADMIN, "Admin use only");
        require(value >= 40000);
        SELL_LIMIT = value * 1 ether;
    }
				
			

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.

MIM Machine (Staking) / Security Audit

Functions that send Ether to arbitrary destinations

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

				
					    function stakeBUSD(uint256 _amount) public payable {
        require(block.timestamp > startTime); 
        require(_amount >= MIN_INVEST_AMOUNT); // added min invest amount
        token.transferFrom(msg.sender, address(this), _amount); // added

        uint256 fee = _amount.mul(FEE).div(PERCENT_DIVIDER); // calculate fees on _amount and not msg.value

        token.transfer(DEV_POOL, fee);

        User storage user = users[msg.sender];

        if (user.sM.totalStaked == 0) {
            user.sM.checkpoint = maxVal(now, startTime);
            totalUsers++;
        } else {
            updateStakeBUSD_IP(msg.sender);
        }

        user.sM.lastStakeTime = now;
        user.sM.totalStaked = user.sM.totalStaked.add(_amount);
        totalBUSDStaked = totalBUSDStaked.add(_amount);
    }
				
			

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.

MIM Machine (Staking) / Security Audit

Unchecked transfer

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

				
					    function stakeToken(uint256 tokenAmount) public {
        User storage user = users[msg.sender];
        require(now >= startTime, "Stake not available yet");
        require(
            tokenAmount <= balanceOf(msg.sender),
            "Insufficient Token Balance"
        );

        if (user.sT.totalStaked == 0) {
            user.sT.checkpoint = now;
        } else {
            updateStakeToken_IP(msg.sender);
        }

        _transfer(msg.sender, address(this), tokenAmount);
        user.sT.lastStakeTime = now;
        user.sT.totalStaked = user.sT.totalStaked.add(tokenAmount);
        totalTokenStaked = totalTokenStaked.add(tokenAmount);
    }
				
			

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..

MIM Machine (Staking) / Security Audit

Missing events arithmetic

Detect missing events for critical arithmetic parameters.

				
					    function SET_MIN_INVEST_AMOUNT(uint256 value) external {
        require(msg.sender == ADMIN, "Admin use only");
        require(value >= 5);
        MIN_INVEST_AMOUNT = value * 1 ether;
    }

    function SET_SELL_LIMIT(uint256 value) external {
        require(msg.sender == ADMIN, "Admin use only");
        require(value >= 40000);
        SELL_LIMIT = value * 1 ether;
    }
				
			

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.

MIM Machine (Staking) / Security Audit

Conformance to Solidity naming conventions

Allow _ at the beginning of the mixed_case match for private variables and unused parameters.

				
					    function SET_MIN_INVEST_AMOUNT(uint256 value) external {
        require(msg.sender == ADMIN, "Admin use only");
        require(value >= 5);
        MIN_INVEST_AMOUNT = value * 1 ether;
    }

    function SET_SELL_LIMIT(uint256 value) external {
        require(msg.sender == ADMIN, "Admin use only");
        require(value >= 40000);
        SELL_LIMIT = value * 1 ether;
    }
				
			

Recommendation

Follow the Solidity naming convention.

Rule exceptions

  • Allow constant variable name/symbol/decimals to be lowercase (ERC20).
  • Allow _ at the beginning of the mixed_case match for private variables and unused parameters.

MIM Machine (Staking) / Security Audit

Redundant Statements

Detect the usage of redundant statements that have no effect.

				
					    function getContractBUSDBalance() public view returns (uint256) {
        // return address(this).balance;
        return token.balanceOf(address(this));
    }
				
			

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.

MIM Machine (Staking) / Security Audit

Other Owner Privileges Check

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

⚠ Owner can set minimum investment amount

⚠ Owner can set sell limit
– Note from the MIM machine team: The sell limit will always be at least 40,000 ether

 

 

MIM Machine (Staking) / Security Audit

Notes

Notes by MIM Machine (Staking)

No notes provided by the team.

Notes by Coinsult

✅ No notes provided by Coinsult

MIM Machine (Staking) / Security Audit

Contract Snapshot

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

				
					contract MIMMachine is Token {
    uint256 private startTime = now - 1 days; 

    address payable private ADMIN;
    address payable private DEV_POOL;

    uint256 public totalUsers;
    uint256 public totalBUSDStaked;
    uint256 public totalTokenStaked;

    uint256 private constant FEE = 100; // 10% fee
    uint256 private constant MANUAL_AIRDROP = 50000 ether; // marketing + giveaways

    uint256 private constant PERCENT_DIVIDER = 1000;
    uint256 private constant PRICE_DIVIDER = 1 ether;
    uint256 private constant TIME_STEP = 1 days;
    uint256 private constant TIME_TO_UNSTAKE = 7 days;


    // Configurables
    uint256 public MIN_INVEST_AMOUNT = 5 ether;
    uint256 public SELL_LIMIT = 50000 ether;
    uint256 public BUSD_DAILYPROFIT = 20; // 2%
    uint256 public TOKEN_DAILYPROFIT = 40; // 4%

    mapping(address => User) private users;
    mapping(uint256 => uint256) private sold;

    struct Stake {
        uint256 checkpoint;
        uint256 totalStaked;
        uint256 lastStakeTime;
        uint256 unClaimedTokens;
    }

    struct User {
        Stake sM; // staked BUSD
        Stake sT; // staked BMT
    }

    event TokenOperation(
        address indexed account,
        string txType,
        uint256 tokenAmount,
        uint256 trxAmount
    );
				
			

MIM Machine (Staking) / 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?

MIM Machine (Staking) / Security Audit

Certificate of Proof

MIM Machine (Staking)

Audited by Coinsult.net

Date: 24 April 2022

Coinsult

coinsult.net

End of report
Smart Contract Audit

Request your smart contract audit / KYC

t.me/coinsult_tg