security audit report metapool eth.pdf

Security Audit Report for Metapool-ethereum

Date: Jul 10, 2023
Version: 1.0
Contact: contact@blocksec.com


Contents

1 Introduction
1.1 About Target Contracts
1.2 Disclaimer
1.3 Procedure of Auditing
1.3.1 Software Security
1.3.2 DeFi Security
1.3.3 NFT Security
1.3.4 Additional Recommendation
1.4 Security Model
2 Findings
2.1 Software Security
2.1.1 Denial of Service by Uninitialized System Parameters
2.2 DeFi Security
2.2.1 Lack of Check for rewardsFee
2.2.2 Denial of Service by Redundant Check
2.2.3 Stolen User’s Assets by Loss of Precision
2.2.4 Lack of Check on Duplicate Nodes
2.2.5 Incorrect Event Parameter
2.3 Additional Recommendation
2.3.1 Incorrect Annotation in updateNodesBalance()
2.3.2 Lack of Check on Address
2.3.3 Failure to Adhere to Checks-Effects-Interactions Pattern
2.4 Notes
2.4.1 Potential Centralization Problem
2.4.2 Timely Triggering of Privileged Function pushToBeacon()
2.4.3 Challenges in Achieving Real-time and Accurate Updates of Staking Rewards on Beacon Chain
2.4.4 Withdrawals might be Delayed if the Ethereum Network is Congested


Report Manifest
Item Description
Client Metapool
Target Metapool-ethereum
Version History
Version Date Description
1.0 July 10, 2023 First Version

About BlockSec

The BlockSec Team focuses on the security of the blockchain ecosystem, and collaborates with leading DeFi projects to secure their products. The team is founded by top-notch security researchers and experienced experts from both academia and industry. They have published multiple blockchain security papers in prestigious conferences, reported several zero-day attacks of DeFi applications, and released detailed analysis reports of high-impact security incidents. They can be reached at Email, Twitter and Medium.


Chapter 1 Introduction

1.1 About Target Contracts

Information Description
Type Smart Contract
Language Solidity
Approach Semi-automatic and manual verification

The repository that has been audited includes Metapool-ethereum.

The auditing process is iterative. Specifically, we will audit the commits that fix the discovered issues. If there are new issues, we will continue this process. The commit SHA values during the audit are shown in the following. Our audit report is responsible for the only initial version (i.e., Version 1), as well as new codes (in the following versions) to fix issues in the audit report.

Project Version Commit SHA
Metapool 1 c448ad22a85596e72ecea75f25cc8fa1797e077a
Metapool 2 8f4f9b179e2abe511ddffd9ab181744bff9addba

Note that, we did NOT audit all the modules in the repository. The modules covered by this audit report include Metapool-ethereum/contracts folder contract only. Specifically, the files covered in this audit include:

1.2 Disclaimer

This audit report does not constitute investment advice or a personal recommendation. It does not consider, and should not be interpreted as considering or having any bearing on, the potential economics of a token, token sale or any other product, service or other asset. Any entity should not rely on this report in any way, including for the purpose of making any decisions to buy or sell any token, product, service or other asset.

This audit report is not an endorsement of any particular project or team, and the report does not guarantee the security of any particular project. This audit does not give any warranties on discovering all security issues of the smart contracts, i.e., the evaluation result does not guarantee the nonexistence of any further findings of security issues. As one audit cannot be considered comprehensive, we always recommend proceeding with independent audits and a public bug bounty program to ensure the security of smart contracts.

The scope of this audit is limited to the code mentioned in Section 1.1. Unless explicitly specified, the security of the language itself (e.g., the Solidity language), the underlying compiling toolchain and the computing infrastructure are out of the scope.

1.3 Procedure of Auditing

We perform the audit according to the following procedure.

We show the main concrete checkpoints in the following.

1.3.1 Software Security
1.3.2 DeFi Security
1.3.3 NFT Security
1.3.4 Additional Recommendation

Note The previous checkpoints are the main ones. We may use more checkpoints during the auditing process according to the functionality of the project.

1.4 Security Model

To evaluate the risk, we follow the standards or suggestions that are widely adopted by both industry and academy, including OWASP Risk Rating Methodology and Common Weakness Enumeration. The overall severity of the risk is determined by likelihood and impact. Specifically, likelihood is used to estimate how likely a particular vulnerability can be uncovered and exploited by an attacker, while impact is used to measure the consequences of a successful exploit.

