Tangle Network Code Review - Tangle Tools


Prepared by:

Halborn Logo

HALBORN

Last Updated Unknown date

Date of Engagement: October 15th, 2024 - December 13th, 2024

Summary

100% of all REPORTED Findings have been addressed

All findings

30

Critical

0

High

1

Medium

2

Low

3

Informational

24


Table of Contents

1. Introduction

Tangle Network engaged Halborn to perform a security assessment of their Rust codebase from Oct. 15, 2024, to Dec. 13, 2024. The assessment focused on the substrate code, precompiled code, and pallets listed in the provided GitHub repository and included relevant commit hashes. More details can be found in the Scope section of this report.

2. Assessment Summary

The Halborn team was allocated 8 weeks and 3 days for the engagement and assigned two full-time security engineers to assess the security of the substrate pallets and the overall codebase. The security engineers are experts in blockchain and smart contract security, with advanced skills in penetration testing and smart contract auditing, as well as extensive knowledge of various blockchain protocols.

The purpose of this assessment is to:

    • Ensure that the codebase functions operate as intended, including properly implementing staking, pooling, reward mechanisms, and Ethereum compatibility features.

    • Identify potential security issues within the codebase, such as:

      • Cryptographic vulnerabilities (e.g., signature malleability, replay attacks, or misuse of hashing functions).

      • Logical inconsistencies in key functionalities like staking, unbonding, reward calculations.

      • Dependency-related risks from external crates and libraries.

      • Insufficient input validation or unchecked operations may lead to panics, overflows, or security exploits.

    • Verify that the code adheres to best practices for blockchain security, such as preventing unauthorized access, maintaining data integrity, and ensuring predictable execution under edge cases and adverse conditions.

    • Assess the implementation of Ethereum precompiles, proxy types, and EVM integration to ensure proper validation, safe asset handling, and gas usage efficiency.

3. Test Approach and Methodology

The Halborn team performed a combination of manual code review and automated security testing to ensure a comprehensive and efficient assessment of the Tangle codebase. This approach balanced efficiency, timeliness, practicality, and accuracy to address the assessment scope. Manual testing was used to uncover flaws in logic, process, and implementation, while automated tools were employed to quickly identify deviations from security best practices. The following phases and associated tools were used throughout the assessment:

    • Research on the architecture, purpose, and usage of the Tangle network.

    • Manual code walkthroughs to understand the design of key modules, including staking, pooling, reward distribution, and EVM precompiles, while identifying potential vulnerabilities.

    • Assessment of Rust functions and variables for arithmetic vulnerabilities, such as overflow/underflow or unsafe computations.

    • Audit of cryptographic protocols and primitives, including ECDSA signature recovery and Ethereum address mapping, to ensure compliance with industry standards and robustness against attacks.

    • Scanning Rust crates with Cargo Audit to identify outdated dependencies, known vulnerabilities, and insecure versions of third-party libraries.

    • Analyzing unsafe code usage with Cargo Geiger, ensuring minimal reliance on unsafe Rust features to reduce risks of memory safety vulnerabilities.

    • Validation of error handling and logging practices to prevent unintentional exposure of sensitive information or system behavior.


4. RISK METHODOLOGY

Every vulnerability and issue observed by Halborn is ranked based on two sets of Metrics and a Severity Coefficient. This system is inspired by the industry standard Common Vulnerability Scoring System.
The two Metric sets are: Exploitability and Impact. Exploitability captures the ease and technical means by which vulnerabilities can be exploited and Impact describes the consequences of a successful exploit.
The Severity Coefficients is designed to further refine the accuracy of the ranking with two factors: Reversibility and Scope. These capture the impact of the vulnerability on the environment as well as the number of users and smart contracts affected.
The final score is a value between 0-10 rounded up to 1 decimal place and 10 corresponding to the highest security risk. This provides an objective and accurate rating of the severity of security vulnerabilities in smart contracts.
The system is designed to assist in identifying and prioritizing vulnerabilities based on their level of risk to address the most critical issues in a timely manner.

4.1 EXPLOITABILITY

Attack Origin (AO):
Captures whether the attack requires compromising a specific account.
Attack Cost (AC):
Captures the cost of exploiting the vulnerability incurred by the attacker relative to sending a single transaction on the relevant blockchain. Includes but is not limited to financial and computational cost.
Attack Complexity (AX):
Describes the conditions beyond the attacker’s control that must exist in order to exploit the vulnerability. Includes but is not limited to macro situation, available third-party liquidity and regulatory challenges.
Metrics:
EXPLOITABILITY METRIC (mem_e)METRIC VALUENUMERICAL VALUE
Attack Origin (AO)Arbitrary (AO:A)
Specific (AO:S)
1
0.2
Attack Cost (AC)Low (AC:L)
Medium (AC:M)
High (AC:H)
1
0.67
0.33
Attack Complexity (AX)Low (AX:L)
Medium (AX:M)
High (AX:H)
1
0.67
0.33
Exploitability EE is calculated using the following formula:

