Summon
Staker

Summon's staker is a permissionless staking contract that takes native tokens, ERC-20, ERC-721 and ERC-1155 deposits. We reviewed the full contract and found only two best-practice items.
report id
0338
category
DeFi & Yield
language
Solidity
final report
October 25, 2024
lines of code
324
Content

Download audit report

1

Executive Summary

This document outlines the security review conducted by Nethermind Security for the Summon staker contract. The audit covers a permissionless staking protocol that allows deposits for native, ERC20, ERC721, and ERC1155 tokens.

The audited code comprises 324 lines of code written in the Solidity language. The Summon team has provided comprehensive documentation, including design documents and inline comments to explain the protocol’s behavior. Additionally, the Nethermind and Summon teams have communicated to clarify all other questions regarding protocol design.

The audit was performed using (a) manual analysis of the codebase, (b) automated analysis tools, and (c) simulation of the smart contract. Along with this document, we report 2 points classified as best practices.

Audit assessment
Audit TypeSecurity Review
Initial ReportOctober 21, 2024
Final ReportOctober 25, 2024
MethodsManual Review, Automated analysis
RepositoryG7DAO/protocol/web3/contracts/staking/Staker.sol
Commit Hashbef2650f8e
Final Commit Hashhttps://github.com/G7DAO/protocol/pull/150/files
Documentation AssessmentHigh
Test Suite AssessmentHigh
Total findings
2
Fixed
1
Acknowledged
1
Mitigated
0
Unresolved
0

Findings by severity

  • Critical0
  • High0
  • Medium0
  • Low0
  • Informational0
  • Best Practices2

2

Audited Files

#ContractLoCCommentsRatioBlankTotal
1Staker.sol32413842.6%78540
Total32413842.6%78540

4

System Overview

The Summon protocol implements the Staker contract, which is a permissionless staking contract where any user can create a staking pool to be used by others. The staking contract supports deposits of native, ERC20, ERC721, and ERC1155 assets. Any user can create a staking pool and set configuration values for the token lock durations, asset type, and position transferability. Once a pool has been created any user is able to deposit into this pool. Each stake position is represented as an ERC721 asset which may be transferred, depending on the pool transferability options set by the pool creator. Pool creators are able to change the configuration after it has been created, and ownership of a pool can be transferred to the zero address to prevent future config changes. Asset lock duration is broken down into two sections; lockup and cooldown. When a stake begins, the lockup period starts to count down. Once the lockup time has passed, then the user must initiate an unstake, where the cooldown period will begin. Once the cooldown period has passed the user can finish the unstake process and receive their assets.

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 Pool administrators can lock tokens using cooldown and lockup durations

FileFix commitTypeStatus
web3/contracts/staking/Staker.sol—Best PracticesAcknowledged

Every pool has an administrator who can modify some aspects of the pool through the function updatePoolConfiguration(...). Specifically, the administrator can change the transferability, lockupSeconds, and cooldownSeconds. For the lockup and cooldown durations, there are no upper limits on how long a user must wait, meaning it is possible for an administrator to effectively lock user tokens by setting the duration to an extremely long duration. The code with audit comments is reproduced below.

function updatePoolConfiguration(...) external {
StakingPool storage pool = Pools[poolID];

...

///////////////////////////////////////////////////////////////////////////
// @audit: missing input validation for lockupSeconds
///////////////////////////////////////////////////////////////////////////
if (changeLockup) {
pool.lockupSeconds = lockupSeconds;
}

///////////////////////////////////////////////////////////////////////////
// @audit: missing input validation for cooldownSeconds
///////////////////////////////////////////////////////////////////////////
if (changeCooldown) {
pool.cooldownSeconds = cooldownSeconds;
}
emit StakingPoolConfigured(
poolID,
pool.administrator,
pool.transferable,
pool.lockupSeconds,
pool.cooldownSeconds
);
}

The values of lockupSeconds and cooldownSeconds are also set during the pool’s creation without any validation, as reproduced below.

function createPool(..., uint256 lockupSeconds, uint256 cooldownSeconds, address administrator) external {

...

///////////////////////////////////////////////////////////////////////////
// @audit: missing input validation for cooldownSeconds and lockupSeconds
///////////////////////////////////////////////////////////////////////////
Pools[TotalPools] = StakingPool({
administrator: administrator,
tokenType: tokenType,
tokenAddress: tokenAddress,
tokenID: tokenID,
transferable: transferable,
lockupSeconds: lockupSeconds,
cooldownSeconds: cooldownSeconds
});

...
}

Also, if the cooldownSeconds is set to a value such that when added with a position’s stake timestamp, it exceeds 2ˆ256-1, then it is possible to overflow when calling initiateUnstake, making it impossible to unstake tokens. The function is reproduced below.

function initiateUnstake(uint256 positionTokenID) external nonReentrant {
...

///////////////////////////////////////////////////////////////////////////
// @audit: in case of overflow, the transaction reverts.
// Unstake will be impossible.
///////////////////////////////////////////////////////////////////////////
if (block.timestamp < position.stakeTimestamp + pool.lockupSeconds) {
revert LockupNotExpired(position.stakeTimestamp + pool.lockupSeconds);
}

...
}

Recommendation

Consider adding input validation when setting the lockupSeconds and cooldownSeconds to prevent these values from being unreasonably high. This validation should be added to both the constructor and updatePoolConfigurations.

Resolution

We don’t think this is a protocol-level concern. Applications which use the ‘Staker‘ may want different types of protections on these values. For example, we are planning to have game contracts which default to max lockup but modify it atomically for players based on game state.

6.2 Staking functions do not follow the Checks-Effects-Interactions pattern

FileFix commitTypeStatus
web3/contracts/staking/Staker.solPR #150Best PracticesFixed

The stake functions in the Staker contract interact with external contracts without following the Checks-Effects-Interactions (CEI) pattern. The Checks-Effects-Interactions Pattern organizes function logic into three steps: a) Checks (validate initial conditions and prerequisites); b) Effects (update the contract’s state; c) Interactions (make external calls or transfer ETH).

This pattern mitigates the risk of reentrancy attacks by ensuring that state changes occur before any external interactions. Even if a malicious contract calls back into your function, the state has already been updated, preventing unintended behavior.

The functions that require changes are listed below.

  • stakeERC20(...);
  • stakeERC721(...);
  • stakeERC1155(...);
  • stakeNative(...);

Those functions use the nonReentrant modifier. This modifier prevents a function from being called recursively. It locks the function during its execution to avoid reentrancy by ensuring that the same function cannot be entered again before the current execution completes. However, this only protects against direct reentrancy from the same contract, and it doesn’t address all security risks related to external interactions.

The Checks-Effects-Interactions pattern helps prevent (a) state inconsistencies in case of failures during external calls and (b) hard-to-trace intermediate states in more complex logic.

Recommendation

Move the external interactions to the last line of the function.

Resolution

Fixed in https://github.com/G7DAO/protocol/pull/150/files.

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 client has provided documentation about their protocol through their github documentation, which includes the execution flow of the Staker contract. Additionally, the client was available to address any questions or concerns from the Nethermind Security team.

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.