Canary
Staking Vaults

Covered Canary's two staking vault contracts under active development.
report id
0326
category
DeFi & Yield
language
Solidity
final report
February 4, 2025
lines of code
601
Content

Download audit report

1

Executive Summary

This document presents the security review performed by Nethermind Security for the Canary staking vault contracts, which are designed to function as a restaking aggregator. The Canary team has developed two distinct vault contracts. The first vault manages ERC20 tokens, allowing administrators to deposit these assets into the Symbiotic protocol. The second vault focuses on managing ERC721 tokens.

This security review focused on the current version of the protocol, which is still under development. Notably, some features, such as the integration with Symbiotic, remain incomplete. Therefore, a follow-up audit is recommended once the protocol is fully developed and additional functionalities are introduced.

The audit was performed using (a) manual analysis of the codebase, (b) automated analysis tools, (c) simulation of the smart contract, and (d) creation of test cases.

Audit assessment
Audit TypeSecurity Review
Initial ReportOct 17, 2024
Final ReportFeb 04, 2025
Repositorycontracts
Commit (Audit)696df5b544
Commit (Final)a49e98aae1
Documentation AssessmentMedium
Test Suite AssessmentMedium
Total findings
4
Fixed
4
Acknowledged
0
Mitigated
0
Unresolved
0

Findings by severity

  • Critical0
  • High1
  • Medium0
  • Low0
  • Informational1
  • Best Practices2

2

Audited Files

#ContractLoCCommentsRatioBlankTotal
1CanaryNFT.sol8144.9%15100
2clToken.sol18316.7%627
3Vault.sol210136.2%36259
4VaultManager.sol10066.0%18124
5TokenFactory.sol441431.8%1674
6NFTVault.sol60915.0%1988
7NFTVaultManager.sol5359.4%1876
8NFTFactory.sol35720.0%951
Total6016110.1%137799

4

System Overview

Canary has implemented two types of vault contracts responsible for managing ERC20 and ERC721 assets. The primary function of the ERC20 vault is to act as a restaking aggregator, connecting with various restaking options, such as Symbiotic.

The reviewed contracts have been categorized into three main components: factories and management contracts, receipt tokens, and vaults, which will be detailed in the following sections.

4.1 Factories and Management Contracts

The NFTFactory and TokenFactory contracts serve as factory contracts responsible for creating receipt tokens. Each receipt token is deployed via these factories as a proxy. The factory handles the proper initialization of these tokens and transfers the ownership of the proxy admin to the designated external owner.

The VaultManager and NFTVaultManager contracts operate similarly to the factories but are responsible for the complete initialization of vaults. Initially, they deploy all receipt tokens through the respective factories and subsequently deploy the vault itself, which is initialized by the manager. The vault is created as a proxy to enable upgradability. Furthermore, the MINTER role is assigned to the vault for all receipt tokens, ensuring that only the vault can mint these tokens.

4.2 Receipt Tokens

Receipt tokens come in two variants based on the ERC standard: CanaryNFT, which is minted as a receipt for deposited NFTs in the NFTVault, and clToken, which is minted upon depositing ERC20 assets into the Vault contract.

Each receipt token has a designated withdrawal period, functioning as a notice period before withdrawing the underlying asset from the vault. Each Vault manages three distinct clToken types, each associated with different withdrawal periods: 7 days, 30 days, and 90 days. The NFTVault, however, issues only a single type of CanaryNFT with a 7-day withdrawal period.

All receipt tokens are also pausable, allowing the protocol to halt the transfer of these tokens if needed.

4.3 Vaults

The vaults are categorized into two types: the Vault contract, responsible for managing ERC20 assets, and the NFTVault for handling ERC721 assets. Each vault is designed to manage only one underlying token.

The vault architecture is consistent across both types. Users can deposit the underlying assets via the stake(...) function. For the NFTVault, users specify the tokenId, and in return, they receive a receipt token corresponding to the same tokenId. In the case of the Vault, users specify the amount of ERC20 tokens they wish to deposit along with the index of the clToken they want to receive as receive.

 
// NFTVault.sol function:
function stake(uint256 tokenId) external;

// Vault.sol function:
function stake(uint256 underlyingAmount, uint256 index) external;

When a user decides to withdraw their underlying asset, they must call the requestWithdraw(...) function, which initiates a withdrawal request and burns the user's receipt token. Once the withdrawal period associated with the receipt token has elapsed, the user can finalize the process by calling the claimWithdraw(...) function to retrieve their asset.

 
// NFTVault.sol functions:
function requestWithdraw(uint256 tokenId) external;

function claimWithdraw(uint256 tokenId) external;

// Vault.sol functions:
function requestWithdraw(uint256 amount, uint256 index) external;

function claimWithdraw(uint256 index) external;

The Vault contract is designed to function as a restaking aggregator, meaning it has the capability to interact with restaking protocols. To facilitate this, the vault introduces two functions that allow administrators with the SYMBIOTIC_ROLE to deposit and withdraw assets from the Symbiotic vault.

 
function depositIntoSymbiotic(uint256 amount) public onlyRole(SYMBIOTIC_ROLE)

