We express our gratitude to the CratD2C team for the collaborative engagement that enabled the execution of this Smart Contract Security Assessment.
CratD2C is a blockchain platform utilizing Delegated Proof of Stake (DPoS) and Layer-1 architecture to enhance security, speed, and scalability. Its ecosystem supports e-commerce, real estate, and luxury services through decentralized applications and a universal payment gateway.
Document
Review Scope
The system users should acknowledge all the risks summed up in the risks section of the report
Functional requirements are complete.
Technical description is detailed.
The development environment is configured.
Code coverage of the project is 99.18% (branch coverage).
Deployment and basic user interactions are covered with tests.
Not every negative cases coverage are covered.
The CRATVesting
contract is a token vesting contract designed to distribute a predefined supply of tokens over a set period. It allows administrators to start the distribution to various recipients (allocators) with predefined schedules for each, outlining how and when tokens are unlocked. The contract uses a time-based vesting schedule that spans from 2024 to 2038, releasing tokens incrementally to the allocators. Administrators can claim unlocked tokens for the recipients, ensuring a controlled release according to the vesting rules.
The CRATStakeManager
contract is responsible for managing staking, slashing, and reward distribution among validators and their delegators. It includes functionalities for depositing funds as a validator or delegator, distributing rewards, and slashing validators when necessary. Validators and delegators can claim or restake rewards, withdraw deposits.
The CRATVesting
contract uses the AccessControl
library from OpenZeppelin to restrict access to some functions. The only role defined in the contract is DEFAULT_ADMIN_ROLE
, addresses with the role can:
Partially claim available tokens.
Claim all available tokens.
The CRATVesting
contract uses the AccessControlUpgradeable
library from OpenZeppelin to restrict access to some functions. The roles defined in this contract are: DEFAULT_ADMIN_ROLE
, DISTRIBUTOR_ROLE
and SWAP_ROLE
.
Addresses with the DEFAULT_ADMIN_ROLE
can:
Change slash receiver address.
Change validators limit.
Change validators and delegators withdrawal cooldown.
Change validators and delegators minimum amount to deposit.
Change validators token amount to slash.
Change delegators percentage to slash.
Change validators and delegators fixed APR.
Change validators and delegators claim cooldown.
Withdraw excess reward tokens from the contract.
Addresses with the DISTRIBUTOR_ROLE
can:
Distribute rewards to validators.
Slash validators.
Addresses with the SWAP_ROLE
can:
Make deposit for exact user as validator.
Dynamic Array Iteration Gas Limit Risks: The project iterates over large dynamic arrays, which leads to excessive gas costs, risking denial of service due to out-of-gas errors, directly impacting contract usability and reliability.
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.
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.
Penalizing Slashing Mechanism: If a validator gets slashed twice in 90 days, all of his fixed APR reward accumulated from the last shashing is withdrawn from his deposit amount as a penalty. The 90 days threshold is variable and can be adjusted by the team.
Code ― | Title | Status | Severity | |
---|---|---|---|---|
F-2024-7875 | [DualDefense] Potential Denial of Service in Validator Withdrawals | Fixed | High | |
F-2024-6642 | Potential Denial of Service in slash Function Due to High Gas Consumption | Fixed | Medium | |
F-2024-6643 | Potential Funds Lock Due to Insufficient Fixed Rewards Balance | Fixed | Low | |
F-2024-6656 | Missing _disableInitializers() in Upgradable Contract Constructor | Fixed | Observation | |
F-2024-6653 | Unoptimized Storage Access | Fixed | Observation | |
F-2024-6650 | Missing Events For Key Actions | Fixed | Observation | |
F-2024-6648 | Gas Inefficiency Due to Missing Usage of Solidity Custom Errors | Fixed | Observation | |
F-2024-6644 | Missing Validator Parameter in DelegatorWithdrawed Event | Fixed | Observation | |
F-2024-6641 | Redundant Code in Conditional Branches Reduces Readability | Fixed | Observation | |
F-2024-6638 | Lack of Upper Bound on Cooldown Values for Claim and Withdraw Actions | Fixed | Observation |
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
Severity
Description
Severity
Description
Severity
Description
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.
The scope of the project includes the following smart contracts from the provided repository:
Scope Details
CRATStakeManager.sol
CRATVesting.sol
During the audit of CratStakeManager, Hacken followed its methodology by performing fuzz-testing on the project's main functions. Medusa → 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 60,000,000 runs. This thorough testing ensured that the system works correctly even with unexpected or unusual inputs.
Invariant
Test Result
Run Count
Invariant
Test Result
Run Count
Invariant
Test Result
Run Count
Invariant
Test Result
Run Count
Invariant
Test Result
Run Count
Invariant
Test Result
Run Count
Invariant
Test Result
Run Count
Invariant
Test Result
Run Count
Invariant
Test Result
Run Count
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.