Starknet Nova
Launchpad

Starknet Nova is a launchpad where users stake assets to build up weight and commit it to token sales. We reviewed staking, sale allocations, linear and cliff vesting, and the SuperNovaToken wrapper.
report id
0259
category
Token & RWA
language
Cairo
final report
October 10, 2024
lines of code
1723
Content

Download audit report

1

Executive Summary

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 TypeSecurity Review
Initial ReportAugust 22, 2024
Final ReportOctober 10, 2024
MethodsManual Review, Automated analysis
RepositoryStarknet-Nova/core-contracts
Commit Hashb83e636758
Final Commit Hash4af4a3cef1
DocumentationSpecs
Documentation AssessmentMedium
Test Suite AssessmentMedium
Total findings
7
Fixed
6
Acknowledged
1
Mitigated
0
Unresolved
0

Findings by severity

  • Critical1
  • High1
  • Medium1
  • Low0
  • Informational1
  • Best Practices3

4

System Overview

The audited core contracts in the Starknet Nova protocol implementation are shown below, each contract is described as follows:

4.1 novasale.cairo

Contains 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.

4.2 novastaking.cairo

This 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.

4.3 novawhitelister.cairo

This 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.

4.4 novatoken.cairo

The Nova Launchpad token, a standard ERC20 contract importing from the OpenZeppelin implementation.

4.5 supernovatoken.cairo

An 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.

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 Users can withdraw more than their purchased token amount

FileFix commitTypeStatus
src/core/novasale.cairo5a5dc1dCriticalFixed

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.

6.2 The supernovatoken cannot be unwrapped by transfer recipients

FileFix commitTypeStatus
src/core/supernovatoken.cairo3ef6ee4HighFixed

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.

6.3 if_user_uncommitted_after_purchase_start_in_sale_id is not related to specific tokens

FileFix commitTypeStatus
src/core/novastaking.cairof1f9ebf
9c24ab9
MediumFixed

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.

6.4 Sale stage is not well defined at start and end timestamp

FileFix commitTypeStatus
src/core/novasale.cairo57fba1bInfoFixed

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.

6.5 Basis points field bips in supernovatoken should be fixed

FileFix commitTypeStatus
src/core/supernovatoken.cairo5f9a8f6Best PracticesFixed

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.

6.6 Return values from ERC20 transfer functions are not checked

FileFix commitTypeStatus
src/*802dec2Best PracticesFixed

When 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.

6.7 The _assert_before_commit_start(...) has multiple responsibilities

FileFix commitTypeStatus
src/core/novasale.cairo—Best PracticesAcknowledged

The function _assert_before_commit_start(...) is used to check if at least one of the following conditions is true:

  • Commit time for the sale has not started;
  • Commit time for the sale has not been set;

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.

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 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.

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