E=meE = \prod m_e

4.2 IMPACT

Confidentiality (C):
Measures the impact to the confidentiality of the information resources managed by the contract due to a successfully exploited vulnerability. Confidentiality refers to limiting access to authorized users only.
Integrity (I):
Measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of data stored and/or processed on-chain. Integrity impact directly affecting Deposit or Yield records is excluded.
Availability (A):
Measures the impact to the availability of the impacted component resulting from a successfully exploited vulnerability. This metric refers to smart contract features and functionality, not state. Availability impact directly affecting Deposit or Yield is excluded.
Deposit (D):
Measures the impact to the deposits made to the contract by either users or owners.
Yield (Y):
Measures the impact to the yield generated by the contract for either users or owners.
Metrics:
IMPACT METRIC (mIm_I)METRIC VALUENUMERICAL VALUE
Confidentiality (C)None (C:N)
Low (C:L)
Medium (C:M)
High (C:H)
Critical (C:C)
0
0.25
0.5
0.75
1
Integrity (I)None (I:N)
Low (I:L)
Medium (I:M)
High (I:H)
Critical (I:C)
0
0.25
0.5
0.75
1
Availability (A)None (A:N)
Low (A:L)
Medium (A:M)
High (A:H)
Critical (A:C)
0
0.25
0.5
0.75
1
Deposit (D)None (D:N)
Low (D:L)
Medium (D:M)
High (D:H)
Critical (D:C)
0
0.25
0.5
0.75
1
Yield (Y)None (Y:N)
Low (Y:L)
Medium (Y:M)
High (Y:H)
Critical (Y:C)
0
0.25
0.5
0.75
1
Impact II is calculated using the following formula:

I=max(mI)+mImax(mI)4I = max(m_I) + \frac{\sum{m_I} - max(m_I)}{4}

4.3 SEVERITY COEFFICIENT

Reversibility (R):
Describes the share of the exploited vulnerability effects that can be reversed. For upgradeable contracts, assume the contract private key is available.
Scope (S):
Captures whether a vulnerability in one vulnerable contract impacts resources in other contracts.
Metrics:
SEVERITY COEFFICIENT (CC)COEFFICIENT VALUENUMERICAL VALUE
Reversibility (rr)None (R:N)
Partial (R:P)
Full (R:F)
1
0.5
0.25
Scope (ss)Changed (S:C)
Unchanged (S:U)
1.25
1
Severity Coefficient CC is obtained by the following product:

C=rsC = rs

The Vulnerability Severity Score SS is obtained by:

S=min(10,EIC10)S = min(10, EIC * 10)

The score is rounded up to 1 decimal places.
SeverityScore Value Range
Critical9 - 10
High7 - 8.9
Medium4.5 - 6.9
Low2 - 4.4
Informational0 - 1.9

5. SCOPE

REPOSITORY
(a) Repository: tangle
(b) Assessed Commit ID: 57afc82
(c) Items in scope:
  • ./precompiles/precompile-registry/src/lib.rs
  • ./precompiles/precompile-registry/src/mock.rs
  • ./precompiles/precompile-registry/src/file.rs
↓ Expand ↓
Out-of-Scope: Third party dependencies and economic attacks.
Out-of-Scope: New features/implementations after the remediation commit IDs.

6. Assessment Summary & Findings Overview

Critical

0

High

1

Medium

2

Low

3

Informational

24

Security analysisRisk levelRemediation Date
Missing Pallet Functionalities In Corresponding Precompiles Makes It Impossible To Call Them Through EVM ContractsHighSolved - 01/21/2025
Incorrect Implementation Of is_nominator In Staking PrecompileMediumSolved - 01/20/2025
Unavailable Features Due to Discrepancies Between Precompile and EVM InterfaceMediumSolved - 01/21/2025
Miscalculated Selector Of The TransferNative LogLowSolved - 01/20/2025
Missing TransferNative Event in ERC-20 Interface ImplementationLowSolved - 01/20/2025
Mismatch in Return Types Between Precompiles and EVM InterfacesLowSolved - 01/21/2025
Potential Overflow in Deposit AccumulationInformationalSolved - 01/19/2025
Underflow in Stake ReductionInformationalSolved - 01/19/2025
Missing Unstake Amount validationInformationalSolved - 01/19/2025
Overflow in Operator Stake AdditionInformationalSolved - 01/19/2025
Ensure APY and Cap Are Within Acceptable RangesInformationalSolved - 01/19/2025
Missing Existing Stake Reduction Request ValidationInformationalSolved - 01/19/2025
Underflow in Gas CalculationInformationalSolved - 01/19/2025
Potential Overflow in Total Supply Update in mint_claimInformationalSolved - 01/19/2025
Overflow Risk in current_reward_counter Commission CalculationInformationalSolved - 01/19/2025
Unhandled Results in verify_signature! MacroInformationalSolved - 01/19/2025
Hardcoded Gas Limit and Inconsistent Error Handling in on_register_hookInformationalSolved - 01/19/2025
Missing Era Validation in dispute FunctionInformationalNot Applicable
Insecure Handling of Invalid Scalar Decoding in decodeInformationalSolved - 01/19/2025
Possible Underflow on Balance ReductionInformationalSolved - 01/19/2025
Use Distinct Error for Pending Leave RoundInformationalSolved - 01/19/2025
Presence Of TyposInformationalSolved - 01/21/2025
Presence Of TODOsInformationalSolved - 01/21/2025
Erroneous DocumentationInformationalSolved - 01/21/2025
Missing Precompiles in Tangle WorkspaceInformationalSolved - 01/21/2025
Compilation Errors In `tangle-lst` PrecompileInformationalSolved - 11/07/2024
Improper Mocking And Testing Of The `tangle-lst` PrecompileInformationalSolved - 11/07/2024
Redundant Function In `services` PrecompileInformationalSolved - 12/19/2024
Redundant Operations in move_claim for Identical AddressesInformationalSolved - 01/19/2025
Lack of Validation for Identity Element in deserialize FunctionInformationalSolved - 01/19/2025