function withdrawFromSymbiotic(uint256 amount) public onlyRole(SYMBIOTIC_ROLE)

5

Risk Rating Methodology

The risk rating methodology used by Nethermind Security follows the principles established by the OWASP Foundation. The severity of each finding is determined by two factors: Likelihood and Impact.

Likelihood measures how likely the finding is to be uncovered and exploited by an attacker. This factor will be one of the following values:

  1. High: the issue is trivial to exploit and has no specific conditions that need to be met;
  2. Medium: the issue is moderately complex and may have some conditions that need to be met;
  3. Low: the issue is very complex and requires very specific conditions to be met.

When defining the likelihood of a finding, other factors are also considered. These can include but are not limited to motive, opportunity, exploit accessibility, ease of discovery, and ease of exploit.

Impact is a measure of the damage that may be caused if an attacker exploits the finding. This factor will be one of the following values:

  1. High: the issue can cause significant damage, such as loss of funds or the protocol entering an unrecoverable state;
  2. Medium: the issue can cause moderate damage, such as impacts that only affect a small group of users or only a particular part of the protocol;
  3. Low: the issue can cause little to no damage, such as bugs that are easily recoverable or cause unexpected interactions that cause minor inconveniences.

When defining the impact of a finding, other factors are also considered. These can include but are not limited to data and state integrity, loss of availability, financial loss, and reputation damage. After defining the likelihood and impact of an issue, the severity is determined according to the table below.

Impact / LikelihoodLowMediumHigh
HighMediumHighCritical
MediumLowMediumHigh
LowInfo / Best PracticesLowMedium
UndeterminedUndeterminedUndeterminedUndetermined

To address issues that do not fit a High, Medium or Low severity, Nethermind Security also uses three more finding severities: Informational, Best Practices, and Undetermined.

  1. Informational findings do not pose any risk to the application, but they carry some information that the audit team intends to pass to the client formally;
  2. Best Practice findings are used when some piece of code does not conform with smart contract development best practices;
  3. Undetermined findings are used when we cannot predict the impact or likelihood of the issue.

6

Issues

6.1 Incorrect assignment of access control roles in Vault and NFTVault contracts

FileFix commitTypeStatus
Vault.sol
NFTVault.sol
a49e98aHighFixed

The Vault and NFTVault contracts inherit from AccessControlEnumerableUpgradeable, which implements a role-based access control model. Critical roles, including DEFAULT_ADMIN_ROLE for both contracts and SYMBIOTIC_ROLE in the Vault contract, are assigned during the initialize(...) function. These roles are automatically granted to the msg.sender.

However, because the vaults are instantiated and initialized by a manager contract, the msg.sender at the time of the initialize(...) call is the manager contract itself. As a result, the privileged roles are inadvertently assigned to the manager contract, rather than an external account. This misconfiguration prevents privileged accounts from accessing or using certain privileged functions (e.g., depositIntoSymbiotic(...)).

Recommendation

Ensure that privileged roles are correctly assigned to external accounts.

6.2 Unnecessary safeApprove(...) call in withdrawFromSymbiotic(...) function

FileFix commitTypeStatus
Vault.sola49e98aInfoFixed

In the withdrawFromSymbiotic(...) function, the Vault withdraws its underlying assets from the Symbiotic vault. The current implementation includes safeApprove(...) call before invoking the withdraw(...) function:

function withdrawFromSymbiotic(uint256 amount) public onlyRole(SYMBIOTIC_ROLE) {
// ...
// Approve symbioticVault to spend the vault's shares
symbioticVault_.safeApprove(address(symbioticVault_), amount); // @audit can be deleted

symbioticVault_.withdraw(address(this), amount);
// ...
}

The withdraw(...) function in the Symbiotic vault contract (Default Collateral Contract) does not require approval. It burns the user's shares directly via its internal _burn(...) function, making the safeApprove(...) call redundant.

Recommendation

Remove the unnecessary safeApprove(...) call to avoid redundant operations.

6.3 Ensure the correct number of clTokens in the Vault contract

FileFix commitTypeStatus
Vault.sola49e98aBest PracticesFixed

The Vault contracts are designed to maintain exactly three clTokens with different withdrawal periods: 7 days, 30 days, and 90 days. However, the current check in the initialize(...) function only verifies that at least one token is provided:

if (_clTokens.length == 0) {
revert AtLeastOneCLTokenAddressMustBeProvided();
}

This check does not enforce the intended requirement of having exactly three tokens.

Recommendation

Update the check in the initialize(...) function to ensure that exactly three clTokens are provided during initialization.

6.4 Integrate setWithdrawPeriod(...) functionality into initialize(...) function

FileFix commitTypeStatus
CanaryNFT.sol
clToken.sol
a49e98aBest PracticesFixed

The setWithdrawPeriod(...) function is designed to set the withdrawPeriod during the deployment process, and it is called only once in factory contracts. Since this value is only set once, it would be more efficient to handle the assignment directly within the initialize(...) function.

In its current design, the setWithdrawPeriod(...) function can still be called on the implementation contract. While this doesn’t introduce a security risk, it creates conflicts with the intent of the _disableInitializers() function, which is meant to prevent initialization.

