Pocket Network
xPOKT Bridge

Pocket Network is moving to xPOKT, a token that can be bridged across EVM chains through Wormhole. We reviewed the token, the lockbox that converts wPOKT, the Wormhole adapter and the one-step bridging router.
report id
0245
category
Cross-chain & Bridges
language
Solidity
final report
June 12, 2024
lines of code
738
Content

Download audit report

1

Executive Summary

This document outlines the security review conducted by Nethermind Security for the Pocket Network contracts. The review focuses on the new xPOKT token and its bridging mechanism. The xPOKT token is a cross-chain token designed to become the native Pocket Network token and will be deployed on different EVM chains. It inherits from the xERC20 token contract and implements a mint limiting and pausing functionalities.

Currently, users hold wPOKT token on Ethereum network. To seamlessly transition to xPOKT, they should interact with the XERC20Lockbox contract, where they lock their wPOKT tokens and mint an equivalent amount of xPOKT tokens. Subsequently, xPOKT holders can bridge their assets to any supported EVM chain by initiating a bridge operation through the WormholeBridgeAdapter contract.

Moreover, holders of wPOKT tokens can leverage the wPOKTRouter to bridge their assets to another chain directly. This process involves implicitly locking the wPOKT tokens in the lockbox and invoking the bridge(...) function on the WormholeBridgeAdapter contract, thereby reducing the number of transactions required to complete the bridging operation.

The audited code comprises 738 lines of code in Solidity. The Pocket Network team has provided documentation that explains the purpose and functionality behind audited contracts.

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

Audit assessment
Audit TypeSecurity Review
Initial ReportJun 12, 2024
Final ReportJun 12, 2024
MethodsManual Review, Automated analysis
Repositorypocket-contracts
Commit Hash932d3f7da9
Final Commit Hashbe8d7ef84b
DocumentationHackMD
Documentation AssessmentMedium
Test Suite AssessmentMedium
Total findings
4
Fixed
4
Acknowledged
0
Mitigated
0
Unresolved
0

Findings by severity

  • Critical0
  • High0
  • Medium2
  • Low0
  • Informational2
  • Best Practices0

2

Audited Files

#ContractLoCCommentsRatioBlankTotal
1governance/WormholeTrustedSender.sol833947.0%23145
2xPOKT/xPOKT.sol1448961.8%39272
3xPOKT/WPOKTRouter.sol583458.6%22114
4xPOKT/WormholeBridgeAdapter.sol1259475.2%37256
5xPOKT/ConfigurablePauseGuardian.sol483572.9%19102
6xPOKT/ConfigurablePause.sol2628107.7%1266
7xPOKT/MintLimits.sol1226452.5%33219
8xPOKT/xERC20BridgeAdapter.sol513874.5%15104
9xPOKT/XERC20Lockbox.sol362261.1%1674
10xPOKT/xERC20.sol4546102.2%19110
Total73848966.3%2351462

4

System Overview

Pocket Network introduced the xPOKT token, a native cross-chain token that will be deployed across different EVM chains. Currently, liquidity on the Ethereum mainnet resides on the wPOKT token. Holders of wPOKT can transition to xPOKT via the XERC20Lockbox contract and then utilize the WormholeBridgeAdapter contract to bridge xPOKT to other EVM chains. Alternatively, wPOKT holders can directly leverage the WPOKTRouter for this purpose. Figure 1 shows a general overview of user flows within the system.

The following sections detail each component within the system including the xPOKT token, the XERC20Lockbox contract as well as the different flows to bridge the xPOKT token into other EVM chains.

4.1 xPOKT token

The xPOKT token is an upgradeable cross-chain token that aligns with the xERC20 standard, designed as the native Pocket Network token that will be deployed across different EVM chains.

The token contract incorporates rate-limiting features inherited from the xERC20 contract. This functionality allows for a controlled issuance of tokens over time by limiting the number of tokens held by each actor. Each minter is assigned a limited buffer, which is dynamically depleted or replenished with each minting or burning operation.

Moreover, the token integrates pause functionalities inherited from the ConfigurablePauseGuardian contract. When the token is paused, both mint and burn operations are stopped, and therefore, the token cannot be bridged.

A designated pause guardian holds the authority to halt or resume mint and burn operations via the pause() and unpause() functions:

function pause() public virtual whenNotPaused
function unpause() external whenPaused

When the contract is paused through the pause() function, the current timestamp is stored in the pauseStartTime state variable. If this pause lasts longer than a defined threshold MAX_PAUSE_DURATION, currently set to 30 days, the contract will automatically resume its operations as demonstrated in the implementation of the paused() function.

function paused() public view virtual override returns (bool) {
return pauseStartTime == 0 ? false : block.timestamp <= pauseStartTime + pauseDuration;
}

Additionally, if the guardian fails to unpause the contract within this time window, anyone can invoke the kickGuardian() function to remove the guardian and resets the pausing state.

function kickGuardian() public whenNotPaused

4.2 WPOKT LockBox

