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.
The audited scope included contracts that allow trading one token for another and staking contract for farms. For Exchange liquidity pools, a fixed 0.25% trading fee is applied, which is broken down as follows: 0.17% returned to liquidity providers 0.08% kept by EG.
The auditor team found issues, most of which did not significantly impact the contract’s ability to operate. After the first review most issues are resolved or not relevant after logic changing & removing functionality, some of them were partly fixed but some points are missed. After second review the rest of issues are fixed excluding 1 issue (informational).
The changes are reflected in this version of the report accordingly.
During the audit process, the Vidma team found several issues, including those with critical severity. 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.
EGSwap represents a transformative step forward in the decentralized finance (DeFi) landscape.
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 scope of work for the given audit consists of the following contracts:
The source code was taken from the following source:
https://github.com/EG-Ecosystem/EGSwap-SmartContracts
Initial commit submitted for the audit:
bcd34de12385c6d4824d0ade95e3d409b925c251
Last commit reviewed by the auditing team:
e8544d6dab3dfa25f808ab758768396671db400f
As a reference to the contracts logic, business concept, and the expected behavior of the codebase, the EGSwap team has provided the following documentation:
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:
High MH – 01 | Not relevant
The Migrator contract was not provided to the audit. If an incorrect migrator address will be passed to the Masterchef contract the migrate() function may fail.
In case, when more reward or staked tokens will be withdrawn with safeApprove() function user calls (withdraw(), leaveStaking(), emergencyWithdraw() functions) could be failed if token balance of the contract will be insufficient.
Make sure that Migrator contract will proceed correctly.
Not relevant after removing functionality.
High MH – 02 | Resolved
The safeApprove() can approve a spender to withdraw all tokens by owner (including EG and LP tokens from the contract).
Make sure that transferring more tokens after safeApprove() will not break operating of the contract.
High MH – 03 | Resolved
In the EGSwapPair Smart Contract in the initialize() function there is two lines:
that makes possibility to withdraw pair tokens of users from the contract by feeToSetter. It can decrease user trust to the project.
Provide the technical description of needing these lines or remove it.
Low ML – 01 | Resolved
In the audited codebase there are some functions that not called in the contract itself so their visibility can be improved from public to external:
Consider changing visibility from public to external to safe gas usage on calling these functions.
Resolved but missed for emergencyWithdraw() function.
Resolved.
Low ML – 02 | Resolved
There is a duplicated if statement in the withdraw() function of the Masterchef contract (L1208).
Remove duplicated if (pending > 0):
Low ML – 03 | Resolved
_msgSender() function can be used instead of msg.sender in Masterchef Smart Contract because it is inherited from Context Smart Contract. The _msgSender() function call requires less gas than msg.sender.
Consider changing msg.sender to _msgSender().
Not resolved for calls in the emergencyWithdraw() function.
Resolved.
Low ML – 04 | Not relevant
In the Materchef Smart Contract there is deposit() functions that can be optimized to process result of ternary operator to transfer EG that will decrease using of if-else branching:
to:
Consider using ternary operators. It can also be used in the withdraw(), enterStaking(), leaveStaking() functions and validateStakingTime():
to:
Not relevant after logic changing.
Low ML – 05 | Resolved
There are state variables in Masterchef contract that are initialized by default type value that can be avoided:
Consider removing initialization by the default type value in the described cases.
Low ML – 06 | Resolved
In function emergencyWithdraw() assigns zero value to few struct fields. It is more efficient to use delete operator here to save gas usage on the function execution:
Consider using delete operator to “clear” variables.
Low ML – 07 | Resolved
In function setMigrator() the migrator address is not checked if the passed address isn’t zero address. Same for the dev() function – if dev will be zero address then all transferred fees will be burned.
Consider adding a requirement statement to check if the value isn’t zero value.
Low ML – 08 | Resolved
There is pairFor() call in the getReserves() function of EGSwapRouter contract (line 303) that returns a CREATE2 address for a pair but it’s not stored to the variable and duplicates the call in the next line.
Consider removing the pairFor() call in the getReserves() function (line 303).
Low ML – 09 | Resolved
There is the requirement in the add() function of Masterchef contract (line 1051):
that could be simplified to decrease gas usage:
Consider changing requirement for gas optimization.
Low TL – 01 | Resolved
There are missed few points of using safe functions in Masterchef contract:
to:
In safeEGTransfer() function:
to:
In emergencyWithdraw() function:
to:
In emergencyWithdraw() function:
to:
In leaveStaking() function:
to:
In leaveStaking() function:
to:
Use safe functions for calculating values and transferring tokens in all cases.
Informational MI – 01 | Unresolved
EGSwapFactory, EGSwapRouter, Masterchef and dependencies contracts are not covered by NatSpec. There are some functions that are covered only by simple comments. Follow:
Consider covering all functions with qualitative and fully NatSpec comments.
Not resolved, only some comments were added. Check the examples with links added in the issue, use triple-slash and tags (@author, @notice, @param etc) to write NatSpec documentation.
Informational MI – 02 | Resolved
There are some typos in the contracts code:
There is typo in comment, appears in Masterchef contract: poitns -> points.
Consider fixing typos.
Informational MI – 03 | Resolved
According to Solidity Style Guide, state and local variables should be in mixedCase style. In the Masterchef contract there are such variables that could be changed:
Consider following the Solidity style guide 0.6.12 and naming conventions.
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 EGSwap 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 EGSwap 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 Naplozz 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.