Coinsult

Request your audit at coinsult.net

Advanced Manual
Smart Contract Audit

May 25, 2022

Audit requested by

Cyberpop (loot box)

0x10fde59432d1d6ee7ad25448e3d8b9b3d2c08b89

Cyberpop (loot box) / 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 Cyberpop (loot box)

7. Contract Snapshot

8. Website Review

9. Certificate of Proof

Cyberpop (loot box) / Security Audit

Audit Summary

Audit Scope

Project Name

Cyberpop (loot box)

Blockchain

Binance Smart Chain

Smart Contract Language

Solidity

Contract Address

0x10fde59432d1d6ee7ad25448e3d8b9b3d2c08b89

Audit Method

Static Analysis, Manual Review

Date of Audit

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

Cyberpop (loot box) / Security Audit

Tokenomics

Source Code

Coinsult was comissioned by Cyberpop (loot box) to perform an audit based on the following code:
https://bscscan.com/address/0x10fde59432d1d6ee7ad25448e3d8b9b3d2c08b89#code

This contract contains 19 imported modules.

Cyberpop (loot box) / 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.

Cyberpop (loot box) / 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

4

0

0

0

1

0

0

0

0

0

0

0

Cyberpop (loot box) / Security Audit

Avoid relying on block.timestamp

block.timestamp can be manipulated by miners.

				
					function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual override {
        require(block.timestamp <= deadline, "ERC20Permit: expired deadline");

        bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));

        bytes32 hash = _hashTypedDataV4(structHash);

        address signer = ECDSA.recover(hash, v, r, s);
        require(signer == owner, "ERC20Permit: invalid signature");

        _approve(owner, spender, value);
    }
				
			

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.

Cyberpop (loot box) / Security Audit

Too many digits

Literals with many digits are difficult to read and review.

				
					    uint256 constant INVERSE_BASIS_POINT = 10000;
				
			

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.

Cyberpop (loot box) / Security Audit

No zero address validation for some functions

Detect missing zero address validation.

				
					    function setFactoryForOption(uint256 _optionId, address _factoryAddress)
        public
        onlyRole(DEFAULT_ADMIN_ROLE)
    {
        LootBoxRandomness.setFactoryForOption(
            state,
            _optionId,
            _factoryAddress
        );
    }
				
			

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.

Cyberpop (loot box) / Security Audit

Missing events arithmetic

Detect missing events for critical arithmetic parameters.

				
					    function setProbabilitiesForOption(
        uint256 _optionId,
        uint16[] memory _probabilities
    ) public onlyRole(DEFAULT_ADMIN_ROLE) {
        LootBoxRandomness.setProbabilitiesForOption(
            state,
            _optionId,
            _probabilities
        );
    }
				
			

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.

Cyberpop (loot box) / Security Audit

Costly operations inside a loop

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

				
					   function _burnBatch(
        address from,
        uint256[] memory ids,
        uint256[] memory amounts
    ) internal virtual {
        require(from != address(0), "ERC1155: burn from the zero address");
        require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch");

        address operator = _msgSender();

        _beforeTokenTransfer(operator, from, address(0), ids, amounts, "");

        for (uint256 i = 0; i = amount, "ERC1155: burn amount exceeds balance");
            unchecked {
                _balances[id][from] = fromBalance - amount;
            }
        }

        emit TransferBatch(operator, from, address(0), ids, amounts);

        _afterTokenTransfer(operator, from, address(0), ids, amounts, "");
    }
				
			

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.

Minter role can mint
				
					    function mint(
        address account,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) public onlyRole(MINTER_ROLE) whenNotPaused {
        _mint(account, id, amount, data);
    }
				
			

Recommendation

No recommendation

Cyberpop (loot box) / Security Audit

Other Owner Privileges Check

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

⚠ Owner can change probabilities

⚠ Owner can mint

⚠ Owner can burn

⚠ Owner can pause the contract

Cyberpop (loot box) / Security Audit

Notes

Notes by Cyberpop (loot box)

No notes provided by the team.

Notes by Coinsult

✅ No notes provided by Coinsult

Cyberpop (loot box) / Security Audit

Contract Snapshot

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

				
					contract LootBox is
    ERC1155,
    ERC1155Burnable,
    ERC1155Supply,
    AccessControl,
    ReentrancyGuard,
    Pausable
{
    using LootBoxRandomness for LootBoxRandomness.LootBoxRandomnessState;
    LootBoxRandomness.LootBoxRandomnessState private state;
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");

    constructor() ERC1155("https://api.cyberpop.online/box/") {
        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _setupRole(MINTER_ROLE, msg.sender);
    }

    function name() public pure returns (string memory) {
        return "CyberPop Loot Box";
    }

    function symbol() public pure returns (string memory) {
        return "CLB";
    }

    function setURI(string memory newuri) public onlyRole(DEFAULT_ADMIN_ROLE) {
        _setURI(newuri);
    }

    function uri(uint256 _tokenId)
        public
        view
        override
        returns (string memory)
    {
        string memory uri_prefix = super.uri(_tokenId);
        return string(abi.encodePacked(uri_prefix, Strings.toString(_tokenId)));
    }
				
			

Cyberpop (loot box) / 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?

Cyberpop (loot box) / Security Audit

Certificate of Proof

Cyberpop (loot box)

Audited by Coinsult.net

Date: 25 May 2022

Coinsult

coinsult.net

End of report
Smart Contract Audit

Request your smart contract audit / KYC

t.me/coinsult_tg