Muni Game

Smart Contract Audit Report

Audit Summary

Muni Game Audit Report Muni Game is a new lottery system consisting of individual rounds where users can purchase tickets using ETH.

For this audit, we reviewed the Lottery contract using code provided by the project team.

Audit Findings

An informational finding remains present that team may want to review. In addition, centralized aspects are present.
Date: October 26th, 2022.
Updated: October 26th, 2022 to reflect changes made by the project team.
Updated: October 27th, 2022 to reflect changes made by the project team.

Finding #1 - Lottery - High (Resolved)

Description: Users are permitted to purchase tickets for a round even if its winner has already been selected.
Risk/Impact: If a winner is selected and a new round has not been started, users purchasing tickets will lose their ETH to the contract.
Recommendation: The team should disallow users from purchasing tickets for a round if a winner has already been selected.
Resolution: Users are no longer allowed to purchase tickets for a round that already has a winner or has been refunded.

Finding #2 - Lottery - Medium (Resolved)

Description: Users are only intended to be permitted to purchase one ticket per round; however, the bought mapping for the user is not correctly updated upon purchase of a ticket.
Risk/Impact: Users will be able to purchase multiple tickets against intended functionality.
Recommendation: The following line should be added immediately after the require statements in the buyTicket() function:
bought[msg.sender] = true;
Resolution: The project team has implemented the above recommendation.

Finding #3 - Lottery - Medium (Resolved)

Description: The ticket and bought mappings are iterated through and cleared in an unbounded loop at the start of new rounds.
Risk/Impact: Creation of a new round may fail leading to a denial of service due to the execution cost of the transaction exceeding the block's gas limit if the number of tickets purchased for the round is too large.
Recommendation: The ticket mapping can instead be stored as an array of addresses with its indexes used as the elements' corresponding ticket numbers. The array can then be deleted at the start of a new round. The bought mapping can instead be stored as a mapping(address=>int) in which the integer corresponds to the round number of their most recent ticket purchase.
Resolution: The maximum number of tickets for a round can now only be set to a value less than or equal to 10.

Finding #4 - Lottery - Medium (Resolved)

Description: The refund() function iterates through the entire list of ticket holders to transfer each user's ETH.
Risk/Impact: A refund may fail leading to a denial of service due to the execution cost of the transaction exceeding the block's gas limit if the number of users to be refunded for a round is too large. Users will then be unable to receive their refund.
Recommendation: The team should mark a round as refunded and allow users to claim individually, or limit the total number of tickets that can be sold per round to a small number.
Resolution: The maximum number of tickets for a round can now only be set to a value less than or equal to 10.

Finding #5 - Lottery - Low (Resolved)

Description: The weiVal variable is intended to be used to set the ticket price for a round, but the price is instead hardcoded as 0.5 ETH.
Risk/Impact: The owner will not be able to update the price of a ticket.
Recommendation: The weiVal variable should be used to determine ticket prices and refund amounts.
Resolution: The team has implemented the above recommendation.

Finding #6 - Lottery - Informational

Description: The s_owner variable is initialized but never used.
Recommendation: This state variable can be removed to save on deployment costs.

Contract Overview

  • This contract allows the owner to create lotteries in which a limited number of users can participate in.
  • A user can purchase a ticket for a lottery round for the specified price in ETH set by the owner.
  • A user is only permitted to purchase one ticket per round.
  • The owner can trigger a random winner to be selected at any time.
  • Chainlink is used to decide the winning ticket. If the maximum number of tickets for a round have not been purchased, the 0 address can be selected as the winner.
  • Once a winner is decided, they are transferred the total ETH balance of the contract after a 10% tax is taken.
  • The tax is transferred to the owner.
  • The owner can end a round and begin a new one at any time, even if a winner has not been chosen for the current round.
  • All existing tickets are deleted when a new round is started, and a new maximum participant amount and price are set.
  • The maximum number of participants for a round cannot exceed 10.
  • Whenever a ticket is purchased, the Stats contract's incrementTOTAL() and incrementPLAYED() functions are executed.
  • When a winner is selected, the Stats contract's incrementWON() function is executed.
  • As the Stats contract was not included in the scope of this audit, we are unable to provide an assessment with regards to security or functionality.
  • The owner can refund all ticket payments for the current round at any time. This will not reset the round or remove existing tickets.
  • The owner of the contract is set to address 0xE6F747501498903758BDF7AE648188E86f508Ef6 and cannot be updated.

