Download audit report
This document presents the security review of Decentraland periodic token vesting implementation performed by Nethermind. The vesting generator allows vesting a token in varying quantities over consecutive periods of the same length. Common vestings would obtain vested tokens linearly over a certain period, occasionally with a cliff to restrict these tokens from being released for a fraction of that time. Decentraland vesting builder allows one to set periods, define how many tokens each period vests, and construct a program in which a variable number of tokens become releasable as each period proceeds.
The contract under security review implements 80 unit tests. The source code consists of 258 lines of Solidity with code coverage of 100%. The audit was completed primarily with manual analysis of the codebase, as well as using automated analysis tools. The application has good technical documentation. The documentation is easy to follow and sufficient for this audit purpose. It includes a high level overview of the application, how to test it, use case scenarios, and access to the application (although the link for the test application is not working to create a token vesting at the time of this report). Overall the code is well-written, structured, commented, and easy to comprehend. Inputs and variables are validated to ensure the data are correct which is ideal for security.
During the initial audit, we point out 5 potential issues. During the reaudit, the Decentraland team has acknowledged 3 issues, fixed 1 issue and 1 issue was defined as false-positive.
| Audit assessment | |
| Audit Type | Security Review |
| Initial Report | Nov. 15, 2022 |
| Response from Client | Nov. 28, 2022 |
| Final Report | Dec. 5, 2022 |
| Methods | Manual Review, Automated Analysis |
| Repository | Periodic Token Vesting Contract |
| Commit Hash (Initial Audit) | 0950e1eab5 |
| Documentation | README.md |
| Documentation Assessment | High |
| Test Suite Assessment | High |
Findings by severity
| # | Contract | LoC | Comments | Ratio | Blank | Total |
| 1 | ./contracts/PeriodicTokenVesting.sol | 258 | 108 | 41.9% | 85 | 451 |
| Total | 258 | 108 | 41.9% | 85 | 451 |
| # | Finding | Severity | Update |
| 1.1 | Changing beneficiary is an atomic process | Low | Acknowledged |
| 1.2 | Total vested amount can be calculated in initialize(...) | Info | Acknowledged |
| 1.3 | Total vested amount not guaranteed to be released to beneficiary | Info | Acknowledged |
| 1.4 | Gas optimization for function getTotal() | Best Practices | Fixed |
No system overview is included in this report.
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.
PeriodicTokenVesting.sol| File | Fix commit | Type | Status |
contracts/PeriodicTokenVesting.sol | — | Low | Acknowledged |
Changing the beneficiary with the function setBenificiary(...) is an atomic process. Once changed only the new beneficiary can make any further changes. If the current beneficiary passes an incorrect non-zero value then access to the contract will be lost.
Recommendation
Consider changing the process of setting a new beneficiary to set-then-claim to ensure that the beneficiary has set the correct address.
Resolution
It is a great suggestion but we will not change it for the moment as we think that if we apply this pattern to setBeneficiary, it would be appropriate to change it on all setters and we can’t do it for inherited OZ contracts.
initialize(...)| File | Fix commit | Type | Status |
contracts/PeriodicTokenVesting.sol | — | Info | Acknowledged |
The function getTotal(...) is used to calculate the total amount to be vested over all time periods. Since the contents of vestedPerPeriod cannot change, the total can be calculated once in the initialize(...) function to save gas.
Recommendation
Consider calculating the total amount to be vested in the initialize(...) function rather than calculating the total on every call to getTotal(...).
Resolution
We won’t apply as it considerably increases the gas consumption of the initialize function.
| File | Fix commit | Type | Status |
contracts/PeriodicTokenVesting.sol | — | Info | Acknowledged |
The vesting contract is used to gradually release tokens based on some vesting schedule. However, it is not guaranteed that the owner has transferred enough funds to the contract to cover the entire vested amount. The beneficiary may be unable to release vested funds due to insufficient contract token balances.
Recommendation
Consider checking in the initialize(...) function that the contract’s balance of vesting tokens is greater than or equal to the total amount to be vested over all periods. This will ensure that the contract has enough tokens for the beneficiary.
Resolution
This is done by design. The one in charge of funding the contract might not be the deployer so it has to be funded manually after the deployment.
getTotal()| File | Fix commit | Type | Status |
contracts/PeriodicTokenVesting.sol | — | Best Practices | Fixed |
The function getTotal() can be optimized by storing the length of the array vestedPerPeriod into a temporary variable using the same strategy adopted by the developers in function getVested(). The original code is shown below.
function getTotal() public view returns (uint256) {
uint256 total;
///////////////////////////////////////////////////////////////////
// @audit store "vestedPerPeriod.length" into a temp var
///////////////////////////////////////////////////////////////////
for (uint i = 0; i < vestedPerPeriod.length; ) {
total += vestedPerPeriod[i];
unchecked {
++i;
}
}
return total;
}The proposed code is presented below.
function getTotal_new_implementation() public view returns (uint256)
{
uint256 total;
///////////////////////////////////////////////////////////////////
// @audit store "vestedPerPeriod.length" into a temp var
///////////////////////////////////////////////////////////////////
uint256 size = vestedPerPeriod.length;
for (uint i = 0; i < size; ) {
total += vestedPerPeriod[i];
unchecked {
++i;
}
}
return total;
}The gas consumption for both strategies is compared in the figure below. The x-axis shows the array length, while the y-axis shows the gas consumption.
5 15 25 50 100
The gas consumption reduction promoted by the new strategy is presented in the next figure.
5 15 25 50 100
Recommendation
Consider using the proposed strategy.
Resolution
We will apply the following optimization in the getTotal(...) function as it saves even more gas due to not having to access storage vestedPerPeriod[i] each iteration.
/// @notice Get the total amount of tokens that will be vested in this contract.
/// @return The total amount of tokens that will be vested in this contract.
function getTotal() public view returns (uint256) {
uint256 total;
uint256[] memory mVestedPerPeriod = vestedPerPeriod;
// Sum all the tokens vested per period to obtain the total amount.
for (uint256 i = 0; i < mVestedPerPeriod.length; ) {
total += mVestedPerPeriod[i];
unchecked {
++i;
}
}
return total;
}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 codebase contains a README file with sufficient information for the purposes of this audit. It includes a high level overview of the application, use case scenarios, and a description of how to run unit tests. There is also a link to use the application to create vesting (although, we could not create a vesting through the provided link). Adequate technical documentation improves the efficiency of audits in addition to being a good programming practice. Consequently, less time is required to comprehend the contract under review and more time can be addressed to audit activities, thus, improving the efficiency and overall audit output. And for this end, the documentation is easy to follow and clarifies the most important features of the protocol.
Concerning code as documentation, we observed that all functions are properly documented by implementing NatSpec in-line documentation structure to make it easy to understand what a function should do as well as its inputs and outputs.
Decentraland presented 80 unit tests addressed to functions implemented in the contract PeriodicTokenVesting, with the code coverage of 100%.
Below, we present the compilation process output. As we can see, there are no warnings and all Solidity files were successfully compiled.
,! is linear
,! is linear
,! is linear
,! periods,! have elapsed
The tests present a full code coverage (100%), i.e., all code lines were tested.
The file config.yaml was defined as:
The following command was used for running Echidna. ,! instructions: 2023
| 80Tests 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