Introduction
We express our gratitude to the X-Pass team for the collaborative engagement that enabled the execution of this Smart Contract Security Assessment.
XPass is an ERC-20 token project with a locking mechanism.
Document | |
|---|---|
| Name | Smart Contract Code Review and Security Analysis Report for X-Pass |
| Audited By | Olesia Bilenka |
| Approved By | Przemyslaw Swiatowiec |
| Website | https://x-pass.io/→ |
| Changelog | 24/10/2024 - Preliminary Report |
| 29/10/2024 - Final Report | |
| Platform | Ethereum Mainnet |
| Language | Solidity |
| Tags | Fungible Token, Centralization, ERC-20 |
| Methodology | https://hackenio.cc/sc_methodology→ |
Document
- Name
- Smart Contract Code Review and Security Analysis Report for X-Pass
- Audited By
- Olesia Bilenka
- Approved By
- Przemyslaw Swiatowiec
- Website
- https://x-pass.io/→
- Changelog
- 24/10/2024 - Preliminary Report
- 29/10/2024 - Final Report
- Platform
- Ethereum Mainnet
- Language
- Solidity
- Tags
- Fungible Token, Centralization, ERC-20
- Methodology
- https://hackenio.cc/sc_methodology→
Review Scope | |
|---|---|
| Repository | https://github.com/xticket-dev-manager/xpasstoken/tree/main→ |
| Commit | 1ee0876 |
Review Scope
- Commit
- 1ee0876
Audit Summary
The system users should acknowledge all the risks summed up in the risks section of the report
Documentation quality
Functional requirements are provided.
Technical description is provided.
Code quality
The code duplicates commonly known contracts instead of reusing them.
The development environment is configured.
Test coverage
Code coverage of the project is 60.29% (branch coverage).
Tests are provided for key functionality.
The coverage for negative cases and allowance is missed.
System Overview
XPass is an ERC-20 token project with a locking mechanism.
BasicToken is a contract that provides basic ERC-20 functionalities, including managing token balances, transferring tokens between addresses, and retrieving the total supply of tokens. It emits events when transfers are executed.
Ownable is a contract that manages ownership of the token. It defines ownership transfer and allows functions to be restricted to the owner via the onlyOwner modifier.
BurnableToken extends the BasicToken contract by introducing the ability to burn tokens, reducing the total supply. It allows users to burn their own tokens, and it emits events when tokens are burned.
StandardToken extends ERC-20 functionality by adding allowances. It allows approved spenders to transfer tokens on behalf of an account using transferFrom and supports increasing or decreasing allowances.
XPASSToken is the main contract, implementing the full ERC-20 token standard with additional features like a locking mechanism and transfer restrictions. The owner can enable or disable transfers globally, and accounts can be locked, preventing the transfer of locked tokens. This contract also allows the owner to burn tokens when transfers are enabled and change the admin address.
Privileged roles
The owner of the XPASSToken contract can enable or disable token transfers globally. The owner can also lock or unlock any user's tokens by specifying the amount to be locked. Additionally, the owner can change the admin address.
The admin of the XPASSToken contract has the ability to perform token transfers even when transfers are globally disabled.
Potential Risks
Fixed Total Supply Post-Deployment: The token’s total supply is determined at deployment and cannot be verified beforehand, potentially limiting the project’s adaptability and economic model flexibility.
Centralized Minting to a Single Address: The project concentrates minting tokens in a single address, raising the risk of fund mismanagement or theft, especially if key storage security is compromised.
Owner's Unrestricted State Modification: The absence of restrictions on state variable modifications by the owner leads to arbitrary changes, affecting contract integrity and user trust, especially during critical operations like minting phases.
Absence of Time-lock Mechanisms for Critical Operations: Without time-locks on critical operations, there is no buffer to review or revert potentially harmful actions, increasing the risk of rapid exploitation and irreversible changes.
Centralization Risk in XPASSToken Leading to Token Locks: Within the XPASSToken contract, there is a function disableTransfer, which allows the owner to disable all token transfers. Additionally, the function lockAccount gives the owner the ability to lock any amount of tokens belonging to any user.
Findings
Code ― | Title | Status | Severity | |
|---|---|---|---|---|
| F-2024-6726 | Centralization Risk in XPASSToken Leading to Token Locks | fixed | Medium | |
| F-2024-6706 | Floating Pragma | mitigated | Observation | |
| F-2024-6705 | Unoptimized Storage Access for Total Supply | accepted | Observation | |
| F-2024-6728 | Potential Underflow in the onlyAllowedAmount Modifier | accepted | Observation | |
| F-2024-6727 | Redundant Comparisons to Boolean Values | accepted | Observation |
Appendix 1. Definitions
Severities
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. |
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.
Potential Risks
The "Potential Risks" section identifies issues that are not direct security vulnerabilities but could still affect the project’s performance, reliability, or user trust. These risks arise from design choices, architectural decisions, or operational practices that, while not immediately exploitable, may lead to problems under certain conditions. Additionally, potential risks can impact the quality of the audit itself, as they may involve external factors or components beyond the scope of the audit, leading to incomplete assessments or oversight of key areas. This section aims to provide a broader perspective on factors that could affect the project's long-term security, functionality, and the comprehensiveness of the audit findings.
Appendix 2. Scope
The scope of the project includes the following smart contracts from the provided repository:
Scope Details | |
|---|---|
| Repository | https://github.com/xticket-dev-manager/xpasstoken/tree/main→ |
| Commit | 1ee087682c9f42d3be8fd6a1b92d1e5f94de4221 |
| Whitepaper | https://github.com/xticket-dev-manager/xpasstoken/blob/main/README.md→ |
Scope Details
- Commit
- 1ee087682c9f42d3be8fd6a1b92d1e5f94de4221
Assets in Scope
Appendix 3. Additional Valuables
Verification of System Invariants
During the audit of XPass, Hacken followed its methodology by performing fuzz-testing on the project's main functions. Foundry, a tool used for fuzz-testing, was employed to check how the protocol behaves under various inputs. Due to the complex and dynamic interactions within the protocol, unexpected edge cases might arise. Therefore, it was important to use fuzz-testing to ensure that several system invariants hold true in all situations.
Fuzz-testing allows the input of many random data points into the system, helping to identify issues that regular testing might miss. A specific Echidna fuzzing suite was prepared for this task, and throughout the assessment, 17 invariants were tested over 100k runs. This thorough testing ensured that the system works correctly even with unexpected or unusual inputs.
Invariant | Test Result | Run Count |
|---|---|---|
BasicToken::totalSupply should always return the correct total supply of tokens. | Passed | 100k+ |
BasicToken::balanceOf should always return the correct balance for each token holder. | Passed | 100k+ |
BasicToken::transfer should always revert if the recipient address is address(0) or if the amount exceeds the sender's balance. | Failed | 100k+ |
BasicToken::transfer should always correctly update the sender's and recipient's balances after the transfer. | Passed | 100k+ |
StandardToken::transferFrom should always check if the spender has sufficient allowance for the transfer. | Passed | 100k+ |
StandardToken::transferFrom should always correctly update the sender's and recipient's balances after the transfer and reduce the allowed amount for the spender. | Passed | 100k+ |
StandardToken::approve should always successfully set an allowance for a spender to a verified amount. | Passed | 100k+ |
StandardToken::increaseAllowance should always successfully increase the allowed amount for a spender. | Passed | 100k+ |
StandardToken::decreaseAllowance should decrease and always check that the allowance is not reduced below zero. | Passed | 100k+ |
XPASSToken::transfer should revert if transferEnabled is false and msg.sender is not adminAddr. | Passed | 100k+ |
XPASSToken::transfer should revert if the recipient address is address(0), address(this), owner, or adminAddr. | Passed | 100k+ |
XPASSToken::transferFrom and transfer should only succeed if transferEnabled is true or msg.sender is adminAddr. | Passed | 100k+ |
XPASSToken::burn should revert if transferEnabled is false. | Passed | 100k+ |
XPASSToken::burn should succeed only when called by owner and when transferEnabled is true. | Passed | 100k+ |
XPASSToken::lockAccount should always revert if the account address is address(0), address(this), owner, or adminAddr. | Passed | 100k+ |
XPASSToken::unlockAccount should always reset the locked balance to zero for the specified account. | Passed | 100k+ |
XPASSToken::changeAdminAddr should set new admin address. | Passed | 100k+ |
Invariant
- BasicToken::
totalSupplyshould always return the correct total supply of tokens. Test Result
- Passed
Run Count
- 100k+
Invariant
- BasicToken::
balanceOfshould always return the correct balance for each token holder. Test Result
- Passed
Run Count
- 100k+
Invariant
- BasicToken::
transfershould always revert if the recipient address isaddress(0)or if the amount exceeds the sender's balance. Test Result
- Failed
Run Count
- 100k+
Invariant
- BasicToken::
transfershould always correctly update the sender's and recipient's balances after the transfer. Test Result
- Passed
Run Count
- 100k+
Invariant
- StandardToken::
transferFromshould always check if the spender has sufficient allowance for the transfer. Test Result
- Passed
Run Count
- 100k+
Invariant
- StandardToken::
transferFromshould always correctly update the sender's and recipient's balances after the transfer and reduce the allowed amount for the spender. Test Result
- Passed
Run Count
- 100k+
Invariant
- StandardToken::
approveshould always successfully set an allowance for a spender to a verified amount. Test Result
- Passed
Run Count
- 100k+
Invariant
- StandardToken::
increaseAllowanceshould always successfully increase the allowed amount for a spender. Test Result
- Passed
Run Count
- 100k+
Invariant
- StandardToken::
decreaseAllowanceshould decrease and always check that the allowance is not reduced below zero. Test Result
- Passed
Run Count
- 100k+
Invariant
- XPASSToken::
transfershould revert iftransferEnabledisfalseandmsg.senderis notadminAddr. Test Result
- Passed
Run Count
- 100k+
Invariant
- XPASSToken::
transfershould revert if the recipient address isaddress(0),address(this),owner, oradminAddr. Test Result
- Passed
Run Count
- 100k+
Invariant
- XPASSToken::
transferFromandtransfershould only succeed iftransferEnabledistrueormsg.senderisadminAddr. Test Result
- Passed
Run Count
- 100k+
Invariant
- XPASSToken::
burnshould revert iftransferEnabledisfalse. Test Result
- Passed
Run Count
- 100k+
Invariant
- XPASSToken::
burnshould succeed only when called by owner and whentransferEnabledistrue. Test Result
- Passed
Run Count
- 100k+
Invariant
- XPASSToken::l
ockAccountshould always revert if the account address isaddress(0),address(this),owner, oradminAddr. Test Result
- Passed
Run Count
- 100k+
Invariant
- XPASSToken::
unlockAccountshould always reset the locked balance to zero for the specified account. Test Result
- Passed
Run Count
- 100k+
Invariant
- XPASSToken::
changeAdminAddrshould set new admin address. Test Result
- Passed
Run Count
- 100k+
Additional Recommendations
The smart contracts in the scope of this audit could benefit from the introduction of automatic emergency actions for critical activities, such as unauthorized operations like ownership changes or proxy upgrades, as well as unexpected fund manipulations, including large withdrawals or minting events. Adding such mechanisms would enable the protocol to react automatically to unusual activity, ensuring that the contract remains secure and functions as intended.
To improve functionality, these emergency actions could be designed to trigger under specific conditions, such as:
Detecting changes to ownership or critical permissions.
Monitoring large or unexpected transactions and minting events.
Pausing operations when irregularities are identified.
These enhancements would provide an added layer of security, making the contract more robust and better equipped to handle unexpected situations while maintaining smooth operations.