Current wPOKT holders can migrate to the new xPOKT token through the XERC20Lockbox contract, exclusively deployed on the Ethereum mainnet. This contract facilitates the locking of wPOKT tokens, simultaneously minting equivalent xPOKT tokens that can be bridged later on.

Users can deposit wPOKT tokens using the deposit(...) or depositTo(...) functions, subsequently receiving the equivalent xPOKT tokens. The minted tokens are either sent to the caller or the specified address to in the depositTo(...) case.

function deposit(uint256 amount) external
function depositTo(address to, uint256 amount) external

Conversely, withdrawals are possible via the withdraw(...) and withdrawTo(...) functions. It entails burning xPOKT tokens and unlocking the corresponding wPOKT tokens, which is set back to the user.

function withdraw(uint256 amount) external
function withdrawTo(address to, uint256 amount) external

4.3 Bridging Mechanism

Bridging the xPOKT token into other chains is realized directly via the WormholeBridgeAdapter for xPOKT holders or by going through the wPOKTRouter for wPOKT holders.

4.3.1 Bridging xPOKT via WormholeBridgeAdapter

The WormholeBridgeAdapter contract serves as the interface with the Wormhole relayer, facilitating the bridging of xPOKT tokens across supported EVM chains. This contract is deployed on every chain with the same address.

The main entry point of the contract is the bridge(...) function:

function bridge(uint256 dstChainId, uint256 amount, address to) external payable virtual

This function enables users to bridge a specific amount of their xPOKT tokens to another chain by covering associated fees. The fees include a message fee for the Wormhole actor processing the message and gas fees for delivering the message. In case of message delivery failure, the message fee is refunded if the refundAddress is specified when calling sendPayloadToEvm(...).

To determine fees to be attached to the bridge(...) call, users can utilize the bridgeCost(...) function, which provides an estimation of the bridging costs for a specific destination chain dstChainId.

function bridgeCost(uint16 dstChainId) public view returns (uint256 gasCost)

Bridging the tokens via the bridge(...) function involves the following actions:

  • The specified amount of xPOKT tokens is burned in the source chain.
  • The sendPayloadToEvm(...) function is invoked in WormholeRelayer contract. This function sends a message to the Wormhole system, including details about the destination chain, target contract, payload data, bridging fees, and the gas limit.
  • Subsequently, on the recipient chain, the Wormhole relayer initiates the receiveWormholeMessages(...) function within the WormholeBridgeAdapter. This results in the minting of xPOKT tokens for the specified receiver.

Note that the contract manages a list of trusted senders, where every WormholeBridgeAdapter contract is whitelisted, ensuring that the invocation of the receiveWormholeMessages(...) function is restricted solely to trusted senders.

4.3.2 Bridging xPOKT via wPOKTRouter

The wPOKTRouter contract serves as a utility for wPOKT holders, enabling them to directly bridge their tokens into xPOKT on a different EVM chain. This mechanism reduces the number of transactions required for the bridging process for wPOKT holders.

The main entry point in the contract is the bridgeTo(...) function:

function bridgeTo(uint16 chainId, address to, uint256 amount) external payable

The function implementation includes the following steps:

  • User transfers the specified amount of wPOKT into the contract.
  • These transferred tokens are then locked within the Lockbox contract through the deposit(...) function, consequently minting an equivalent amount of xPOKT tokens for the router.
  • Subsequently, the bridge(...) function on the xERC20BridgeAdapter is invoked. This action results in the burning of tokens on the current EVM chain and the subsequent minting of equivalent tokens on the target chain (chainId) for the specified recipient (to).

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 Refund address is not specified

FileFix commitTypeStatus
WormholeBridgeAdapter45d5841MediumFixed

The WormholeBridgeAdapter contract utilizes the Wormhole protocol to bridge tokens between different EVM chains. When users want to bridge tokens from chain A to chain B, they need to call the bridge(...) function, which internally triggers the _bridgeOut(...) function.

function _bridgeOut(...) internal override {
// ...
wormholeRelayer.sendPayloadToEvm{value: cost}(
targetChainId,
targetAddress[targetChainId],
// payload
abi.encode(to, amount),
/// no receiver value allowed, only message passing
0,
gasLimit
// @audit missing refund address and refund chain
);
// ...
}

This internal function initiates a message to the Wormhole relayer by calling sendPayloadToEvm(...). The relayer processes the message and publishes it within Wormhole’s infrastructure. The message is then delivered to the target address on the target chain by executing receiveWormholeMessages(....). During the bridging process, the user must pay a message fee and gas, which are consumed during the receiveWormholeMessages(...) execution.

In the current implementation of this bridge contract, the execution of receiveWormholeMessages(...) can fail due to two issues:

1. The specified gas limit is too low (depending on the chain where the message is bridged); 2. RateLimiting functionality is triggered when the bridge mints an excessive number of tokens;

In instances of receiveWormholeMessages(...) execution failure, all paid fees associated with bridging the message, including any remaining gas, are sent to a refund address. However, since the refund address is not specified in this case, the fees will be sent to the Wormhole delivery contract and will not be returned to Pocket Network users.