Recommendation

Consider removing the setWithdrawPeriod(...) function and incorporating the assignment of the withdrawPeriod within the initialize(...) function.

7

Documentation Evaluation

Software documentation refers to the written or visual information that describes the functionality, architecture, design, and implementation of software. It provides a comprehensive overview of the software system and helps users, developers, and stakeholders understand how the software works, how to use it, and how to maintain it. Software documentation can take different forms, such as user manuals, system manuals, technical specifications, requirements documents, design documents, and code comments. Software documentation is critical in software development, enabling effective communication between developers, testers, users, and other stakeholders. It helps to ensure that everyone involved in the development process has a shared understanding of the software system and its functionality. Moreover, software documentation can improve software maintenance by providing a clear and complete understanding of the software system, making it easier for developers to maintain, modify, and update the software over time. Smart contracts can use various types of software documentation. Some of the most common types include:

  • Technical whitepaper: A technical whitepaper is a comprehensive document describing the smart contract’s design and technical details. It includes information about the purpose of the contract, its architecture, its components, and how they interact with each other;
  • User manual: A user manual is a document that provides information about how to use the smart contract. It includes step-by-step instructions on how to perform various tasks and explains the different features and functionalities of the contract;
  • Code documentation: Code documentation is a document that provides details about the code of the smart contract. It includes information about the functions, variables, and classes used in the code, as well as explanations of how they work;
  • API documentation: API documentation is a document that provides information about the API (Application Programming Interface) of the smart contract. It includes details about the methods, parameters, and responses that can be used to interact with the contract;
  • Testing documentation: Testing documentation is a document that provides information about how the smart contract was tested. It includes details about the test cases that were used, the results of the tests, and any issues that were identified during testing;
  • Audit documentation: Audit documentation includes reports, notes, and other materials related to the security audit of the smart contract. This type of documentation is critical in ensuring that the smart contract is secure and free from vulnerabilities.

These types of documentation are essential for smart contract development and maintenance. They help ensure that the contract is properly designed, implemented, and tested, and they provide a reference for developers who need to modify or maintain the contract in the future.

8

Remarks & Test Suite

The Canary contracts lack comprehensive documentation and NatSpec comments in some parts of the code, which made certain sections challenging to understand. However, the Canary team effectively addressed the concerns and questions raised by the Nethermind Security team during regular calls.

Remarks about Canary test suite

The Canary team has developed a testing suite that covers the basic flows of the protocol, including deposits, withdrawals, and various privileged actions. However, the protocol should always ensure that user impersonation is properly handled in the tests, as incorrect implementation of these tests led to a severe issue within the protocol.

Test suite
48Tests passed0Failed

The complete test output is in the full report.

As auditors, we recommend that any changes or updates made to the audited codebase undergo a re-audit or security review to address potential vulnerabilities or risks introduced by the modifications. By conducting a re-audit or security review of the modified codebase, you can significantly enhance the overall security of your system and reduce the likelihood of exploitation. However, we do not possess the authority or right to impose obligations or restrictions on our clients regarding codebase updates, modifications, or subsequent audits. Accordingly, the decision to seek a re-audit or security review lies solely with you.

This report is based on the scope of materials and documentation provided by you to Nethermind in order that Nethermind could conduct the security review outlined in 1. Executive Summary and 2. Audited Files. The results set out in this report may not be complete nor inclusive of all vulnerabilities. Nethermind has provided the review and this report on an as-is, where-is, and as-available basis. You agree that your access and/or use, including but not limited to any associated services, products, protocols, platforms, content, and materials, will be at your sole risk. Blockchain technology remains under development and is subject to unknown risks and flaws. The review does not extend to the compiler layer, or any other areas beyond the programming language, or other programming aspects that could present security risks. This report does not indicate the endorsement of any particular project or team, nor guarantee its security. No third party should rely on this report in any way, including for the purpose of making any decisions to buy or sell a product, service or any other asset. To the fullest extent permitted by law, Nethermind disclaims any liability in connection with this report, its content, and any related services and products and your use thereof, including, without limitation, the implied warranties of merchantability, fitness for a particular purpose, and non-infringement. Nethermind does not warrant, endorse, guarantee, or assume responsibility for any product or service advertised or offered by a third party through the product, any open source or third-party software, code, libraries, materials, or information linked to, called by, referenced by or accessible through the report, its content, and the related services and products, any hyperlinked websites, any websites or mobile applications appearing on any advertising, and Nethermind will not be a party to or in any way be responsible for monitoring any transaction between you and any third-party providers of products or services. As with the purchase or use of a product or service through any medium or in any environment, you should use your best judgment and exercise caution where appropriate. FOR AVOIDANCE OF DOUBT, THE REPORT, ITS CONTENT, ACCESS, AND/OR USAGE THEREOF, INCLUDING ANY ASSOCIATED SERVICES OR MATERIALS, SHALL NOT BE CONSIDERED OR RELIED UPON AS ANY FORM OF FINANCIAL, INVESTMENT, TAX, LEGAL, REGULATORY, OR OTHER ADVICE.