ClayStack
EigenLayer Restaking

ClayStack lets users stake ETH and receive csETH. This review covered its EigenLayer integration, which lets validators restake native ETH through an EigenPod and claim withdrawals from it.
report id
0179
category
DeFi & Yield
language
Solidity
final report
January 25, 2024
lines of code
1002
Content

Download audit report

1

Executive Summary

This document presents the security review conducted by Nethermind for the ClayStack ETH Staking Contracts. ClayStack is a platform that enables ETH staking on the Ethereum blockchain. It allows users to participate in the staking process by delegating their stake to validators on the Ethereum Beacon chain. This staking process involves users locking up their ETH in exchange for a token called csETH. This csETH token represents their staked amount and is minted on the Ethereum network. The validator pool on ClayStack is managed by the platform, and those who operate and manage the validators are rewarded for their efforts. These operators can either be direct nodes or operators using a DVT based approach. In the audited version of ClayStack, validators are trusted/controlled entities that are not likely to be malicious.

This assessment focuses on the recent update to the ClayStack protocol that implements integration with the EigenLayer protocol, enabling the restaking of native ETH. Notably, registered validators can designate a withdrawal address pointing to the EigenPod contract linked with ClayStack’s NodeManager. The contract has been modified to incorporate new functions that enable the withdrawal and claiming processes directly from the EigenPod. Additionally, when oracles report the exit of a validator associated with the EigenPod, a claiming process is initiated to claim expired withdrawal requests. The claimed amount is then reflected in the validator’s balance. The node is considered exited only if all withdrawal requests have been claimed. Otherwise, it will be subtracted from the total number of exited nodes.

The audit was performed using: (a) manual analysis of the codebase, (b) automated analysis tools, and (c) simulation of the smart contracts.

Audit assessment
Audit TypeSecurity Review
Initial ReportJan 25, 2024
Final ReportJan 25, 2024
MethodsManual Review, Automated Analysis
Repositoryclaystack-ethereum
Commit Hash0de890799f
Commit Hash184f9a9e8c
DocumentationDocs
Documentation AssessmentHigh
Test Suite AssessmentHigh
Total findings
2
Fixed
1
Acknowledged
1
Mitigated
0
Unresolved
0

Findings by severity

  • Critical1
  • High0
  • Medium0
  • Low0
  • Informational1
  • Best Practices0

2

Audited Files

#ContractLoCCommentsRatioBlankTotal
1src/ClayMain.sol57117029.8%148889
2src/NodeManager.sol43115235.3%111694
Total100232232.1%2591583

4

System Overview

No system overview is included in this report.

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 Claiming withdrawals on EigenLayer can be done without updating internal accounting

FileFix commitTypeStatus
NodeManager.sol184f9a9CriticalFixed

The claimEigenLayer(...) function shown below is claiming withdrawals within EigenLayer and updating the accounting in eigenLayerWithdraws variable.

function claimEigenLayer(uint256 maxNumberOfWithdrawalsToClaim) public {
uint256 balanceBefore = address(this).balance;
// @audit call to EigenLayer to claim withdrawals
eigenDelayedWithdrawalRouter.claimDelayedWithdrawals(maxNumberOfWithdrawalsToClaim);
uint256 balanceAfter = address(this).balance;
if (balanceAfter > balanceBefore) {
uint256 claimedAmount = balanceAfter - balanceBefore;
// @audit update of the internal accounting
eigenLayerWithdraws -= claimedAmount;
emit LogClaimEigenLayer(claimedAmount);
}
}

However, anyone can bypass this function and execute the claim directly on EigenLayer side, by calling the claimDelayedWithdrawals(. . . ) function. This function allows the caller to claim withdrawals on behalf of a specified recipient, with the recipient address provided as an input. If the NodeManager contract address is utilized as the recipient, the claim is made on its behalf.

Consequently, the eigenLayerWithdraws variable won’t be updated, resulting in wrong accounting within the contract. Despite funds being claimed and nodes considered exited, they are still accounted for in the active validators’ balance, resulting in higher rewards.

Recommendation

Consider modifying the way the contract handles claims in EigenLayer, by moving the accounting for claimed amounts to the receive function, and filtering the funds received from the eigenDelayedWithdrawalRouter contract only.

Resolution

updated with commit: 184f9a9e8c90d19021640340a485edb8e4b68b48

6.2 Updating Eigen Layer addresses could result in erroneous accounting

FileFix commitTypeStatus
NodeManager.sol—InfoAcknowledged

The setEigenLayer(...) function allows updating EigenLayer related addresses. This update carries a risk of affecting the balances accounting within NodeManager contract. That is possible because, after the update, the contract loses access to the queue of pending and completed withdrawals of the current validators, in addition to the current balance of the EigenPod.

Recommendation

Before updating EigenLayer addresses in the contract, consider reviewing the status of validators and withdrawal claims in the previous router contract. Confirm that all withdrawals have been successfully claimed and all nodes are exited.

Resolution

-

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 ClayStack contracts’ documentation is presented through inline comments within the code, providing explanations for the objectives and operations of various functions and formulas. Additionally, the README file, accessible at this link, outlines the deposit and withdrawal processes and delineates different roles within the system. Furthermore, the ClayStack team remained available to address any inquiries or concerns raised by the Nethermind auditors.

7.1 Contracts Compilation

7.3 Code Coverage

The relevant output is presented below.

Test suite
281Tests 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.