In this report, both likelihood and impact are categorized into two ratings, i.e., high and low respectively, and their combinations are shown in Table 1.1.

Table 1.1: Vulnerability Severity Classification

Impact High High Medium
Impact Low Medium Low
Impact High Low
Impact Likelihood

Accordingly, the severity measured in this report are classified into three categories: High, Medium, Low. For the sake of completeness, Undetermined is also used to cover circumstances when the risk cannot be well determined.

Furthermore, the status of a discovered item will fall into one of the following four categories:


Chapter 2 Findings

In total, we find six potential issues. Besides, we have three recommendations and four notes as follows:

ID Severity Description Category Status
1 Low Denial of Service by Uninitialized System Parameters Software Security Fixed
2 Medium Lack of Check for rewardsFee DeFi Security Fixed
3 Medium Denial of Service by Redundant Check DeFi Security Fixed
4 Low Stolen User's Assets by Loss of Precision DeFi Security Fixed
5 Low Lack of Check on Duplicate Nodes DeFi Security Fixed
6 Low Incorrect Event Parameter Software Security Fixed
7 - Incorrect Annotation in updateNodesBalance() Recommendation Fixed
8 - Lack of Check on Address Recommendation Fixed
9 - Failure to Adhere to Checks-Effects-Interactions Pattern Recommendation Fixed
10 - Potential Centralization Problem Note Confirmed
11 - Timely Triggering of Privileged Function push-ToBeacon() Note Confirmed
12 - Challenges in Achieving Real-time and Accurate Updates of Staking Rewards on Beacon Chain Note Confirmed
13 - Withdrawals might be Delayed if the Ethereum Network is Congested Note Confirmed

The details are provided in the following sections.

2.1 Software Security

2.1.1 Denial of Service by Uninitialized System Parameters

Severity Low
Status Fixed in Version 2
Introduced by Version 1
Description In the Staking contract, state variables withdrawal and liquidUnstakePool are accessed in privileged functions such as pushToBeacon() and updateNodeBalance(). However, they are not initialized in the function initialize(). The values will be 0 by default if they are not configured in the functions updateWithdrawal() and updateLiquidPool().

function updateWithdrawal(address payable _withdrawal) external onlyRole(DEFAULT_ADMIN_ROLE) {
    withdrawal = _withdrawal;
}

Impact The user can still stake their funds, but withdrawals are not allowed. Besides, the whole protocol will not work properly. Suggestion Configure the withdrawal and liquidUnstakePool properly in the function initialize().

2.2 DeFi Security

2.2.1 Lack of Check for rewardsFee

Severity Medium
Status Fixed in in Version 2
Introduced by Version 1
Description In the function updateNodesBalance() of the contract Staking, if nodesTotalBalance increases, a certain proportion of mpETH, calculated based on rewardsFee, will be charged and sent to the treasury. This rewardsFee can be changed by the privileged role DEFAULT_ADMIN_ROLE via the function updateRewardsFee(). However, there is no check to limit the maximum value of this system parameter.

function updateRewardsFee(uint16 _rewardsFee) public onlyRole(DEFAULT_ADMIN_ROLE) {
    rewardsFee = _rewardsFee;
}

Impact The user may get no farming rewards earned from the Beacon Chain if the rewardsFee is 100%. Suggestion Add a check to ensure the rewardsFee can never exceed a reasonable maximum value in the function updateRewardsFee().

2.2.2 Denial of Service by Redundant Check

Severity Medium
Status Fixed in Version 2
Introduced by Version 1
Description In the function getEthForValidator() of the contract LiquidUnstakePool, there is a check assert(previousTotalAssets == totalAssets()).

If there is a precision loss during the Staking(STAKING).depositETH process, the checks in the assert statement will not pass, resulting in a revert.

function getEthForValidator(uint _amount) external nonReentrant onlyStaking {
   currentETHPercentage = (ethBalance * 10000) / totalAssets();  
   newEthPercentage = ((ethBalance-_amount) * 10000) / totalAssets();
   assert(previousTotalAssets == totalAssets());
}

Impact Once loss of precision occurred during Staking(STAKING).depositETH, the function getEthForValidator() will revert. Suggestion Remove redundant checks.

2.2.3 Stolen User’s Assets by Loss of Precision

Severity Low
Status Fixed in Version 2
Introduced by Version 1
Description Ethers with rewards. The function redeem() allows the liquidity provider of the LiquidUnstakePool to redeem their Ethers, however, if the variable _shares is too small, the poolPercentage may be rounded down to 0 due to the precision loss.

