The Hacken 2025 Yearly Security ReportCovers major Web3 breaches, their root causes, prevention insights, and key regulatory trends for 2026.
Learn more

Audit name:

[SCA] Bitlayer | ERC20 | Apr2024

Date:

May 1, 2024

Table of Content

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

Want a comprehensive audit report like this?

Introduction

We express our gratitude to the Bitlayer team for the collaborative engagement that enabled the execution of this Smart Contract Security Assessment.

Bitlayer leads with its innovative BitVM technology, offering a secure and computationally complete solution for enhancing Bitcoin's layer 2 capabilities.

titlecontent
PlatformEVM
LanguageSolidity
TagsFungible Token; Permit Token; Centralization; Upgradable
Timeline11/04/2024 - 22/04/2024
Methodologyhttps://hackenio.cc/sc_methodology

    Audit Summary

    Total8.1/10
    Security Score

    10/10

    Test Coverage

    69.23%

    Code Quality Score

    9/10

    Documentation Quality Score

    5/10

    8Total Findings
    6Resolved
    2Accepted
    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

    NameSmart Contract Code Review and Security Analysis Report for Bitlayer
    Audited ByIvan Bondar
    Approved ByGrzegorz Trawinski
    Websitehttps://www.bitlayer.org/
    Changelog17/04/2024 - Preliminary Report; 22/04/2024 - Final Report
    • Document

      Name
      Smart Contract Code Review and Security Analysis Report for Bitlayer
      Audited By
      Ivan Bondar
      Approved By
      Grzegorz Trawinski
      Changelog
      17/04/2024 - Preliminary Report; 22/04/2024 - Final Report

    System Overview

    BitLayer introduces PegToken, an innovative system operating on the EVM blockchains. This project, utilizing a UUPS upgradeable framework, is designed for dynamic token management and control.

    The files in the scope:

    • PegToken.sol:

      • This contract is an ERC20 token with extended functionalities. Key features include pausing/unpausing token transfers, blacklisting addresses, freezing/unfreezing tokens, and cross-chain burning.

      • Token minting is controlled, ensuring no pre-minting.

      • Allows cross-chain token burning, enabling wider ecosystem interoperability.

    • TokenManager.sol:

      • Central control unit for creating and managing PegToken instances.

      • Implements a robust role-based access control system with distinct roles such as Admin, Operator, Freezer, and Pauser.

      • Facilitates token creation, upgrade, minting, and management of token state (pause/unpause, freeze/unfreeze).

    Key Functionalities and Roles:

    • Token Creation and Management: Operators can dynamically create new PegToken instances with specific attributes and upgrade existing tokens.

    • Governance and Control: Admins have overarching control over the system, capable of pausing entire operations (stopTheWorld).

    • Token Minting and Supply Management: Operators control minting of PegTokens, crucial for managing the token supply and ecosystem balance.

    • Pause and Freeze Mechanisms: Pausers can temporarily halt token transactions, while Freezers can immobilize tokens in specific accounts, adding layers of control and security.

    • Cross-Chain Functionality: CrossChainBurn feature for PegToken indicates a bridge between different blockchain networks, enhancing the token's utility and reach.

    Privileged roles

    TokenManager.sol:

    • AdminRole:

      • Role: The AdminRole is a pivotal role with comprehensive control over the entire contract. Initially granted to the contract creator, this role has the highest level of authority.

      • Capabilities:

        • Authorize upgrades of the contract using _authorizeUpgrade.

        • Grant or revoke all other roles.

        • Implement the stopTheWorld feature, impacting the entire system.

    • Operator:

      • Role: Operators are responsible for the day-to-day management of the token ecosystem. They handle critical functions related to token operations.

      • Capabilities:

        • Create new token instances using createToken.

        • Upgrade token contracts with upgradeToken.

        • Set blacklist status for addresses using setBlackList.

        • Assign or revoke minter roles for each token using setMinter.

    • FreezeRole:

      • Role: Holders of the FreezeRole have control over the liquidity of tokens by managing their availability.

      • Capabilities:

        • Freeze or unfreeze tokens for specific addresses using freezeToken and unfreezeToken.

        • Recall tokens from one address to another using recall.

    • PauserRole:

      • Role: The PauserRole is designated to manage the transactional state of tokens, providing a control mechanism over their transferability.

      • Capabilities:

        • Pause or unpause token transactions on an individual token basis using pauseToken and unpauseToken.

    PegToken.sol:

    • Minter:

      • Role: Minters are addresses authorized to create new tokens in the system.

      • Capabilities:

        • Mint new tokens using mint, subject to not being blacklisted and the token not being paused or the system stopped.

    • Manager:

      • Role: The Manager is a central figure with overarching control over critical functionalities of the token.

      • Capabilities:

        • Upgrade the contract using _authorizeUpgrade.

        • Set or remove addresses from the blacklist using setBlacklist.

        • Assign or revoke minter status using setMinter.

        • Pause or unpause token transfers using pause and unpause.

        • Mint new tokens via mint.

        • Recall tokens from one account to another using recall.

        • Freeze or unfreeze tokens in an account using freeze and unfreeze.

    Executive Summary

    Documentation quality

    The total Documentation Quality score is 5 out of 10.

    • Functional requirements are partially missed.

      • Project overview is basic.

      • Roles in the system are adequately described.

      • Use cases are not explicitly described.

      • For each contract, key features are moderately detailed.

      • Interactions within the system are basically outlined.

    • Technical description is not provided.

      • Run instructions are provided.

      • Technical specification is not provided.

      • NatSpec documentation is not included.

    Code quality

    The total Code Quality score is 9 out of 10.

    • The development environment is configured.

    • Solidity Style Guide violations.

    Test coverage

    Code coverage of the project is 69.23% (branch coverage).

    • Deployment and basic user interactions are covered with tests.

    • Negative cases coverage is partially missed.

    • Interactions by several users are tested.

    Security score

    Upon auditing, the code was found to contain 0 critical, 0 high, 1 medium, and 1 low severity issues, leading to a security score of 9 out of 10. After addressing findings during the initial review, the security score was subsequently raised to 10 out of 10.

    All identified issues are detailed in the “Findings” section of this report.

    Summary

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

    Risks

    Single Points of Failure and Control: The project is fully or partially centralized, introducing single points of failure and control. This centralization can lead to vulnerabilities in decision-making and operational processes, making the system more susceptible to targeted attacks or manipulation.

    Administrative Key Control Risks: The digital contract architecture relies on administrative keys for critical operations. Centralized control over these keys presents a significant security risk, as compromise or misuse can lead to unauthorized actions or loss of funds.

    Single Entity Upgrade Authority: The token ecosystem grants a single entity the authority to implement upgrades or changes. This centralization of power risks unilateral decisions that may not align with the community or stakeholders' interests, undermining trust and security.

    Flexibility and Risk in Contract Upgrades: The project's contracts are upgradable, allowing the administrator to update the contract logic at any time. While this provides flexibility in addressing issues and evolving the project, it also introduces risks if upgrade processes are not properly managed or secured, potentially allowing for unauthorized changes that could compromise the project's integrity and security.

    Absence of Upgrade Window Constraints: The contract suite allows for immediate upgrades without a mandatory review or waiting period, increasing the risk of rapid deployment of malicious or flawed code, potentially compromising the system's integrity and user assets.

    Compatibility and Stability Risks with Mixed Contract Imports: The project utilizes a combination of upgradable and non-upgradable contract imports from OpenZeppelin, which can lead to compatibility issues and affect the stability of the contract in an upgradeable context. This mixing may restrict the full advantages of the upgradeable pattern, potentially leading to inefficiencies and heightening security risks. Proper management and continuous review are essential to mitigate these risks and ensure consistent functionality across different contract versions.

    Findings

    Code
    Title
    Status
    Severity
    F-2024-2131Insufficient Check for Blacklisted Users in TransferFrom Function
    fixed

    Medium
    F-2024-2154Unvalidated Chain ID in crossChainBurn Function
    fixed

    Low
    F-2024-2130Hardcoded EIP712 Domain Name in PegToken Initialization
    fixed

    Observation
    F-2024-2129Shadowing of State Variables in initialize Function
    fixed

    Observation
    F-2024-2128Inconsistent Use of Upgradable and Non-Upgradable OpenZeppelin Contracts
    accepted

    Observation
    F-2024-2127Unused Import
    fixed

    Observation
    F-2024-2125Public functions not called by the contract should be declared external instead
    fixed

    Observation
    F-2024-2124Floating Pragma
    accepted

    Observation
    1-8 of 8 findings

    Identify vulnerabilities in your smart contracts.

    Appendix 1. Severity Definitions

    When auditing smart contracts, Hacken is using a risk-based approach that considers Likelihood, Impact, Exploitability and Complexity metrics to evaluate findings and score severities.

    Reference on how risk scoring is done is available through the repository in our Github organization:

    Severity

    Description

    Critical
    Critical vulnerabilities are usually straightforward to exploit and can lead to the loss of user funds or contract state manipulation.

    High
    High vulnerabilities are usually harder to exploit, requiring specific conditions, or have a more limited scope, but can still lead to the loss of user funds or contract state manipulation.

    Medium
    Medium vulnerabilities are usually limited to state manipulations and, in most cases, cannot lead to asset loss. Contradictions and requirements violations. Major deviations from best practices are also in this category.

    Low
    Major deviations from best practices or major Gas inefficiency. These issues will not have a significant impact on code execution, do not affect security score but can affect code quality score.
    • Severity

      Critical

      Description

      Critical vulnerabilities are usually straightforward to exploit and can lead to the loss of user funds or contract state manipulation.

      Severity

      High

      Description

      High vulnerabilities are usually harder to exploit, requiring specific conditions, or have a more limited scope, but can still lead to the loss of user funds or contract state manipulation.

      Severity

      Medium

      Description

      Medium vulnerabilities are usually limited to state manipulations and, in most cases, cannot lead to asset loss. Contradictions and requirements violations. Major deviations from best practices are also in this category.

      Severity

      Low

      Description

      Major deviations from best practices or major Gas inefficiency. These issues will not have a significant impact on code execution, do not affect security score but can affect code quality score.

    Appendix 2. Scope

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

    Scope Details

    Repositoryhttps://github.com/bitlayer-org/peg-tokens-contract
    Commitf0d2a54db1648ec76b55c1dcd227a9af16de4c8b
    Whitepaper
    RequirementsAUDIT.md
    Technical RequirementsREADME.md

    Contracts in Scope

    contracts
    PegToken.sol - contracts › PegToken.sol
    TokenManager.sol - contracts › TokenManager.sol

    Disclaimer