Introduction
We express our gratitude to the Covalent team for the collaborative engagement that enabled the execution of this Smart Contract Security Assessment.
Document | |
|---|---|
| Name | Smart Contract Code Review and Security Analysis Report for Covalent |
| Audited By | , Viktor Raboshchuk |
| Approved By | Przemyslaw Swiatowiec |
| Website | https://www.covalenthq.com/→ |
| Changelog | 27/06/2024 - Preliminary Report, 04/07/2024 - Final Report |
| Platform | EVM |
| Language | Solidity |
| Tags | ERC20 |
| Methodology | https://hackenio.cc/sc_methodology→ |
Document
- Name
- Smart Contract Code Review and Security Analysis Report for Covalent
- Audited By
- , Viktor Raboshchuk
- Approved By
- Przemyslaw Swiatowiec
- Website
- https://www.covalenthq.com/→
- Changelog
- 27/06/2024 - Preliminary Report, 04/07/2024 - Final Report
- Platform
- EVM
- Language
- Solidity
- Tags
- ERC20
- Methodology
- https://hackenio.cc/sc_methodology→
Review Scope | |
|---|---|
| Repository | https://github.com/covalenthq/covalent-x-token→ |
| Commit | 3c3db2841fcd77415c42413feabe483f9b8a8881 |
Review Scope
- Commit
- 3c3db2841fcd77415c42413feabe483f9b8a8881
Audit Summary
The system users should acknowledge all the risks summed up in the risks section of the report
Documentation quality
Functional requirements are mostly missed.
The technical description is not provided.
NatSpec is sufficient.
Code quality
No code quality issues were found.
Test coverage
Code coverage of the project is 93.10% (branch coverage).
Deployment and basic user interactions are covered with tests.
System Overview
CovalentMigration - is a smart contract that is designed for the initial migration of Covalent Network Tokens. It has a setToken function to set a new token, and batchDistribute function to distribute tokens to multiple recipients in one transaction.
CovalentXToken - is a ERC20 token with additional functionalities. It inherits from ERC20Permit and AccessControlEnumerable, and implements ICovalentXToken. The mint function allows token minting within a capped rate, updateMintCap changes the minting cap, updatePermit2Allowance manages permit2's allowance. The token has the following attributes:
Name: Covalent X Token
Symbol: CXT
Decimals: 18
DefaultEmissionManager - is a contract designed for managing the emissions of the Covalent ERC20 token on Ethereum L1. It uses Ownable2StepUpgradeable for ownership management and SafeERC20 for safe token operations. The mint function calculates the new supply based on the elapsed time and mints the required amount to maintain the target inflation rate, transferring minted tokens to the treasury. The inflatedSupplyAfter function calculates the expected supply after a given time period using the PowUtil library.
Privileged roles
The owner of the CovalentMigration contract can set new tokens, and distribute the tokens to the users.
The DEFAULTADMINROLE of the CovalentXToken contract can grant and revoke any roles.
The EMISSION_ROLE of the CovalentXToken contract can mint new tokens using the
mintfunction, within the constraints of the minting cap.The CAPMANAGERROLE of the CovalentXToken contract can update the minting cap using the
updateMintCapfunction.The PERMIT2REVOKERROLE of the CovalentXToken contract can update the allowance for the
PERMIT2address using theupdatePermit2Allowancefunction.The deployer (set during the contract deployment) of the DefaultEmissionManager.sol contract is the only entity allowed to initialize the contract
Risks
The project utilizes Solidity version 0.8.20 or higher, which includes the introduction of the PUSH0 (0x5f) opcode. This opcode is currently supported on the Ethereum mainnet but may not be universally supported across other blockchain networks. Consequently, deploying the contract on chains other than the Ethereum mainnet, such as certain Layer 2 (L2) chains or alternative networks, might lead to compatibility issues or execution errors due to the lack of support for the PUSH0 opcode. In scenarios where deployment on various chains is anticipated, selecting an appropriate Ethereum Virtual Machine (EVM) version that is widely supported across these networks is crucial to avoid potential operational disruptions or deployment failures.
The project has minimal documentation. This lack of comprehensive comments and explanations can lead to misunderstandings about the contract's functionality and intended behavior. It also makes the contract harder to maintain and audit, as future developers or auditors may not fully understand the contract's logic or the implications of its functions. This could potentially lead to overlooked bugs or security vulnerabilities. Furthermore, it may not meet the functional requirements if they are not clearly documented and understood.
In the DefaultEmissionManager.sol contract, the exp2 function from the PowUtil library is called with a potentially large argument. The exp2 function expects an unsigned 192.64-bit fixed-point number, and returns a 60.18 unsigned fixed-point number. If the argument passed to exp2 exceeds the precision of a 192.64-bit fixed-point number, it could result in precision loss and inaccurate calculations.
The DefaultEmissionManager.sol contract uses the safeApprove function from the OpenZeppelin library, which has been deprecated due to potential security risks. The safeApprove function can potentially lead to a race condition where someone may use both the old and the new allowance due to unfortunate transaction ordering. This could result in unauthorized or unexpected token transfers. OpenZeppelin recommends first reducing the spender's allowance to 0 and then setting the desired value to mitigate this risk.
The CovalentXToken.sol contract forces users to grant infinite approval to the PERMIT2 address from Uniswap when the permit2Enabled variable is set to true. This could potentially expose users to unnecessary risks, as it allows the PERMIT2 address to spend an unlimited amount of tokens from the user's account at any time. While this might be intended to facilitate transactions with PERMIT2, it could be seen as an overreach, as users could simply approve to PERMIT2 when they want to use it, rather than being forced to grant infinite approval. This practice could potentially lead to misuse or unintended token transfers if the PERMIT2 address is compromised.
The DefaultEmissionManager.sol contract's constructor is initializing immutable variables. This practice is generally discouraged because immutable variables are set at contract creation and cannot be changed afterwards. In the context of upgradeable contracts, this means that all proxies that share the same implementation contract will also share the same values for these immutable variables. If this is not the intended behavior, it could lead to unexpected results and potential security risks.
Findings
Code ― | Title | Status | Severity | |
|---|---|---|---|---|
| F-2024-4076 | Inefficient Token Minting Process in DefaultEmissionManager.sol | fixed | Observation | |
| F-2024-4075 | Incomplete Initialization of DefaultEmissionManager.sol Contract | fixed | Observation | |
| F-2024-4073 | Floating Pragma Statement in CovalentXToken.sol | fixed | Observation | |
| F-2024-4072 | Missing Zero Address Check in setToken Function | fixed | Observation |
Appendix 1. Severity Definitions
When auditing smart contracts, Hacken is using a risk-based approach that considers Likelihood, Impact, Exploitability and Complexity metrics to evaluate findings and score severities.
Reference on how risk scoring is done is available through the repository in our Github organization:
Severity | Description |
|---|---|
Critical | Critical vulnerabilities are usually straightforward to exploit and can lead to the loss of user funds or contract state manipulation. |
High | High vulnerabilities are usually harder to exploit, requiring specific conditions, or have a more limited scope, but can still lead to the loss of user funds or contract state manipulation. |
Medium | Medium vulnerabilities are usually limited to state manipulations and, in most cases, cannot lead to asset loss. Contradictions and requirements violations. Major deviations from best practices are also in this category. |
Low | Major deviations from best practices or major Gas inefficiency. These issues will not have a significant impact on code execution, do not affect security score but can affect code quality score. |
Severity
- Critical
Description
- Critical vulnerabilities are usually straightforward to exploit and can lead to the loss of user funds or contract state manipulation.
Severity
- High
Description
- High vulnerabilities are usually harder to exploit, requiring specific conditions, or have a more limited scope, but can still lead to the loss of user funds or contract state manipulation.
Severity
- Medium
Description
- Medium vulnerabilities are usually limited to state manipulations and, in most cases, cannot lead to asset loss. Contradictions and requirements violations. Major deviations from best practices are also in this category.
Severity
- Low
Description
- Major deviations from best practices or major Gas inefficiency. These issues will not have a significant impact on code execution, do not affect security score but can affect code quality score.
Appendix 2. Scope
The scope of the project includes the following smart contracts from the provided repository:
Scope Details | |
|---|---|
| Repository | https://github.com/covalenthq/covalent-x-token→ |
| Commit | 3c3db2841fcd77415c42413feabe483f9b8a8881 |
| Deployed Address | 0x7ABc8A5768E6bE61A6c693a6e4EAcb5B60602C4D (Ethereum Mainnet) |
| Whitepaper | |
| Requirements | https://covalentnetwork.mintlify.app/introduction→ |
| Technical Requirements | https://covalentnetwork.mintlify.app/introduction→ |
Scope Details
- Commit
- 3c3db2841fcd77415c42413feabe483f9b8a8881
- Deployed Address
- 0x7ABc8A5768E6bE61A6c693a6e4EAcb5B60602C4D (Ethereum Mainnet)
- Whitepaper
- Technical Requirements
- https://covalentnetwork.mintlify.app/introduction→