7. Findings & Tech Details

7.1 Missing Pallet Functionalities In Corresponding Precompiles Makes It Impossible To Call Them Through EVM Contracts

//

High

Description
BVSS
Recommendation
Remediation Comment

7.2 Incorrect Implementation Of is_nominator In Staking Precompile

//

Medium

Description
BVSS
Recommendation
Remediation Comment

7.3 Unavailable Features Due to Discrepancies Between Precompile and EVM Interface

//

Medium

Description
BVSS
Recommendation
Remediation Comment

7.4 Miscalculated Selector Of The TransferNative Log

//

Low

Description
BVSS
Recommendation
Remediation Comment

7.5 Missing TransferNative Event in ERC-20 Interface Implementation

//

Low

Description
BVSS
Recommendation
Remediation Comment

7.6 Mismatch in Return Types Between Precompiles and EVM Interfaces

//

Low

Description
BVSS
Recommendation
Remediation Comment

7.7 Potential Overflow in Deposit Accumulation

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment

7.8 Underflow in Stake Reduction

//

Informational

Description
Proof of Concept
Score
(0.0)
Recommendation
Remediation Comment

7.9 Missing Unstake Amount validation

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment

7.10 Overflow in Operator Stake Addition

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment

7.11 Ensure APY and Cap Are Within Acceptable Ranges

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment

7.12 Missing Existing Stake Reduction Request Validation

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment

7.13 Underflow in Gas Calculation

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment

7.14 Potential Overflow in Total Supply Update in mint_claim

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment

7.15 Overflow Risk in current_reward_counter Commission Calculation

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment

7.16 Unhandled Results in verify_signature! Macro

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment

7.17 Hardcoded Gas Limit and Inconsistent Error Handling in on_register_hook

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment

7.18 Missing Era Validation in dispute Function

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment

7.19 Insecure Handling of Invalid Scalar Decoding in decode

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment

7.20 Possible Underflow on Balance Reduction

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment

7.21 Use Distinct Error for Pending Leave Round

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment

7.22 Presence Of Typos

//

Informational

Description
BVSS
Recommendation
Remediation Comment

7.23 Presence Of TODOs

//

Informational

Description
BVSS
Recommendation
Remediation Comment

7.24 Erroneous Documentation

//

Informational

Description
BVSS
Recommendation
Remediation Comment

7.25 Missing Precompiles in Tangle Workspace

//

Informational

Description
BVSS
Recommendation
Remediation Comment

7.26 Compilation Errors In `tangle-lst` Precompile

//

Informational

Description
BVSS
Recommendation
Remediation Comment

7.27 Improper Mocking And Testing Of The `tangle-lst` Precompile

//

Informational

Description
BVSS
Recommendation
Remediation Comment

7.28 Redundant Function In `services` Precompile

//

Informational

Description
BVSS
Recommendation
Remediation Comment

7.29 Redundant Operations in move_claim for Identical Addresses

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment

7.30 Lack of Validation for Identity Element in deserialize Function

//

Informational

Description
Score
(0.0)
Recommendation
Remediation Comment
References

8. Automated Testing

Halborn strongly recommends conducting a follow-up assessment of the project either within six months or immediately following any material changes to the codebase, whichever comes first. This approach is crucial for maintaining the project’s integrity and addressing potential vulnerabilities introduced by code modifications.

// Download the full report

Tangle Network Code Review

* Use Google Chrome for best results

** Check "Background Graphics" in the print settings if needed

© Halborn 2025. All rights reserved.