Download audit report
This document outlines the security review conducted by Nethermind Security for Summon. The Summon system allows gamifying the participation and commitment of users towards a community, using playful reward mechanisms in the form of tokens to obtain the engagement of its members. The system supports various token standards for representing user rewards, including ERC-20, ERC-721, and ERC-1155, and it can also utilize ETH. This code review focuses on the LootDrop.sol contract, which contains the logic for the main system functions related to managing rewards for users utilizing ERC-1155 tokens.
Note about the audit
It is important to mention that the audit was conducted within a tight time constraint of 3 days to meet a launch plan. Therefore, the protocol should consider an after-deployment audit for additional audit coverage of the codebase.
The audited code comprises 409 lines of code in Solidity. The Summon’s team provided a detailed description of the functionality of LootDrop contract, with supporting diagrams of interaction flows. The audit was performed using: (a) manual analysis of the codebase, (b) simulation of the smart contracts.
| Audit assessment | |
| Audit Type | Security Review |
| Initial Report | Apr 12, 2024 |
| Final Report | Apr 16, 2024 |
| Methods | Manual Review |
| Repository | achievo-contracts |
| Commit Hash | 44fcac0406 |
| Final Commit Hash | 5ab2e61397 |
| Documentation | Comments in the codebase and diagrams |
| Documentation Assessment | Low |
| Test Suite Assessment | Medium |
Findings by severity
| # | Contract | LoC | Comments | Ratio | Blank | Total |
| 1 | LootDrop.sol | 409 | 39 | 9.5% | 79 | 527 |
| Total | 409 | 39 | 9.5% | 79 | 527 |
| # | Finding | Severity | Update |
| 1 | Distribution of rewards could revert for ERC721 | High | Fixed |
| 2 | Possible signature replay attack across different chains | High | Fixed |
| 3 | Lack of ERC20 transfer safety checks in LootDrop contract | Medium | Fixed |
| 4 | User could claim rewards even if contract is paused | Medium | Fixed |
| 5 | Centralization risks | Low | Unresolved |
| 6 | itemIds can be duplicated in createTokenAndDepositRewards(...) | Low | Fixed |
| 7 | ERC1155 with token ID zero can’t be added as a reward | Info | Fixed |
| 8 | Missing input validations | Best Practices | Fixed |
| 9 | Perform input parameter validation before modifying the contract state | Best Practices | Fixed |
| 10 | Unused Code | Best Practices | Fixed |
The Summon protocol introduces the LootDrop contract, enabling users to earn rewards in various forms, such as ERC20 tokens, ERC721, ERC1155 items, and Ether, based on predefined allocations. The Manager role-based account is authorized to create these token rewards, and users with reward tokens can claim them by invoking the mint function with a pre-approved whitelist signer signature. Rewards can also be airdropped to users through Minter and Manager role-based accounts.
The system distinguishes between 5 main roles:
Manager Role: It is an account with elevated privileges that can perform the below administrative tasks on the protocol:
Minter Role: It is an account with elevated privileges that can perform the below administrative tasks on the protocol:
Whitelist Signer: The whitelist signer account is authorized to sign the whitelist signature so that users can claim reward tokens.
Dev Config Role: It is an account with elevated privileges that can perform the below administrative tasks on the protocol:
Users: These are the wallet accounts of the users that can call the below functions:
The general flow of this contract is divided into several steps. First, a manager needs to create a reward token with a specific ID through createTokenAndDepositRewards(...) function. A reward token is linked to rewards such as Ether, ERC20, ERC721 or ERC1155 tokens. As a second step, a minter needs to mint a reward token to a user, or a whitelisted signer has to generate a signature which will include the user’s address, reward token ID and nonce—allowing users to mint their reward token through mint(...) function. Finally, a user can claim their reward by calling claimReward(...) function, which will distribute all rewards connected with the reward token.
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:
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:
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 / Likelihood | Low | Medium | High |
| High | Medium | High | Critical |
| Medium | Low | Medium | High |
| Low | Info / Best Practices | Low | Medium |
| Undetermined | Undetermined | Undetermined | Undetermined |
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.
| File | Fix commit | Type | Status |
LootDrop.sol | 1c93d95 | High | Fixed |
The function _distributeReward(...) distributes various rewards to a user. Rewards are divided into native Ether, ERC20, ERC721 and ERC1155 tokens.
When the ERC721 reward type is used as part of a user’s reward, it has to contain several variables. The most important is the rewardTokenIds array, which specifies all IDs of NFTs that will be distributed to users, and the rewardAmount variable, which holds the number of NFTs per reward. To track the already distributed tokens, the LootDrop contract contains the erc721RewardCurrentIndex mapping, which holds the current index of the rewardTokenIds array for the distribution.
The following code snippet contains a distribution of the ERC721 reward:
// ...
} else if (reward.rewardType == LibItems.RewardType.ERC721) {
uint256 currentIndex = erc721RewardCurrentIndex[_rewardTokenId][i];
uint256[] memory tokenIds = reward.rewardTokenIds;
for (uint256 j = 0; j < reward.rewardAmount; j++) {
if (currentIndex >= tokenIds.length) {
revert InsufficientBalance();
}
// @audit The currentIndex is not being updated
_transferERC721(IERC721(reward.rewardTokenAddress), _from, _to, tokenIds[currentIndex]);
erc721RewardCurrentIndex[_rewardTokenId][i]++;
}
}
// ...In the provided code, the currentIndex variable contains the value stored inside the erc721RewardCurrentIndex mapping for the current token that should be sent to the user. This variable is then used inside a loop, which iterates based on the number of tokens that should be distributed as a reward. However, the currentIndex variable is not updated during the loop’s iterations, which causes a revert in the second iteration. As a result, the whole distribution of a reward will revert.
Recommendation
Consider updating the currentIndex variable inside the loop.
Resolution
Fixed 1c93d95114b9edcb8681c74bcb8627eb7a4956db
| File | Fix commit | Type | Status |
LootDrop.sol | e8f407e | High | Fixed |
The mint(...) function allows users to mint a reward token or claim a reward directly. To call this function, the user must provide a signature created by a whitelisted signer, e.g., the protocol owner.
A signature and other user inputs are checked inside the _verifySignature(...) function, which is inherited from the ERCWhitelistSignature.sol contract.
function _verifySignature(
address to,
uint256 nonce,
bytes calldata data,
bytes calldata signature
) internal virtual returns (bool) {
if (usedSignatures[signature]) revert("AlreadyUsedSignature");
address signer = _recoverAddress(to, nonce, data, signature);
// ...
}The parameters utilized in signature validation include the recipient’s address (to), a unique nonce distinguishing between various signatures, and a data field containing the list of authorized reward token IDs.
The _verifySignature(...) function effectively mitigates signature reuse by maintaining a mapping of utilized signatures, incorporating the nonce passed as a parameter. It mitigates potential signature replay attacks within the same contract instance. However, the user might still use the same signature across different instances of this contract in different EVM blockchains.
Since the intention is to implement the protocol across various blockchains, it becomes paramount to incorporate metadata within the signature to prevent this type of attack between contract instances across distinct blockchains. This can be achieved by including identifiers specific to the underlying blockchain, such as the chain ID, within the signature.
A missing chain identifier inside a signature allows an attacker to claim or mint his rewards n-times, depending on the number of EVM chains.
Recommendation
Consider using a chain-specific signing scheme such as EIP-155, which includes the chain ID in the signed message.
Resolution
Fixed e8f407ee4c998ba2174b92683a93bc687f0a3d8c
| File | Fix commit | Type | Status |
LootDrop.sol | 1c93d95 | Medium | Fixed |
The LootDrop contract incorporates ERC20 tokens as rewards. The manager account approves the contract to transfer the required tokens when creating a token reward by invoking the createTokenAndDepositRewards(...) or createMultipleTokensAndDepositRewards(...) functions, which internally call the _createTokenAndDepositRewards(...) function. This function transfers the tokens to the contract. Similarly, when a user claims a reward, the _transferERC20(...) function is internally called to transfer the tokens to the user.
The problem with the current implementation is that it does not handle tokens that don’t comply with the ERC20 standard, e.g., tokens that don’t revert on failure. In case of a silent failure of the transfer function, the reward claimers may be unable to receive their rewards.
// @audit called to claim user's rewards
function _transferERC20(IERC20 _token, address _to, uint256 _amount) private {
// ...
_token.transfer(_to, _amount);
}
// @audit called to deposit rewards
function _createTokenAndDepositRewards(...) private {
//...
if (reward.rewardType == LibItems.RewardType.ERC20) {
IERC20 token = IERC20(reward.rewardTokenAddress);
token.transferFrom(_from, _to, reward.rewardAmount);
}
// ...
}Recommendation
Utilize OpenZeppelin’s SafeERC20 versions with the safeTransfer(...) and safeTransferFrom(...) functions that handle the edge cases when dealing with non-ERC20 compliant tokens.
Resolution
Fixed 1c93d95114b9edcb8681c74bcb8627eb7a4956db
| File | Fix commit | Type | Status |
LootDrop.sol | 1c93d95 | Medium | Fixed |
The LootDrop contract has a standard Openzeppelin library Pause mechanism. However, this mechanism isn’t implemented in the functions for claiming rewards, leading to an eventual unauthorized claim of rewards when the contract is in a paused state.
// @audit The whenNotPaused modifier is missing
function claimReward(uint256 _tokenId) external nonReentrant {
// ...
}
function claimRewards(uint256[] calldata _tokenIds) external nonReentrant {
// ...
}Recommendation
Consider adding the whenNotPaused modifiers to the claim reward functions.
Resolution
Fixed 1c93d95114b9edcb8681c74bcb8627eb7a4956db
| File | Fix commit | Type | Status |
LootDrop.sol | 1c93d95 | Low | Unresolved |
In the LootDrop contract, a single account has the authority to perform several critical operations. The _devWallet address is assigned all privileged roles: DEFAULT_ADMIN_ROLE, DEV_CONFIG_ROLE, MINTER_ROLE, MANAGER_ROLE. This address is also registered as a whitelisted signer.
Having one account performing all the critical operations introduces a significant security risk if access to this account is lost or compromised. If an attacker gains control of the _devWallet address, the contract’s assets could be drained through the withdrawAssets(...) function.
Recommendation
To minimize security risks connected with centralization, consider distributing authority roles among different accounts and implementing multi-signature authorization for these accounts.
Resolution
Fixed 1c93d95114b9edcb8681c74bcb8627eb7a4956db
Update from Nethermind Security
Even though privileges were divided for multiple addresses, the centralization risks persist due to the protocol’s design. We suggest implementing multi-signature wallets to minimize these risks.
itemIds can be duplicated in createTokenAndDepositRewards(...)| File | Fix commit | Type | Status |
LootDrop.sol | 1c93d95 | Low | Fixed |
The _createTokenAndDepositRewards(...) function does not check if the token ID was already set, as presented in the function snippet below:
function _createTokenAndDepositRewards(LibItems.RewardToken calldata _token) private {
_validateTokenInputs(_token);
// @audit There is no check if the token ID was already set.
tokenRewards[_token.tokenId] = _token;
tokenExists[_token.tokenId] = true;
itemIds.push(_token.tokenId);
LibItems.TokenCreate memory tokenCreate = LibItems.TokenCreate(_token.tokenId, _token.tokenUri);
rewardTokenContract.addNewToken(_token.tokenId);
// ...
}This allows for calling that function with the same token ID multiple times, in effect overriding the reward in the tokenRewards mapping and pushing duplicates of the same ID to the itemIds array. Moreover, the itemIds inside AdminERC1155Soulbound.sol could also contain multiple IDs due to invoking the addNewToken(...) function.
Recommendation
Consider checking if the token ID was already set to mitigate rewards overwriting and storing ID duplicates.
Resolution
Fixed 1c93d95114b9edcb8681c74bcb8627eb7a4956db
| File | Fix commit | Type | Status |
LootDrop.sol | 1c93d95 | Info | Fixed |
LootDrop allows users to earn rewards in various forms, including ERC20 tokens, ERC721, ERC1155 items, and Ether, based on predefined allocations. A manager account sets these allocations through the createTokenAndDepositRewards(...) or createMultipleTokensAndDepositRewards(...) functions, which creates the token rewards and deposits them accordingly. These functions rely on _validateTokenInputs(...) to ensure the input parameters provided by the manager are valid.
The _validateTokenInputs(...) validates different reward properties based on their type. For example, for the ERC1155 token, specifying a token ID zero is forbidden.
function _validateTokenInputs(LibItems.RewardToken calldata _token) private pure {
// ...
if (reward.rewardType == LibItems.RewardType.ERC1155) {
// @audit ERC1155 tokens might start with token ID 0
if (reward.rewardTokenId == 0) {
revert InvalidTokenId();
}
}
// ...
}However, the ERC1155 standard allows a token ID to be set to zero. Therefore, LootDrop unnecessarily forbids some ERC1155 collections from being distributed as a reward.
Recommendation
Consider allowing a ERC1155 reward with token ID zero.
Resolution
Fixed, I just removed the check since there is no need here 1c93d95114b9edcb8681c74bcb8627eb7a4956db
| File | Fix commit | Type | Status |
LootDrop.sol | 1c93d95 | Best Practices | Fixed |
Several parts of the code do not implement proper input validation checks. To mitigate human errors, it is considered a best practice to perform input validation to ensure that the contract is always in a proper state.
withdrawAssets(...) and adminBatchMintById(...) functions, the arrays received as parameters are iterated using the same index. Thus, if these arrays possess differing lengths, it may result in an out-of-bounds access. To prevent transactions from reverting, consider implementing checks to ensure that the arrays are not empty and have the same lengths. The checks are especially important when dealing with ERC1155;LootDrop contract’s constructor(...) does not perform the address(0) check on the _devWallet. A similar check is already present in the initialize(...) function;address(0) check on the address parameter in the minting functions, e.g., mint(...), adminMint(...), adminMintById(...), and adminBatchMintById(...). Given that all these functions invoke the internal function _mintAndClaimRewardToken(...), consider adding the validation within this function;Recommendation
Consider validating the inputs according to the above recommendations.
Resolution
Fixed 1c93d95114b9edcb8681c74bcb8627eb7a4956db
| File | Fix commit | Type | Status |
LootDrop.sol | 1c93d95 | Best Practices | Fixed |
In some functions, input validation checks are performed after a gas-expensive operation such as writing to storage. This may result in an unnecessary gas expense in case of a transaction failure due to a check reverting.
For instance, within the _mintAndClaimRewardToken(...) function, the execution gas could be saved if the _amount check would be performed before writing to storage.
function _mintAndClaimRewardToken(...) private {
// ...
// @audit Perform the check before writing to storage.
currentRewardSupply[_tokenId] += _amount;
// ...
// @audit Perform this check earlier to follow the CEI pattern and save gas.
if (_amount == 0) {
revert InvalidAmount();
}
// ...
}Recommendation
Consider applying the Check-Effect Interaction pattern to make the code more robust while saving gas in the process.
Resolution
_mintAndClaimRewardToken() fixed, not sure anywhere else in the contract has this issue. Can you point it out for me please? 1c93d95114b9edcb8681c74bcb8627eb7a4956db
| File | Fix commit | Type | Status |
LootDrop.sol | 1c93d95 | Best Practices | Fixed |
The codebase contains some unused code, affecting overall readability and code quality. A non-exhaustive list of unused declarations is shown below:
tokenCreate variable in the _createTokenAndDepositRewards(...) function;tokenIdProcessed mapping state variable;TokenUpdated event;Recommendation
To keep the code clean and readable, consider removing unused functionality.
Resolution
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:
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.
The Summon team has described the contract during the code walk-through. Additionally, supporting diagrams of interaction flows were provided. Unfortunately, the codebase lacks detailed comments on individual functions.
Remarks about Summon test suite
The Summon team has diligently crafted test suites that encapsulate the fundamental workflows for interacting with the protocol. However, the current test suite lacks comprehensiveness, especially regarding edge cases and functionalities. For example, tests for scenarios with multiple claimants and accounting validation still need to be included.
| 54Tests passed | 0Failed |
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.
The Leading Engineers of Blockchain Infrastructure