Recommendation

To avoid losing paid fees and remaining gas after the execution of receiveWormholeMessages(...), specify the refundAddress and refundChain arguments during the execution of sendPayloadToEVM(...).

Resolution

Implemented according the recommendation: 45d5841ea9cc6925aa7cbd6bd2c57ddc7a7fa7d9

6.2 The ownerUnpause() function does not unpause the contract

FileFix commitTypeStatus
xPOKT.sola32f7d6MediumFixed

The xPOKT contract incorporates a pausing mechanism by inheriting from the ConfigurablePausableGuardian contract. This mechanism allows designated guardians to pause the contract for a specific period, after which it automatically unpauses. The pauseStartTime variable is reset upon unpausing to restore the pausing capability. This reset can occur through several actions: unpausing the contract via a guardian, removing the guardian entirely, or the contract owner appointing a new guardian.

If the contract is paused, the owner can unpause it by invoking ownerUnpause(). However, this function is currently misimplemented, as it calls the _unpause() internal method inherited from PausableUpgradable contract of OpenZeppelin (OZ). This method resets the paused state variable but does not impact the pauseStartTime.

Recommendation

To address the issue, replace the call to _unpause() inside ownerUnpause() with _resetPauseState() internal function. This will ensure proper resetting of the pauseStartTime variable and removing the current guardian.

Resolution

Implemented according the recommendation: a32f7d6c543ca3d22cd2a7c3000ff67365d61553

6.3 Allowing excessive funds in _bridgeTo(...) function is unnecessary

FileFix commitTypeStatus
WPOKTRouter.sol8fc47d5InfoFixed

The _bridgeTo(...) function facilitates the bridging of xPOKT tokens to a target chain. Upon invocation, users are expected to provide a value equal to or greater than the bridging cost (bridgeCostFee). However, only the bridging cost is forwarded to the Wormhole bridge. The excess value is always sent back to the user.

function _bridgeTo(uint16 chainId, address to, uint256 amount) private {
uint256 bridgeCostFee = wormholeBridge.bridgeCost(chainId);
//@audit User can send a value higher than needed (bridgeCostFee)
require(
bridgeCostFee <= msg.value,
"WPOKTRouter: insufficient fee sent"
);

// ...
// @audit Only `bridgeCostFee` is sent to the wormhole bridge
wormholeBridge.bridge{value: bridgeCostFee}(chainId, xpoktAmount, to);

// @audit Excess funds are sent back to the user
if (address(this).balance != 0) {
(bool success, ) = msg.sender.call{value: address(this).balance}("");
require(success, "WPOKTRouter: failed to refund excess fee");
}
// ...
}

Allowing a higher msg.value than the actual cost is unnecessary and leads to increased gas consumption due to the need to refund the user.

Recommendation

Consider modifying the condition checking msg.value to enforce strict equality with the bridge cost.

Resolution

Implemented according the recommendation: 8fc47d5b978f1c424db94e340b822d44a927762f

6.4 Amount of gas can differ on various chains

FileFix commitTypeStatus
WormholeBridgeAdapterbe8d7efInfoFixed

Token bridging from chain A to chain B through the Wormhole protocol must include the payment of fees, which are calculated using quoteEVMDeliveryPrice(...). This function returns the amount of ETH required for fees based on the target chain for delivery of the message and the estimated gas limit for the execution of receiveWormholeMessages(...).

(gasCost, ) = wormholeRelayer.quoteEVMDeliveryPrice(dstChainId, 0, gasLimit);

The gasLimit is a state variable that can be modified by the contract owner, with a default value of 300_000. However, not all chains calculate gas costs similarly to the Ethereum mainnet; thus, the required gas may vary across different chains.

_Note: For example, on Arbitrum, the gas amount is calculated using the following equation:_ Gas Limit (G) = Gas used on L2 (L2G) +

Extra Buffer for L1 cost (B)

If the gas amount is insufficient for the execution of receiveWormholeMessages(...), the Wormhole message will need to be resent with a higher gas amount. Furthermore, due to the current usage of sendPayloadToEvm(...), any remaining gas will be sent to the Wormhole delivery contract and not returned to the user.

Recommendation

Implement different gas limits for each chain to ensure sufficient gas is allocated for the execution of

receiveWormholeMessages(...).

Resolution

Added an option for overriding default gas limit (300_000) with a custom gas limit.

be8d7ef84b551d544b9b5e14c1a5cbae989152ff

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 Pocket Network team has provided documentation about their protocol based on the following HackMD. Additionally, the Pocket Network team was available to address any questions or concerns from the Nethermind Security team.

Remarks about Pocket Network test suite

The Pocket Network team has developed a comprehensive test suite encompassing various user workflows and integration scenarios with the Wormhole protocol. This rigorous testing has contributed to a well-written and secure codebase. However, the integration tests only utilized Wormhole mock contracts, which limited the testing of real integration behavior and the completeness of Wormhole message delivery failures.

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