Audit name:

[L1] MANTRA Chain / Blockchain Audit / Jun2024

Date:

Nov 8, 2024

Table of Content

Introduction

Audit Summary

System Overview

Risks

Findings

Appendix 1. Severity Definitions

Appendix 2. Scope

Disclaimer

Introduction

We express our gratitude to the MANTRA Chain team for the collaborative engagement that enabled the execution of this Blockchain Protocol Security Assessment.

MANTRA Chain is a Layer 1 blockchain meticulously engineered to navigate the complex intersection of decentralized finance and regulatory compliance. It offers a permissionless environment for deploying applications that necessitate adherence to financial regulations. Built on the robust Cosmos SDK and leveraging the Inter-Blockchain Communication protocol (IBC), MANTRA Chain ensures fast and secure transactions both on-chain and cross-chain.

A standout feature is its native Decentralized ID (DID) system, which streamlines user onboarding and KYC/AML procedures using non-transferable Soulbound NFTs. This innovative approach enhances security and simplifies compliance for both users and developers. Furthermore, the chain's hybrid DEX combines the benefits of automated market making with an order book model, offering greater capital efficiency and enhanced trading experiences.

  • Document

    Name
    Blockchain Protocol Review and Security Analysis Report for MANTRA Chain
    Audited By
    Tanuj Soni
    Approved By
    Nino Lipartiia
    Changelog
    06/09/2024 - Preliminary Report
    Changelog
    08/11/2024 - Final Report
    Platform
    Mantra Chain
    Language
    Golang
    Tags
    Cosmos SDK, DID, Soulbound NFT, Hybrid DEX

Audit Summary

16Total Findings
2Resolved
14Accepted
0Mitigated

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

Documentation quality

  • User-facing documentation for use-cases and features is readily available and well-developed.

  • x/liquidity, x/lpfarm, x/marketmakerand x/coinfactory benefit from detailed documentation inherited from Crescent Network and Osmosis.

  • The x/did, x/token, and x/guard modules have adequate technical documentation for developers.

  • Technical implementation details within the x/txfees module could be enhanced.

  • Documenting KYC/whitelisting procedures would be beneficial.

  • A comprehensive technical document outlining the purpose and interactions of each module within the system is necessary for a holistic overview.

Code quality

  • The codebase adheres to established Go programming best practices, promoting maintainability and performance.

  • x/liquidity, x/lpfarm, x/marketmaker and x/coinfactory inherit and maintain high code quality standards from established projects like Crescent Network and Osmosis.

  • Several functions exhibit high Cyclomatic Complexity, Excessive Function Length, and Deeply Nested Conditional Structures, suggesting potential areas for refactoring and simplification.

  • The x/token module contains redundant code.

Architecture quality

  • Mantra Chain utilizes the Cosmos SDK, a mature and widely-adopted framework for building blockchains, contributing to a robust technical foundation.

  • The project leverages modules from established projects, adapting them to Mantra's specific use case, potentially accelerating development and enhancing reliability.

  • The implementation of DID and soul-bound NFTs for identity verification demonstrates a commitment to security and user control over their digital identity.

  • The guard module's capability to assign multiple permission types to whitelisted addresses showcases flexibility in access control.

  • The current architecture grants the chain administrator excessive control over the x/guard module, undermining decentralized governance principles.

Test coverage

  • E2E test cases exist to validate positive and some negative scenarios, providing valuable insights into the interaction of different modules.

  • Modules adopted from other projects have brought along their existing unit tests, offering a degree of pre-existing coverage.

  • Unit test coverage is currently low and could be improved.

System Overview

Mantrachain leverages the Cosmos SDK for its core architecture and incorporates various modules for specific functionalities. Some modules are inherited and adapted from existing projects, while others are developed in-house. The system supports decentralized identity management, user permission control, liquidity provision, and market-making activities.

  • x/coinfactory: Enables permissionless token creation.

  • x/did: Manages decentralized identifiers (DIDs) for identity verification.

  • x/guard: Handles user privileges and access control.

  • x/liquidity: Core module for creating and managing liquidity pools.

  • x/lpfarm: Implements liquidity provider (LP) farming functionalities.

  • x/marketmaker: Facilitates market maker registration and incentive distribution.

  • x/token: Manages token-related operations.

  • x/txfees: Configures fee tokens and handles gas fee collection.

Risks

Centralization Risk: The use of a single externally owned account (EOA) as chain admin and the x/guard module for access control introduces centralization. If compromised, it could enable unauthorized control over critical functions. While this setup is intended as a temporary measure for development, it deviates from decentralization principles. The planned Role-Based Access Control (RBAC) aims to distribute control to mitigate this risk.

Audit Coverage Gaps: The modules x/airdrop, x/bridge, and x/rewards were removed from the audit scope during the process. Despite this exclusion, the x/airdrop and x/bridge modules remain in the codebase. Their lack of review presents potential risks, as undiscovered vulnerabilities in these modules could impact the system's integrity or lead to exploitation.

Findings

Code
Title
Status
Severity
F-2024-4346
Critical Vulnerability in Dependencies
Fixed

Critical
F-2024-5508
Security Vulnerabilities in CosmWasm
Fixed

High
F-2024-5511
Unchecked Fee Manipulation
Accepted

Medium
F-2024-5641
Admin Role Decentralization Leads to Non-Terminable Private Plans
Accepted

Low
F-2024-5510
Single-Step Ownership Transfer Risks
Accepted

Low
F-2024-5469
Misdirection of Collected Fees to an EOA
Accepted

Low
F-2024-5456
Insufficient Validation and Lack of FeeToken Liveness Checks
Accepted

Low
F-2024-5313
Centralized Control and Elevated Admin Privileges
Accepted

Low
F-2024-5911
Privilege Revocation and Limit Order Conflict
Accepted

Observation
F-2024-5910
Missing Explicit Whitelisted Address Checks in DEX Trading Functions
Accepted

Observation
1-10 of 16 findings

Appendix 1. Severity Definitions

  • 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 components from the provided repository:

Components in Scope

Modules:

  1. x/coinfactory

  2. x/did

  3. x/guard

  4. x/liquidity

  5. x/lpfarm

  6. x/marketmaker

  7. x/token

  8. x/txfees

Assets in Scope

x
coinfactory - x/coinfactory
txfees - x/txfees
liquidity - x/liquidity
guard - x/guard
lpfarm - x/lpfarm
token - x/token
dependencies - dependencies
CosmWASM - CosmWASM
Code Quality - Code Quality
Test Coverage - Test Coverage
Dependencies - Dependencies

Disclaimer