Introduction
We express our gratitude to the Pikamoon team for the collaborative engagement that enabled the execution of this Smart Contract Security Assessment.
Pikamoon is a staking solution that involves several pools for staking with various types of reward tokens: PikaMoon and Uniswap liquidity tokens.
Document | |
|---|---|
| Name | Smart Contract Code Review and Security Analysis Report for Pikamoon |
| Audited By | Grzegorz Trawinski |
| Approved By | Ataberk Yavuzer |
| Website | https://www.pikamoon.io/→ |
| Changelog | 15/10/2024 - Preliminary Report |
| Platform | Ethereum |
| Language | Solidity |
| Tags | Staking |
| Methodology | https://hackenio.cc/sc_methodology→ |
Document
- Name
- Smart Contract Code Review and Security Analysis Report for Pikamoon
- Audited By
- Grzegorz Trawinski
- Approved By
- Ataberk Yavuzer
- Website
- https://www.pikamoon.io/→
- Changelog
- 15/10/2024 - Preliminary Report
- Platform
- Ethereum
- Language
- Solidity
- Tags
- Staking
- Methodology
- https://hackenio.cc/sc_methodology→
Review Scope | |
|---|---|
| Repository | https://github.com/orbit-cosmos/pikamoon-staking→ |
| Commit | 231523055a930c6f681d6797e88f85ea3d4d0d43 |
Review Scope
- Commit
- 231523055a930c6f681d6797e88f85ea3d4d0d43
Audit Summary
The system users should acknowledge all the risks summed up in the risks section of the report
Documentation quality
The documentation is provided and sufficient. The NatSpec covers the code and is sufficient.
Code quality
The code has clean architecture and it is commented.
Test coverage
Code coverage of the project is around 80% (branch coverage).
System Overview
Pikamoon is a staking protocol with the following contracts:
CorePool — a contract that manages token staking.
PikaStakingPool — is an upgradeable implementation of a staking pool for a pool token and reward token.
PoolController — manages staking pools and holds the rewards.
Stake — library responsible for the weight calculation and storing important constants related to stake period, base weight, and multipliers utilised.
Privileged roles
The owner of the
CorePool.solcontract can pause/unpause the staking contract, and set the address which is responsible for approving the users staking rewards.The owner of the
PoolController.solcontract can register a new pool, update the rate of reward token distribution per second, changes the weight of the pool.
Potential Risks
Single Points of Failure and Control: The project is fully or partially centralized, introducing single points of failure and control. This centralization can lead to vulnerabilities in decision-making and operational processes, making the system more susceptible to targeted attacks or manipulation.
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.
Administrative Key Control Risks: The digital contract architecture relies on administrative keys for critical operations. Centralized control over these keys presents a significant security risk, as compromise or misuse can lead to unauthorized actions or loss of funds.
Single Entity Upgrade Authority: The contract grants a single entity the authority to implement upgrades or changes. This centralization of power risks unilateral decisions that may not align with the community or stakeholders' interests, undermining trust and security.
Absence of Upgrade Window Constraints: The contract suite allows for immediate upgrades without a mandatory review or waiting period, increasing the risk of rapid deployment of malicious or flawed code, potentially compromising the system's integrity and user assets.
Flexibility and Risk in Contract Upgrades: The project's contracts are upgradable, allowing the administrator to update the contract logic at any time. While this provides flexibility in addressing issues and evolving the project, it also introduces risks if upgrade processes are not properly managed or secured, potentially allowing for unauthorized changes that could compromise the project's integrity and security.
Uniswap LP Tokens Lockout: The protocol aims to stake both PikaMoon and Uniswap LP tokens. Additionaklly, the protocol implemented slashing mechanism for early unstake. Whenever staked tokens are slashed the amount of toknes is transferred to the pool controller. Such obtained PikaMoon tokens can be reused as staking rewards. However, the Uniswap LP tokens are meant to be locked within the pool controller.
Findings
Code ― | Title | Status | Severity | |
|---|---|---|---|---|
| F-2024-6648 | The update of pikaPerSecond affects not-synced past rewards | accepted | Medium | |
| F-2024-6632 | Lack of compliance with EIP-712 standard | accepted | Low | |
| F-2024-6647 | The encodePacked is used for signature based authorisation | accepted | Observation | |
| F-2024-6645 | Inconsistent application of ownership renounce | accepted | Observation | |
| F-2024-6635 | The unstake can revert with unhandled error | accepted | Observation | |
| F-2024-6634 | The changePoolWeight function does not check whether pool exists | accepted | Observation | |
| F-2024-6631 | The gap state variable is redundant | 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/orbit-cosmos/pikamoon-staking→ |
| Commit | 231523055a930c6f681d6797e88f85ea3d4d0d43 |
| Whitepaper | N/A |
| Requirements | https://github.com/orbit-cosmos/pikamoon-staking/tree/main/docs→ |
| Technical Requirements | https://github.com/orbit-cosmos/pikamoon-staking/tree/main/docs→ |
Scope Details
- Commit
- 231523055a930c6f681d6797e88f85ea3d4d0d43
- Whitepaper
- N/A
- Technical Requirements
- https://github.com/orbit-cosmos/pikamoon-staking/tree/main/docs→
Assets in Scope
Appendix 3. Additional Valuables
Verification of System Invariants
During the audit of PikaMoon Staking protocol, 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, 9 invariants were tested over 10,000 runs. This thorough testing ensured that the system works correctly even with unexpected or unusual inputs.
Invariant | Test Result | Run Count |
|---|---|---|
| Pool controller allows to register any pool. | Passed | 10k |
| Pool controller allows to update rewards token rate with any amount except 0. | Passed | 10k |
| Pool controller allows to change pool weight with any value. | Passed | 10k |
| Pool controller allows to change pool weight with any value twice in a row. | Passed | 10k |
| Core pool allows to stake any amount except 0 and for any time within min and max staking time. | Passed | 10k |
| Core pool allows to stake any amount except 0 and for any time within min and max staking time for single user multiple times in time range. | Passed | 10k |
| Core pool allows to stake any amount except 0 and for any time within min and max staking time and unstake it immediately. | Passed | 10k |
| Core pool allows to stake any amount except 0 and for any time within min and max staking time and unstake after period. | Passed | 10k |
| Core pool allows to stake any amount except 0 and claim any time after random period with random claim percentage and with or without restaking. | Passed | 10k |
Invariant
- Pool controller allows to register any pool.
Test Result
- Passed
Run Count
- 10k
Invariant
- Pool controller allows to update rewards token rate with any amount except 0.
Test Result
- Passed
Run Count
- 10k
Invariant
- Pool controller allows to change pool weight with any value.
Test Result
- Passed
Run Count
- 10k
Invariant
- Pool controller allows to change pool weight with any value twice in a row.
Test Result
- Passed
Run Count
- 10k
Invariant
- Core pool allows to stake any amount except 0 and for any time within min and max staking time.
Test Result
- Passed
Run Count
- 10k
Invariant
- Core pool allows to stake any amount except 0 and for any time within min and max staking time for single user multiple times in time range.
Test Result
- Passed
Run Count
- 10k
Invariant
- Core pool allows to stake any amount except 0 and for any time within min and max staking time and unstake it immediately.
Test Result
- Passed
Run Count
- 10k
Invariant
- Core pool allows to stake any amount except 0 and for any time within min and max staking time and unstake after period.
Test Result
- Passed
Run Count
- 10k
Invariant
- Core pool allows to stake any amount except 0 and claim any time after random period with random claim percentage and with or without restaking.
Test Result
- Passed
Run Count
- 10k
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.