Audit Results

Vulnerability Category Notes Result
Arbitrary Jump/Storage Write N/A PASS
Centralization of Control
  • The owner has the permissions described above.
  • The owner can delete all tickets and start a new round at any time, even if a winner has not been selected or a refund has not been issued.
  • WARNING
    Compiler Issues N/A PASS
    Delegate Call to Untrusted Contract N/A PASS
    Dependence on Predictable Variables N/A PASS
    Ether/Token Theft N/A PASS
    Flash Loans N/A PASS
    Front Running N/A PASS
    Improper Events N/A PASS
    Improper Authorization Scheme N/A PASS
    Integer Over/Underflow N/A PASS
    Logical Issues N/A PASS
    Oracle Issues N/A PASS
    Outdated Compiler Version N/A PASS
    Race Conditions N/A PASS
    Reentrancy N/A PASS
    Signature Issues N/A PASS
    Unbounded Loops N/A PASS
    Unused Code N/A PASS
    Overall Contract Safety   PASS

    Inheritance Chart

    Smart Contract Audit - Inheritance

    Function Graph

    Smart Contract Audit - Graph

    Functions Overview

    
       ($) = payable function
       # = non-constant function
       
       + [Int] VRFCoordinatorV2Interface 
          - [Ext] getRequestConfig
          - [Ext] requestRandomWords #
          - [Ext] createSubscription #
          - [Ext] getSubscription
          - [Ext] requestSubscriptionOwnerTransfer #
          - [Ext] acceptSubscriptionOwnerTransfer #
          - [Ext] addConsumer #
          - [Ext] removeConsumer #
          - [Ext] cancelSubscription #
          - [Ext] pendingRequestExists
    
       +  VRFConsumerBaseV2 
          - [Pub]  #
          - [Int] fulfillRandomWords #
          - [Ext] rawFulfillRandomWords #
    
       + [Int] Stats 
          - [Ext] incrementTOTAL #
          - [Ext] incrementWON #
          - [Ext] incrementLOST #
          - [Ext] incrementPLAYED #
    
       +  Lottery (VRFConsumerBaseV2)
          - [Pub]  #
             - modifiers: VRFConsumerBaseV2
          - [Pub] editVal #
             - modifiers: OnlyOwner
          - [Pub] buyTicket ($)
          - [Ext] requestRandomWords #
             - modifiers: OnlyOwner
          - [Int] fulfillRandomWords #
          - [Int] settleLotto #
          - [Pub] refund #
             - modifiers: OnlyOwner
    
          

    About SourceHat

    SourceHat has quickly grown to have one of the most experienced and well-equipped smart contract auditing teams in the industry. Our team has conducted 1800+ solidity smart contract audits covering all major project types and protocols, securing a total of over $50 billion U.S. dollars in on-chain value!
    Our firm is well-reputed in the community and is trusted as a top smart contract auditing company for the review of solidity code, no matter how complex. Our team of experienced solidity smart contract auditors performs audits for tokens, NFTs, crowdsales, marketplaces, gambling games, financial protocols, and more!

    Contact us today to get a free quote for a smart contract audit of your project!

    What is a SourceHat Audit?

    Typically, a smart contract audit is a comprehensive review process designed to discover logical errors, security vulnerabilities, and optimization opportunities within code. A SourceHat Audit takes this a step further by verifying economic logic to ensure the stability of smart contracts and highlighting privileged functionality to create a report that is easy to understand for developers and community members alike.

    How Do I Interpret the Findings?

    Each of our Findings will be labeled with a Severity level. We always recommend the team resolve High, Medium, and Low severity findings prior to deploying the code to the mainnet. Here is a breakdown on what each Severity level means for the project:

    • High severity indicates that the issue puts a large number of users' funds at risk and has a high probability of exploitation, or the smart contract contains serious logical issues which can prevent the code from operating as intended.
    • Medium severity issues are those which place at least some users' funds at risk and has a medium to high probability of exploitation.
    • Low severity issues have a relatively minor risk association; these issues have a low probability of occurring or may have a minimal impact.
    • Informational issues pose no immediate risk, but inform the project team of opportunities for gas optimizations and following smart contract security best practices.