Vidma is pleased to present this audit report outlining our assessment of code, smart contracts, and other important audit insights and suggestions for management, developers, and users.
MegaFans is a multiplayer tournament platform. The audited scope included the MegaNFT.sol contract that implements the ERC721 NFT standard. The NFT contract allows users to buy NFT by paying the price in a native coin that is settled in the contract. There is some max supply for the token sale that can be changed by the contract owner, the same as price and baseTokenURI. The NFT contact inherits the Ownable functionality. Except listed above owner right, the owner has the ability to withdraw native coin from the SC that was paid as the price for each token. The owner of the contract can pause the token sale at any time, the same as unpause it back. The owner of the contract has an opportunity to mint NFT to any address without paying the required price.
During the audit process, the Vidma team found several issues. A detailed summary and the current state are displayed in the table below.
After evaluating the findings in this report and the final state after fixes, the Vidma auditors can state that the contracts are fully operational and secure. Under the given circumstances, we set the following risk level:
To set the codebase quality mark, our auditors are evaluating the initial commit given for the scope of the audit and the last commit with the fixes. This approach helps us adequately and sequentially evaluate the quality of the code. Code style, optimization of the contracts, the number of issues, and risk level of the issues are all taken into consideration. The Vidma team has developed a transparent evaluation codebase quality system presented below.
Evaluating the initial commit and the last commit with the fixes, Vidma audit team set the following codebase quality mark.
Score
Based on the overall result of the audit and the state of the final reviewed commit, the Vidma audit team grants the following score:
In addition to manual check and static analysis, the auditing team has conducted a number of integrated autotests to ensure the given codebase has an adequate performance and security level. The test results and coverage can be found in the accompanying section of this audit report.
Please be aware that this audit does not certify the definitive reliability and security level of the contract. This document describes all vulnerabilities, typos, performance issues, and security issues found by the Vidma audit team.
If the code is still under development, we highly recommend running one more audit once the code is finalized.
Bringing the online gaming community together, MEGAFANS strives to provide a fun and competitive environment to gamers of all levels. Their esports game platform also gives gamers a chance to win cash prizes by participating and have even more fun when playing mobile games online. It's hard to find a mobile game system that combines fun and monetary incentives, but MEGAFANS does exactly that.
Within the scope of this audit, two independent auditors thoroughly investigated the given codebase and analyzed the overall security and performance of the smart contracts.
The audit was conducted on Thursday, April 20, 2023.
The initial review of the fixes was conducted on Friday, April 21, 2023. The second review of the fixes is conducted on Monday, April 24th. Two new issues are added to the list of findings. Both issues were caused during the fixing process.
The final review of the fixes was conducted on April 25th, 2023. During this review the Vidma audit team stated that all found issues are resolved.
The outcome is disclosed in this document.
The scope of work for the given audit consists of the following contract:
The source code was taken from the following source:
https://github.com/megafans/SmartContracts
Last commit reviewed by the auditing team:
Vidma audit team uses the most sophisticated and contemporary methods and well-developed techniques to ensure contracts are free of vulnerabilities and security risks. The overall workflow consists of the following phases:
After the Audit kick-off, our security team conducts research on the contract’s logic and expected behavior of the audited contract.
Vidma auditors do a deep dive into your tech documentation with the aim of discovering all the behavior patterns of your codebase and analyzing the potential audit and testing scenarios.
At this point, the Vidma auditors are ready to kick off the process. We set the auditing strategies and methods and are prepared to conduct the first audit part.
During the manual phase of the audit, the Vidma team manually looks through the code in order to find any security issues, typos, or discrepancies with the logic of the contract. The initial commit as stated in the agreement is taken into consideration.
Static analysis tools are used to find any other vulnerabilities in smart contracts that were missed after a manual check.
An interim report with the list of issues.
Within the testing part, Vidma auditors run integration tests using the Truffle or Hardhat testing framework. The test coverage and the test results are inserted in the accompanying section of this audit report.
Second interim report with the list of new issues found during the testing part of the audit process.
For simplicity in reviewing the findings in this report, Vidma auditors classify the findings in accordance with the severity level of the issues. (from most critical to least critical).
All issues are marked as “Resolved” or “Unresolved”, depending on if they have been fixed by project team or not. The issues with “Not Relevant” status are left on the list of findings but are not eligible for the score points deduction.
The latest commit with the fixes reviewed by the auditors is indicated in the “Scope of Work” section of the report.
The Vidma team always provides a detailed description of the issues and recommendations on how to fix them.
Classification of found issues is graded according to 6 levels of severity described below:
Medium MM – 01 | Resolved
In MegaNFT contract the function withdraw() use send method to transfer ether. Both send and transfer forward a stipend of 2300 gas, which is just enough to log an event at the receiving contract. In case the receiver requires a larger amount of gas to handle the reception of ether, call.value has to be used, as it forwards all remaining gas, unless specified otherwise with the help of the .gas() parameter.
Read more about this issue:
https://fravoll.github.io/solidity-patterns/secure_ether_transfer.html
Use call to transfer ether.
Medium MM – 02 | Resolved
In the contract, there is a case when the owner can mint a token and not pay the price. In this case, msg.value will be zero. But there is a require in the whenNotPausedAndValidSupply() modifier to check if the sent ether value by the user is above 0. That's why the owner won't be able to call internalMint() function at any time.
Consider removing the require in line 53.
Low ML – 01 | Resolved
In MegaNFT contract events are emitted without indexed parameter, which helps to log parameters in a transaction. The reason it is important to add indexed parameter to events is that it allows for more efficient and selective event filtering. By making certain parameters as indexed, Solidity can create an index of these values, making it easier and faster to search for events with the specific parameter value.
Add indexed parameter in events.
Low ML – 02 | Resolved
In MegaNFT in constructor contractPaused value set to false. This is a useless step that increases the use of gas, as a bool value by default is false.
Remove the initialization of the variable from constructor.
Low ML – 03 | Resolved
In MegaNFT the global values baseTokenURI and maxSupply are created without declaring their visibility. By default it is internal, but the best practice is to set visibility directly.
Add visibility to baseTokenURI and maxSupply variables.
Low ML – 04 | Resolved
In MegaNFT contract most of the functions have absent to check input parameters for zero value.
Add require for inputs.
Low ML – 05 | Resolved
Require require(_tokenId != 0, "ERC721Metadata: token must not be 0") in tokenURI() function line 137 is never reached. The starting token id is 1 so it is impossible that the token with id 0 will ever exist. Its condition is checked in the require in line 133. So that is why the mentioned previously require in line 137 is useless.
Consider deleting the require in line 137.
Informational MI – 01 | Resolved
In MegaNFT smart contract the functions mint(), mint_to(), internalMint(), pauseContract() and unpauseContract() have public visibility. The visibility can be changed to external, as it consumes less gas, and functions are not called outside the contract.
Change functions visibility.
After re-audit, the function setBaseURI() still has public visibility, which can be changed to external.
Informational MI – 02 | Resolved
In MegaNFT smart contract the order of functions and declared variables are not the same as in solidity documentation.
Layouts, functions, and modifier order should be grouped according to Solidity documentation:
Layouts:
Functions:
Pay attention to the order of global variables and internal and public functions.
After re-audit there is still left one function setBaseURI(), which is public, between two external functions. It should be declared after all external and before internal.
Informational MI – 03 | Resolved
MegaNFT smart contract has no explanation for functions and variables, which makes it harder to understand the contract’s logic.
Add Natspec even for internal and private functions in all contracts that do not have it.
Informational MI – 04 | Resolved
In MegaNFT smart contract has mint and mint_to functions with the same requires. To reduce repetitive code, checking conditions can be moved to a separate function. At the same time this require require(!contractPaused, "Sale Paused!"); is used three times and can be moved to a modifier.
Create a modifier for checking if the contract is paused, and add a separate function for requires.
Informational MI – 05 | Resolved
In MegaNFT smart contract the function mint_to() doesn’t follow naming conventions from official documentation:
https://docs.soliditylang.org/en/v0.8.17/style-guide.html#naming-styles
Rename function to mintTo().
Informational MI – 06 | Resolved
In MegaNFT smart contract the current pragma Solidity directive is “^0.8.16”. It is recommended to specify a fixed compiler version to ensure that the bytecode produced does not vary between builds. This is especially important if you rely on bytecode-level verification of the code.
Change the version to “0.8.16”.
The project team didn't change the pragma version or leave any comment about this issue. Hence, the issue is till unresolved.
To verify the security of contracts and the performance, a number of integration tests were carried out using the Hardhat testing framework.
In this section, we provide both tests written by MEGAFANS and tests written by Vidma auditors.
Vidma Coverage – 100%
Industry Standard – 95%
It is important to note that Vidma auditors do not modify, edit or add tests to the existing tests provided in the MEGAFANS repository. We write totally separate tests with code coverage of a minimum of 95% to meet the industry standards.
We are delighted to have a chance to work with the MEGAFANS team and contribute to your company's success by reviewing and certifying the security of your smart contracts.
The statements made in this document should be interpreted neither as investment or legal advice, nor should its authors be held accountable for decisions made based on this document.