Introduction
We express our gratitude to the Credbull team for the collaborative engagement that enabled the execution of this Smart Contract Security Assessment.
Credbull is an ERC-4626 vault system.
Document | |
|---|---|
| Name | Smart Contract Code Review and Security Analysis Report for Credbull |
| Audited By | Olesia Bilenka, Andy Cho |
| Approved By | Ataberk Yavuzer |
| Website | https://credbull.io/→ |
| Changelog | 26/07/2024 - Preliminary Report |
| 15/08/2024 - Final Report | |
| Platform | Arbitrum |
| Language | Solidity |
| Tags | Vault; Yield Farming |
| Methodology | https://hackenio.cc/sc_methodology→ |
Document
- Name
- Smart Contract Code Review and Security Analysis Report for Credbull
- Audited By
- Olesia Bilenka, Andy Cho
- Approved By
- Ataberk Yavuzer
- Website
- https://credbull.io/→
- Changelog
- 26/07/2024 - Preliminary Report
- 15/08/2024 - Final Report
- Platform
- Arbitrum
- Language
- Solidity
- Tags
- Vault; Yield Farming
- Methodology
- https://hackenio.cc/sc_methodology→
Review Scope | |
|---|---|
| Repository | https://github.com/credbull/credbull-defi/→ |
| Commit | f927c85 |
| Remediation commit | ce1c17e |
Review Scope
- Commit
- f927c85
- Remediation commit
- ce1c17e
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.
NatSpec comments are provided.
Code quality
The code mostly follows best practices and styleguides.
The development environment is configured.
Test coverage
Code coverage of the project is 90% (branch coverage).
Deployment and basic user interactions are covered with tests.
System Overview
Credbull is an ERC-4626 vault system with the following contracts:
Vault \- is an abstract smart contract based on OpenZeppelin's ERC4626, designed to manage ERC20 token deposits with enhanced security. Deposited assets are transferred to a designated CUSTODIAN address, with the contract maintaining records of total assets deposited. The contract includes functions for depositing, minting, withdrawing, and redeeming assets, with built-in error handling for invalid operations. Additionally, it features access control mechanisms and the ability to pause operations for security purposes.
MaturityVault \- is an abstract contract extends the Vault by adding a maturity feature, preventing further deposits once matured. It tracks whether the vault is matured and includes functions to mature the vault and check maturity status. This ensures that only existing assets and any accrued yield are managed after maturity.
FixedYieldVault \- is a contract that extends the MaturityVault and integrates additional features from WhiteListPlugin, WindowPlugin, and MaxCapPlugin. It allows deposits and redemptions based on set windows and caps, and it offers a fixed yield to users. The contract includes mechanisms for maturity checking and whitelisting, ensuring that only approved addresses can interact with it. The FixedYieldVault also has functionality to pause operations and to withdraw any ERC20 tokens held by the contract.
UpsideVault \- is a contract that extends the functionality of the FixedYieldVault by integrating collateral management using the Credbull token (CBL). Users must deposit collateral in CBL tokens alongside their main assets, with the required collateral amount determined by a specified percentage of the asset value and the current TWAP (Time-Weighted Average Price). The contract allows for both deposits and withdrawals while ensuring the proper handling and accounting of the collateral. Additionally, the contract has a mechanism to update the TWAP value, which is crucial for calculating the collateral requirements.
VaultFactory \- is a factory designed to manage the creation and oversight of vault contracts. It maintains sets of allowed custodians and created vaults, allowing only authorized custodians to interact with the factory. The contract allows administrators to add or remove custodians and provides functions to query the list of created vaults and validate custodians.
WhiteListProvider - is a contract that manages a whitelist of addresses that can be used by other contracts to determine if addresses are authorized. It allows the owner to update the whitelist status of multiple addresses at once. The contract tracks whitelist status through a mapping and provides a function to check if an address is whitelisted.
MaxCapPlugin - is a contract that provides functionality to enforce a maximum cap on asset deposits in a vault. It tracks the maximum allowed cap through the maxCap variable and uses a boolean flag, checkMaxCap, to enable or disable the cap enforcement. The contract provides internal functions to check if the deposited amount exceeds the cap, update the cap value, and toggle the cap check status.
WhiteListPlugin - is a contract that manages white-listing functionality within a vault system. It enforces that certain addresses must be white-listed to perform operations, such as deposits, if their transaction amount meets or exceeds a specified threshold (depositThresholdForWhiteListing). The white-list status is determined through an external IWhiteListProvider contract. The plugin includes internal functions for checking white-list status and toggling the white-list check.
WindowPlugin - is a contract that contract manages deposit and redemption time windows for a vault. It defines time periods during which deposits and redemptions are permitted, using timestamps for opening and closing these windows. The plugin includes functions to check whether operations fall within these time windows, update window timestamps, and toggle the window check functionality.
CredbullFixedYieldVault - is a straightforward implementation of the FixedYieldVault contract. It serves as a specific instance of FixedYieldVault with no additional functionality or modifications.
CredbullFixedYieldVaultFactory - is a contract that extends the VaultFactory and is designed to facilitate the creation of CredbullFixedYieldVault instances. It provides functionality for deploying new vaults and managing the list of allowed custodians and vault addresses.
CredbullFixedYieldVaultWithUpside - is a contract that extends the UpsideVault and is tailored to integrate additional upside functionality into the fixed yield vault. It leverages the existing features of UpsideVault, which itself extends FixedYieldVault, to provide enhanced capabilities for handling collateral and deposit-redemption windows.
CredbullUpsideVaultFactory - is a contract that extends VaultFactory to create instances of CredbullFixedYieldVaultWithUpside. This factory contract provides functionality for deploying new vaults that integrate both fixed yield and upside features.
CredbullWhiteListProvider - is an implementation that extends the WhiteListProvider contract. It inherits the functionality for managing a whitelist of addresses from WhiteListProvider, including updating whitelist statuses and querying the whitelist status of an address.
Privileged roles
The
DEFAULT_ADMIN_ROLEin theVaultcontract has the authority to pause and unpause contract operations, impacting the ability of users to deposit or withdraw assets. They can also set the custodian address and modify parameters related to asset management, such as asset decimals and share token settings.The
DEFAULT_ADMIN_ROLEin theMaturityVaultcontract has the authority to toggle the maturity check, initiate the vault's maturation process, and manage other critical parameters, affecting the vault's operational status and asset management.The
DEFAULT_ADMIN_ROLEin theFixedYieldVaultcontract has significant control, including the ability to toggle checks for maturity, whitelisting, window periods, and max cap, as well as to update the max cap value and window timestamps. TheOPERATOR_ROLEcan initiate the vault's maturation process and setting the TWAP value (UpsideVaultcontract). These roles hold significant power over the contract's functionality and the management of user assets.The
DEFAULT_ADMIN_ROLEin theVaultFactorycontract has broad control, including adding or removing custodian addresses and managing factory-wide settings. TheOPERATOR_ROLEdoes not have direct access to this contract's functions but is important in related contexts where vaults are created and managed.The owner is of the
WhiteListProvidercontract is authorized to update the whitelist status of addresses and make changes to the whitelist.OPERATOR_ROLErole can create newCredbullFixedYieldVaultinstances. It must be a valid custodian to create a vault
Risks
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.
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.
Findings
Code ― | Title | Status | Severity | |
|---|---|---|---|---|
| F-2024-4404 | Centralization Risk in Vault System Leading to Deposit Lock | mitigated | Medium | |
| F-2024-4396 | Risk of Ownership Control Loss in Owner-Dependent Contracts | fixed | Low | |
| F-2024-4419 | Violation of Checks-Effects-Interactions Pattern | accepted | Observation | |
| F-2024-4416 | Missing Validation for collateralPercentage and twap in UpsideVault Contract | fixed | Observation | |
| F-2024-4414 | Missing Zero Addresses Validations Leading to Misconfiguration | fixed | Observation | |
| F-2024-4403 | State Variables That Should Be Immutable | fixed | Observation | |
| F-2024-4400 | Lack of Configuration Events | fixed | Observation | |
| F-2024-4399 | Redundant Fallback and Receive Functionality | fixed | Observation | |
| F-2024-4398 | Missing Validation for Time Windows in WindowPlugin Contract | fixed | Observation | |
| F-2024-4397 | Floating Pragma | accepted | 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/credbull/credbull-defi/→ |
| Commit | f927c850b628a63dd71e5c6a1e8888e89a6262e5 |
| Remediation commit | ce1c17ea94494d985c516f0ac3be379cb2fef8e3 |
| Whitepaper | Credbull High Level Architecture (SHA256: 13117d79fe1da3f456fad5b0c0d24c956bb8552b1e9c40b97c2d90c6f50cf4f6) |
| https://docs.credbull.io/docs/litepaper→ |
Scope Details
- Commit
- f927c850b628a63dd71e5c6a1e8888e89a6262e5
- Remediation commit
- ce1c17ea94494d985c516f0ac3be379cb2fef8e3
- Whitepaper
- Credbull High Level Architecture (SHA256: 13117d79fe1da3f456fad5b0c0d24c956bb8552b1e9c40b97c2d90c6f50cf4f6)