H1 2025 Web3 Security Report$3.1B in losses, DeFi hit hardest, AI threats on the rise
Read the full report
  • Hacken
  • Audits
  • near
  • [L1] Near | Nearcore | Oct2023

Audit name:

[L1] Near | Nearcore | Oct2023

Date:

Oct 24, 2023

Table of Content

Introduction
Audit Summary
Document Information
System Overview
Executive Summary
Findings
Appendix 1. Severity Definitions
Appendix 2. Scope
Disclaimer

Want a comprehensive audit report like this?

Introduction

This report may contain confidential information about IT systems and the intellectual property of the Customer, as well as information about potential vulnerabilities and methods of their exploitation.

titlecontent
PlatformNEAR
LanguageRust
TagsL1
Timeline17/07/2023 - 23/10/2023
Methodologyhttps://hackenio.cc/blockchain_methodology

    Review Scope

    Repositoryhttps://github.com/near/nearcore
    Commit1e781bcccfaeb9a4bb9531155193a459257afd8d

    Audit Summary

    Total10/10
    Security Score

    10/10

    Test Coverage

    10/10

    Code Quality Score

    10/10

    Documentation Quality Score

    10/10

    9Total Findings
    8Resolved
    1Accepted
    0Mitigated

    The system users should acknowledge all the risks summed up in the risks section of the report

    Document Information

    This report may contain confidential information about IT systems and the intellectual property of the Customer, as well as information about potential vulnerabilities and methods of their exploitation.

    The report can be disclosed publicly after prior consent by another Party. Any subsequent publication of this report shall be without mandatory consent.

    Document

    NameBlockchain Protocol Review and Security Analysis Report for NEAR
    Audited ByHacken
    Approved ByLuciano Ciattaglia ([email protected])
    Websitehttps://near.org/
    Changelog23/10/2023 - Final Report
    • Document

      Name
      Blockchain Protocol Review and Security Analysis Report for NEAR
      Audited By
      Hacken
      Approved By
      Luciano Ciattaglia ([email protected])
      Changelog
      23/10/2023 - Final Report

    System Overview

    The Near Protocol, a decentralized application platform designed for scalable and user-friendly apps, has been gaining traction in the blockchain community. With a focus on usability and scalability, Near provides developers with tools to create efficient decentralized applications.

    At Hacken, we conducted security research on nearcore, revealing findings ranging from informational to low severity.

    Our primary focus was on identifying critical vulnerabilities that could potentially lead to a loss of funds or unauthorized minting of tokens, as well as vulnerabilities that could incapacitate the network or a segment of it.

    The logical state of the blockchain in nearcore is split into two components: chain and runtime. These two are the main components in our scope of research. The chain is responsible for block and chunk production and processing, consensus, and validator selection. The runtime is responsible for applying transactions to the state.

    We ensured block and chunk production and validation logic for safety, liveness, and correctness. Continuous fuzzing for block and chunk production and serialization didn't yield any issues, only a few false positives and an issue in Arbitrary derivation, which is not part of the scope of of our research. We manually explored the related codebase and tests to learn how it works. We didn't find a way to produce an invalid chunk and include it in the block. The chunk creation and distribution logic is well-designed, having undergone many refactors over the last few years. The use of erasure coding allows only a subset of validators to reconstruct an entire chunk, ensuring data integrity and availability. After checking how incoming chunks are processed and validated, we didn't find an option to corrupt a chunk that would go unnoticed.

    In our deep dive into chunk production, we focused on transaction validation and processing. It's crucial to ensure the integrity and accuracy of all related processes. We set up continuous fuzzing for transaction and receipt serialization and also checked related bug bounty findings. There is one very interesting finding that exposes a vulnerability, enabling a hacker to mint tokens from thin air by duplicating receipts. This critical issue was promptly fixed the day after the bug submission and is currently being evaluated for a payout, which is anticipated to be a significant amount, acknowledging the seriousness of the vulnerability. Post-fix, we confirmed that the issue could no longer be reproduced, ensuring the robustness of our system.

    Nearcore has an impressive stateless runtime implementation, but it demands a thorough understanding of its design and the mechanisms invented for specific scenarios. We like that it's possible to bundle many actions into one transaction, ensuring they all execute or fail together. As the Near Protocol is a sharded blockchain, it has developed a way to process transactions that go beyond its signer shard. This area seemed ripe for potential issues, but our investigations found it to be robust. We believe, however, that this area still requires vigilant attention from developers due to its potential impact on network economics.

    Near supports nine different transaction types. The most significant one allows the execution of smart contracts inside the Near VM. Our approach here involved continuous fuzzing, aiming to identify crashes and subsequently investigate with test code. Most crashes were false positives, but some highlighted gaps in the singlepass compiler. One particular crash could disrupt the contract compilation process, but this has been addressed in the current protocol version.

    The blockchain state in nearcore adopts an MPT structure, akin to Ethereum's but with unique modifications. While documentation on this storage approach is sparse, our codebase investigation found its design for recording and committing changes to be sound. We did identify a minor issue with TrieKey serialization related to data separator inconsistency, but this impacts only code quality, not security.

    Executive Summary

    Documentation quality

    Near boasts comprehensive documentation, illuminating the concepts and architecture of the node and protocol. Additionally, the specifications for all protocol components are of high quality. While we initially found that the runtime crates' documentation was outdated, this has since been updated. Additionally, the previously identified broken links throughout the codebase and readme files have been rectified. These improvements have effectively resolved the minor inconsistencies that could have potentially misled readers or developers.

    The total Documentation quality score is 10 out of 10.

    Code quality

    The nearcore is renowned for its high code quality, effectively utilizing the capabilities of the Rust programming language and its architectural patterns. As part of their ongoing commitment to security and excellence, the project developers have implemented a significant enhancement in their continuous integration (CI) process. By integrating cargo-audit into their CI system, the Near Protocol team ensures the enforcement of a "no vulnerable dependency" policy, not just as a one-time fix but as a sustained, long-term change. This proactive approach continuously safeguards against potential vulnerabilities. Furthermore, the few vulnerable or outdated external dependencies previously identified have been promptly updated. The Wasmtime dependency has been upgraded to ensure compatibility with its latest version. Concerning the singlepass compiler's validation process during compilation, a low-severity issue, it's noteworthy that a separate validation mechanism within near_vm_runner filters out unsupported features before compilation. The initial concerns regarding the test code quality, specifically adherence to best practices and inconsistent test coverage measurements, particularly for external tests, have been addressed and are now marked as resolved by the Near Protocol team.

    The total Code quality score is 10 out of 10.

    Architecture quality

    The architecture of nearcore is commendable. Designed with sharding at its core, it embodies scalability from day one. While no system is flawless, our comprehensive research did not identify any high-level architectural issues in nearcore.

    Code coverage of the project is 10 out of 10.

    Security score

    Our exhaustive research did not unearth any critical security flaws within the audit's scope. However, a few high-severity issues identified by bug hunters were promptly addressed and rectified. At this project stage, we believe that a bug bounty program is invaluable, often leading to in-depth, focused investigations.

    In conclusion, nearcore is a high-quality blockchain project.

    The total Security score is 10 out of 10.

    Summary

    The comprehensive audit of the customer's smart contract yields an overall score of 10. This score reflects the combined evaluation of documentation, code quality, architecture quality, and security aspects of the project.

    Findings

    Code
    Title
    Status
    Severity
    F-2023-1640Singlepass Compiler Vulnerability: Absence of wasm Feature Validation
    fixed

    Low
    F-2023-164Address Vulnerable, Outdated, and Unmaintained Dependencies
    fixed

    Low
    F-2023-1642Address Broken Links Throughout Codebase
    fixed

    Low
    F-2023-164Inconsistent TrieKey Implementation
    fixed

    Low
    F-2023-1648Upgrade Wasmtime Dependency and Adjust for API Changes
    fixed

    Observation
    F-2023-1647Test Fixtures And Coverage Analysis
    fixed

    Observation
    F-2023-1646Rectification of Documentation Inconsistencies
    fixed

    Observation
    F-2023-164NearVM runtime crates has inadequate documentation and TODO annotations
    fixed

    Observation
    F-2023-164Inherent risk with use of "clamp" function for gas price validation
    accepted

    Observation
    1-9 of 9 findings

    Findings like these can secure your blockchain.

    Appendix 1. Severity Definitions

    Severity

    Description

    Critical
    Vulnerabilities that can lead to a complete breakdown of the blockchain network's security, privacy, integrity, or availability fall under this category. They can disrupt the consensus mechanism, enabling a malicious entity to take control of the majority of nodes or facilitate 51% attacks. In addition, issues that could lead to widespread crashing of nodes, leading to a complete breakdown or significant halt of the network, are also considered critical along with issues that can lead to a massive theft of assets. Immediate attention and mitigation are required.

    High
    High severity vulnerabilities are those that do not immediately risk the complete security or integrity of the network but can cause substantial harm. These are issues that could cause the crashing of several nodes, leading to temporary disruption of the network, or could manipulate the consensus mechanism to a certain extent, but not enough to execute a 51% attack. Partial breaches of privacy, unauthorized but limited access to sensitive information, and affecting the reliable execution of smart contracts also fall under this category.

    Medium
    Medium severity vulnerabilities could negatively affect the blockchain protocol but are usually not capable of causing catastrophic damage. These could include vulnerabilities that allow minor breaches of user privacy, can slow down transaction processing, or can lead to relatively small financial losses. It may be possible to exploit these vulnerabilities under specific circumstances, or they may require a high level of access to exploit effectively.

    Low
    Low severity vulnerabilities are minor flaws in the blockchain protocol that might not have a direct impact on security but could cause minor inefficiencies in transaction processing or slight delays in block propagation. They might include vulnerabilities that allow attackers to cause nuisance-level disruptions or are only exploitable under extremely rare and specific conditions. These vulnerabilities should be corrected but do not represent an immediate threat to the system.
    • Severity

      Critical

      Description

      Vulnerabilities that can lead to a complete breakdown of the blockchain network's security, privacy, integrity, or availability fall under this category. They can disrupt the consensus mechanism, enabling a malicious entity to take control of the majority of nodes or facilitate 51% attacks. In addition, issues that could lead to widespread crashing of nodes, leading to a complete breakdown or significant halt of the network, are also considered critical along with issues that can lead to a massive theft of assets. Immediate attention and mitigation are required.

      Severity

      High

      Description

      High severity vulnerabilities are those that do not immediately risk the complete security or integrity of the network but can cause substantial harm. These are issues that could cause the crashing of several nodes, leading to temporary disruption of the network, or could manipulate the consensus mechanism to a certain extent, but not enough to execute a 51% attack. Partial breaches of privacy, unauthorized but limited access to sensitive information, and affecting the reliable execution of smart contracts also fall under this category.

      Severity

      Medium

      Description

      Medium severity vulnerabilities could negatively affect the blockchain protocol but are usually not capable of causing catastrophic damage. These could include vulnerabilities that allow minor breaches of user privacy, can slow down transaction processing, or can lead to relatively small financial losses. It may be possible to exploit these vulnerabilities under specific circumstances, or they may require a high level of access to exploit effectively.

      Severity

      Low

      Description

      Low severity vulnerabilities are minor flaws in the blockchain protocol that might not have a direct impact on security but could cause minor inefficiencies in transaction processing or slight delays in block propagation. They might include vulnerabilities that allow attackers to cause nuisance-level disruptions or are only exploitable under extremely rare and specific conditions. These vulnerabilities should be corrected but do not represent an immediate threat to the system.

    Appendix 2. Scope

    The scope of the project includes the following smart contracts from the provided repository:

    Scope Details

    Repositoryhttps://github.com/near/nearcore
    Commit1e781bcccfaeb9a4bb9531155193a459257afd8d

    Accounts

    • Accounts implementation review.

    • Security vectors analysis (data availability, nonce…)

    Chain

    • Tx and receipt implementation review (defaults, timestamps, assembly).

    • Block and chunk production and validation logic review.

    • Bootstrap review (genesis, seed peers).

    • Mempool review (defaults, timestamps).

    • Economics and staking model review.

    • Standard attacks review (replay, malleability…)

    Consensus

    • Consensus implementation review (validation, fork…)

    • Attack scenarios analysis (liveness, finality, eclipse, double spend…)

    • Upgrade mechanisms review.

    Runtime/VM

    • Runtime implementation review.

    • VM implementation review.

    • Smart contract implementation review.

    • Known VM Vulnerabilities review.

    • Attack scenarios analysis (Gas, race, stack, DoS, state implosion…)

    • Contract storage implementation review.

    Light client integration

    • Light client block validation logic review.

    • Light client execution proof verification logic review

    Disclaimer