function redeem(uint _shares, address _receiver, address _owner) public virtual override nonReentrant returns (uint ETHToSend) {
   uint poolPercentage = (_shares * 1 ether) / totalSupply();
}

Impact When the variable _shares is too small, the user’s shares are burnt without receiving anything. Suggestion Add a check to ensure that poolPercentage is greater than 0.

2.2.4 Lack of Check on Duplicate Nodes

Severity Low
Status Fixed in Version 2
Introduced by Version 1
Description In Ethereum staking, depositing more than 32 Ethers to a single set of keys does not increase rewards potential, nor does accumulating rewards above 32 Ethers. However, the function pushBeacon() lacks a check to ensure if the node hasn’t been deposited before.

function pushToBeacon(Node[] memory _nodes, uint256 _requestPoolAmount, uint256 _requestWithdrawalAmount) external onlyOperational onlyRole(ACTIVATOR_ROLE) {
   // Add checks for nodes
}

Impact If deposit Ethers are deposited to duplicate nodes, the staking rewards will be less as expected. Suggestion Add checks to prevent depositing Ethers to duplicate nodes.

2.2.5 Incorrect Event Parameter

Severity Low
Status Fixed in Version 2
Introduced by Version 2
Description In the function withdraw() of the contract LiquidUnstakePool, the parameter within the RemoveLiquidity event is incorrect. Based on the given event definition, the first event parameter should be the _owner instead of the msg.sender.

emit RemoveLiquidity(msg.sender, shares, ETHToSend, mpETHToSend);

Impact Misconfigured event parameters can potentially lead to confusion and misinformation. Suggestion Change emit RemoveLiquidity(msg.sender,..) to emit RemoveLiquidity(_owner,..).

2.3 Additional Recommendation

2.3.1 Incorrect Annotation in updateNodesBalance()

Status Fixed in Version 2
Introduced by Version 1
Description The annotation in the function updateNodesBalance() of the contract Staking is incorrect.

//@notice Updates nodes total balance

Suggestion Revise the incorrect annotation.

2.3.2 Lack of Check on Address

Status Fixed in Version 2
Introduced by Version 1
Description Lack of zero address check before updating address variables in multiple places.

function initialize(...) {
    require(_weth != address(0), "Invalid address");
}

Suggestion Add zero address check before updating address variable.

2.3.3 Failure to Adhere to Checks-Effects-Interactions Pattern

Status Fixed in Version 2
Introduced by Version 1
Description In the function redeem(), the operation of sending Ether to the _receiver occurs before the update of the ethBalance, which breaks the Checks-Effects-Interactions pattern.

payable(_receiver).sendValue(ETHToSend);
ethBalance -= ETHToSend;

Suggestion Send Ether to the _receiver after the ethBalance has been updated.


2.4 Notes

2.4.1 Potential Centralization Problem

Status Confirmed
Introduced by version 1
Description This project has potential centralization problems. The privileged role DEFAULT_ADMIN_ROLE can change the contract address of liquidUnstakePool and withdrawal at any time. Meanwhile, the privileged role ACTIVATOR_ROLE is able to call depositContract.deposit() to activate specified validators. We suggest these roles should be in multi-signature.

Feedback from the Project The admin (i.e., DEFAULT_ADMIN_ROLE) will be managed by a multisig.

2.4.2 Timely Triggering of Privileged Function pushToBeacon()

Status Confirmed
Introduced by version 1
Description The function pushToBeacon() allows the privileged role ACTIVATOR_ROLE to timely deposit the staked funds into the Beacon Chain for earning. This function should be triggered timely. Otherwise, the rewards will be less as expected.

Feedback from the Project The call is automated and monitored. Timely execution is of utmost interest to the protocol.

2.4.3 Challenges in Achieving Real-time and Accurate Updates of Staking Rewards on Beacon Chain

Status Confirmed
Introduced by version 1
Description The update of staking rewards earned from the Beacon Chain is not real-time, and has a 4-hour delay, which requires the UPDATER_ROLE to invoke the function updateNodesBalance() for the update.

Feedback from the Project It is not viable to update staking rewards earned from the Beacon Chain “real-time” thus rewards for users are estimated by the second.

2.4.4 Withdrawals might be Delayed if the Ethereum Network is Congested

Status Confirmed
Introduced by version 1
Description Users are allowed to withdraw their staked Ethers in the contract Withdrawal. Withdrawals might encounter delays during periods of Ethereum network congestion.