Download audit report
This document outlines the security review conducted by Nethermind Security for Starknet Nova. Starknet Nova is a permissioned launchpad where users looking for investors can create token sales. Users who want to buy tokens must stake their supported ERC20 assets to gain a weighting that accumulates over time, which can be committed to a token sale. Committing these weights allows the users to gain an allocation in the token sale. Token sales run for a given time window, and then the assets can be released to the users either through a linear or cliff vesting approach. This review also included the SuperNovaToken, which is an ERC20 implementation that supports wrapping of the NovaToken.
The audited code comprises of 1723 lines of code written in the Cairo language, and the audit was performed using (a) manual analysis of the codebase, (b) automated analysis tools, (c) simulation of the smart contract.
| Audit assessment | |
| Audit Type | Security Review |
| Initial Report | August 22, 2024 |
| Final Report | October 10, 2024 |
| Methods | Manual Review, Automated analysis |
| Repository | Starknet-Nova/core-contracts |
| Commit Hash | b83e636758 |
| Final Commit Hash | 4af4a3cef1 |
| Documentation | Specs |
| Documentation Assessment | Medium |
| Test Suite Assessment | Medium |
Findings by severity
| # | Contract | LoC | Comments | Ratio | Blank | Total |
| 1 | src/utils.cairo | 2 | 0 | 0.0% | 0 | 2 |
| 2 | src/interfaces.cairo | 8 | 0 | 0.0% | 0 | 8 |
| 3 | src/models.cairo | 4 | 0 | 0.0% | 0 | 4 |
| 4 | src/core.cairo | 5 | 0 | 0.0% | 0 | 5 |
| 5 | src/lib.cairo | 4 | 0 | 0.0% | 0 | 4 |
| 6 | src/core/novawhitelister.cairo | 48 | 11 | 22.9% | 9 | 68 |
| 7 | src/core/novatoken.cairo | 25 | 9 | 36.0% | 6 | 40 |
| 8 | src/core/novasale.cairo | 715 | 36 | 5.0% | 50 | 801 |
| 9 | src/core/novastaking.cairo | 305 | 34 | 11.1% | 23 | 362 |
| 10 | src/core/supernovatoken.cairo | 167 | 22 | 13.2% | 22 | 211 |
| 11 | src/utils/storeu64span.cairo | 50 | 9 | 18.0% | 10 | 69 |
| 12 | src/utils/mockerc20.cairo | 19 | 8 | 42.1% | 5 | 32 |
| 13 | src/models/sale.cairo | 19 | 1 | 5.3% | 1 | 21 |
| 14 | src/models/usercheckpoint.cairo | 38 | 1 | 2.6% | 8 | 47 |
| 15 | src/models/stakingtoken.cairo | 4 | 1 | 25.0% | 0 | 5 |
| 16 | src/models/supernovauser.cairo | 5 | 1 | 20.0% | 0 | 6 |
| 17 | src/interfaces/fundable.cairo | 35 | 47 | 134.3% | 5 | 87 |
| 18 | src/interfaces/purchasable.cairo | 112 | 170 | 151.8% | 19 | 301 |
| 19 | src/interfaces/versionable.cairo | 3 | 1 | 33.3% | 0 | 4 |
| 20 | src/interfaces/novasale.cairo | 23 | 49 | 213.0% | 8 | 80 |
| 21 | src/interfaces/stakeable.cairo | 74 | 103 | 139.2% | 18 | 195 |
| 22 | src/interfaces/supernovatoken.cairo | 23 | 75 | 326.1% | 16 | 114 |
| 23 | src/interfaces/vestable.cairo | 20 | 48 | 240.0% | 9 | 77 |
| 24 | src/interfaces/whitelistable.cairo | 15 | 17 | 113.3% | 4 | 36 |
| Total | 1723 | 643 | 37.3% | 213 | 2579 |
| # | Finding | Severity | Update |
| 1 | Users can withdraw more than their purchased token amount | Critical | Fixed |
| 2 | The supernovatoken cannot be unwrapped by transfer recipients | High | Fixed |
| 3 | if_user_uncommitted_after_purchase_start_in_sale_id is not related to specific tokens | Medium | Fixed |
| 4 | Sale stage is not well defined at start and end timestamp | Info | Fixed |
| 5 | Basis points field bips in supernovatoken should be fixed | Best Practices | Fixed |
| 6 | Return values from ERC20 transfer functions are not checked | Best Practices | Fixed |
| 7 | The _assert_before_commit_start(...) has multiple responsibilities | Best Practices | Acknowledged |
The audited core contracts in the Starknet Nova protocol implementation are shown below, each contract is described as follows:
novasale.cairoContains functions for managing sales. This contract allows the creation and configuration of new sales. Users looking to buy tokens will also interact with this contract through the purchase(...) and purchase_whitelist(...) functions. Whitelisted sales will use a novawhitelister contract to verify users that can participate in purchasing tokens; non-whitelisted sales will use the committed weights by users to define the token allocation associated with each user.
After a sale has finished, the sale’s owner can use the cashout(...) function to claim the payment tokens and any surplus of sale tokens that were not bought by the users. Users can also claim the tokens they bought after the sale has ended. However, they depend on the sale configuration to decide how to claim the tokens. It is possible for the sales owner to set two different ways of claiming the tokens: one is through linear vesting, and the other is by a sequence of releases of different amounts of tokens.
novastaking.cairoThis contract manages all the functionalities related to staking. Staking is a crucial part of the NovaSale protocol. Users are required to stake tokens in order to gain weights that they can use to receive allocations in the different token sales that exist. The contract’s owner can define which tokens can be staked at any moment and how much weight each token will generate per second.
Users can stake their tokens and will earn weights for each second they are staked. These weights can be committed to a sale during the commitment period to receive an allocation of tokens to buy. Users can also uncommit their committed weights at any time; however, they need to have them committed when the commitment period of the sale ends in order to get the token allocation. Because of how allocations are computed, users can commit the same weights in multiple sales and receive allocation if those sales do not finish their commitment phase simultaneously. It is important to note that weights are linked to the tokens that produced them.
The total weights a user has for a specific token are evenly distributed between the amount of that token the user has staked; this can produce different situations where staking and unstaking a certain amount of tokens can vary the amount of weights a user has in unexpected ways. To unstake a certain amount of tokens, the users must have a proportional amount of uncommitted weights associated with that token.
novawhitelister.cairoThis contract holds a merkle tree where each leaf is the result of hashing a ContractAddress and a u256, representing a whitelisted user’s address and the amount of tokens they are eligible to purchase respectively. The merkle root is set by the owner, and a verify(...) function is exposed which is used by the NovaSale contract for verifying whitelisted purchases.
novatoken.cairoThe Nova Launchpad token, a standard ERC20 contract importing from the OpenZeppelin implementation.
supernovatoken.cairoAn ERC20 contract imported from the OpenZeppelin implementation with an additional feature allowing the Nova Launchpad token to be wrapped. Tokens must remain wrapped for some set amount of time, otherwise a penalty is applied.
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 |
src/core/novasale.cairo | 5a5dc1d | Critical | Fixed |
The function withdraw_claimable_tokens is called by users to transfer assets once a cliff time has been reached or when a reasonable amount of time has passed for linear vesting. The number of claimable tokens is calculated first, and then vesting_claimed_sale_token_amount_for_user is updated. This storage variable should track the cumulative amount of tokens claimed, but it only tracks the amount of the most recent claim.
fn withdraw_claimable_tokens(ref self: ContractState, sale_id: u64) {
// ...
let withdraw_amount = self.get_unclaimed_tokens(user, sale_id);
self.vesting_claimed_sale_token_amount_for_user.write((user, sale_id), withdraw_amount);
self.sale_token.read(sale_id).transfer(user, withdraw_amount);
// ...
}The function get_unclaimed_tokens then uses this storage variable with an incorrect assumption that it tracks the cumulative claim, and allows for more assets to be claimed than expected. Consider the following scenario for cliff vesting:
formula = total_token * released_bips / total_bips - vesting_claimed
total_tokens = 1000
cliff1 = 2500 bips
cliff2 = 2500 bips
cliff3 = 2500 bips
cliff4 = 2500 bips
1st claim
vesting_claimed = 0
released_bips = 2500
1000 * 2500 / 10000 - 0 = 250
250 claimed, set vesting_claimed to 250
2nd claim
vesting_claimed = 250
released_bips = 5000
1000 * 5000 / 10000 - 250 = 250
250 claimed, set vesting_claimed to 250 (should be 500, cumulative)
3rd claim
vesting_claimed = 250
released_bips = 7500
1000 * 7500 / 10000 - 250 = 500
500 claimed, set vesting_claimed to 500 (should be 750, cumulative)
4th claim
vesting_claimed = 500
released_bips = 10000
1000 * 10000 / 10000 - 500 = 500
500 claimed, set vesting_claimed to 500 (should be 1000, cumulative)A user could call this function repeatedly after the fourth claim and the contract logic will determine every time that they should get 500 tokens. This can be used to drain the token balance from the contract.
Recommendation
Consider changing the function withdraw_claimable_tokens to add onto the existing value for vesting_claimed_sale_token_amount_for_user rather than directly overwriting.
Resolution
Resolved with 5a5dc1d5e06013498f35e7660dfc3b68baa53e02.
supernovatoken cannot be unwrapped by transfer recipients| File | Fix commit | Type | Status |
src/core/supernovatoken.cairo | 3ef6ee4 | High | Fixed |
When a user first wraps some amount of novatoken into supernovatoken, the storage mapping users will be updated. Particularly, the wrapped_amount field will be incremented to reflect the new amount of wrapped tokens, as shown below:
fn wrap(ref self: ContractState, amount: u256) {
//...
user.wrapped_amount += amount;
self.users.write(user_address, user);
self.erc20._mint(user_address, amount);
}When unwrapping assets, this wrapped_amount field is decreased to reflect the change after some number of assets have been unwrapped. This operation will work correctly only when the caller has wrapped an equivalent number of tokens themselves. If a user did not ever wrap tokens themselves, but received them via transfer or transferFrom instead, then their entry in the users mapping will be empty. When subtracting from the wrapped_amount field it will result in an underflow and cause the call to revert.
fn unwrap(ref self: ContractState, amount: u256) {
// ...
let user_address = get_caller_address();
let mut user = self.users.read(user_address);
// @audit If user received tokens via transfer this will be zero
// Attempting to subtract will result in the call reverting
user.wrapped_amount -= amount;
// ...
}Recommendation
Consider using the user’s token balance to track the user wrapped amount instead of tracking it separately in storage with user.wrapped_amount, as they are both updated in the same functions with the same values.
Resolution
Resolved with 3ef6ee4db90de2ab933afb397d0f6b56b3b6f17d.
if_user_uncommitted_after_purchase_start_in_sale_id is not related to specific tokens| File | Fix commit | Type | Status |
src/core/novastaking.cairo | f1f9ebf9c24ab9 | Medium | Fixed |
Users can uncommit their voting power through the uncommit(...) function. This function contains a check to ensure that users do not uncommit power related to the same more than once.
fn uncommit(ref self: ContractState, sale_id: u64, token: ContractAddress) {
...
let past_commit_period = !IPurchasableDispatcher {
contract_address: self.nova_sale_contract.read()
}
.is_currently_committable(sale_id);
assert(
!(past_commit_period
&& self
.if_user_uncommitted_after_purchase_start_in_sale_id
.read((get_caller_address(), sale_id))),
StakeableError::ALREADY_UNCOMMITTED
);
...
}For this, the if_user_uncommitted_after_purchase_start_in_sale_id mapping is used. However, these mapping entries are linked to a specific user and sales ID; they are not related to specific tokens. In case a user has committed voting power from multiple tokens until the end of the committable period, after they uncommit the power related to one token, they won’t be able to uncommit the power related to the rest of the tokens.
Recommendation
Consider adding one more key to this mapping in order to have entries per the tuple (user, sale_id, token).
Resolution
Overhauled staking and committing logic in commits f1f9ebf58b50fcc2cf9186097cf5dba478518c9e and 9c24ab9ef4a089a87859f2bdece2a79c27e35fa7.
| File | Fix commit | Type | Status |
src/core/novasale.cairo | 57fba1b | Info | Fixed |
The _assert_before_sale_start(...), _assert_during_sale(...), and _assert_after_sale_end(...) functions are used to verify that a sale is at a specific stage.
fn _assert_before_sale_start(self: @ContractState, sale_id: u64) {
let (start, _) = self.sale_start_end_timestamp.read(sale_id);
assert(start > get_block_timestamp(), FundableError::NOT_BEFORE_SALE_START);
}
fn _assert_during_sale(self: @ContractState, sale_id: u64) {
let (start, end) = self.sale_start_end_timestamp.read(sale_id);
let current_timestamp = get_block_timestamp();
assert(
start < current_timestamp && end > current_timestamp, FundableError::NOT_DURING_SALE
);
}
fn _assert_after_sale_end(self: @ContractState, sale_id: u64) {
let (_, end) = self.sale_start_end_timestamp.read(sale_id);
assert(end < get_block_timestamp(), FundableError::SALE_IN_PROGRESS);
}The _assert_during_sale(...) checks that the current time is strictly lower than the end time and strictly bigger than the start time. The _assert_after_sale_end(...) checks that the current time is strictly greater than the end time. The _assert_before_sale_start(...) function checks that the current time is strictly lower than the start time. When the current timestamp is equal to the start or end timestamp, all these functions will fail
Recommendation
Consider defining the stage of a sale at the start and end timestamps and modifying the functions accordingly.
Resolution
Resolved with 57fba1b40448c553dfc923f2c3a340bf8a96772e.
bips in supernovatoken should be fixed| File | Fix commit | Type | Status |
src/core/supernovatoken.cairo | 5f9a8f6 | Best Practices | Fixed |
The contract supernovatoken has a penalty mechanism which is applied to users that unwrap their tokens before the specified wait time is over. The penalty fee is measured in basis points (bips), a financial term where each bip is one hundredth of one percentage point (1/10000). The supernovatoken contract does not follow the proper definition of basis points, as the denominator should always be 10000, but instead there is a function set_bips that allows it to be set to an arbitrary value.
// @audit The term "bips" implies it should always be 10000
// No need for this to be set, can be a constant
fn set_bips(ref self: ContractState, bips: u256) {
self.ownable.assert_only_owner();
self.bips.write(bips);
}
// @audit This could be simplified to `amount * penalty / 10000`
fn get_penalty_amount(self: @ContractState, amount: u256) -> u256 {
amount * self.force_claim_penalty_bips.read() / self.bips.read()
}Recommendation
If the term "bips" is to be followed correctly, consider setting the bips as a fixed value of 10000. This will also remove a storage read when applying penalty amounts. If the denominator needs to change to values other than 10000, consider using a term other than "bips" to make it clear to any developers reading the codebase.
Resolution
Resolved in 5f9a8f6651309c896848aed6250aea0df124e016.
ERC20 transfer functions are not checkedWhen using transfer(...) and transfer_from(...) functions from ERC20 contracts the returned value is not checked. These functions are expected to return a the value true when they are successful and revert when that are not. However, there are widely use tokens in networks like Ethereum mainnet that do not follow this flow and return false instead of reverting when a transfer cannot occur. It is possible that this behavior will be replicated in Starknet by some tokens, in this case contracts interacting with this kind of tokens could work in unintended ways.
Recommendation
Consider checking that the transfer(...) and transfer_from(...) functions return true indicating a successful execution.
Resolution
Resolved with 802dec21991cf43cbbba2bf881ac6c3b6f4837fa.
_assert_before_commit_start(...) has multiple responsibilities| File | Fix commit | Type | Status |
src/core/novasale.cairo | — | Best Practices | Acknowledged |
The function _assert_before_commit_start(...) is used to check if at least one of the following conditions is true:
These conditions are expected to check for different flows; however, the same function is used in all the flows.
Recommendation
It is a good practice to keep a clear and unique responsibility to each function to avoid bugs in future development.
Resolution
Acknowledged, but skipping the fix.
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 Starknet Nova provided a specification for some of the main functionalities of the contracts; besides this, inline comments within the codebase are informative and describe expected functionality. Additionally, the Starknet Nova team was available to address any questions or concerns from the Nethermind Security team.
| 16Tests 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