Introduction
We express our gratitude to the Bitlayer team for the collaborative engagement that enabled the execution of this Smart Contract Security Assessment.
Bitlayer is the layer 2 based on BitVM. It consists an EVM compatible chain/sequencer that can map BTC ecological assets and facilitate the entry of BTC users.
| title | content |
|---|---|
| Platform | EVM |
| Language | Solidity |
| Tags | ERC20, Layer2, Staking, Token Factory, MultiSig |
| Timeline | 06/03/2024 - 01/04/2024 |
| Methodology | https://hackenio.cc/sc_methodology→ |
Review Scope | |
|---|---|
| Repository | https://github.com/bitlayer-org/bitlayer-contracts→ |
| Commit | 751c34b1072b7539c1a063b38522cf7606c9268a |
Review Scope
- Commit
- 751c34b1072b7539c1a063b38522cf7606c9268a
Audit Summary
10/10
62.5%
8/10
7/10
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 | |
|---|---|
| Name | Smart Contract Code Review and Security Analysis Report for Bitlayer |
| Audited By | Niccolò Pozzolini, Kornel Światłowski |
| Approved By | Przemyslaw Swiatowiec |
| Website | https://www.bitlayer.org/→ |
| Changelog | 21/03/2024 - Preliminary Report |
| 01/04/2024 - Final Report |
Document
- Name
- Smart Contract Code Review and Security Analysis Report for Bitlayer
- Audited By
- Niccolò Pozzolini, Kornel Światłowski
- Approved By
- Przemyslaw Swiatowiec
- Website
- https://www.bitlayer.org/→
- Changelog
- 21/03/2024 - Preliminary Report
- 01/04/2024 - Final Report
System Overview
The project revolves around a blockchain framework, focusing on staking mechanisms and validator management to achieve consensus. Central components include a suite of smart contracts for staking (Staking.sol, Validator.sol), token management (BRC.sol, TokenFactory.sol), and security features (LockingContract.sol, MultiSigWallet.sol). The system allows for validator registration under a permission-based approach, transitioning to permission-less to enhance inclusivity. Validators compete for network consensus roles based on the amount of BRC tokens staked, with mechanisms for reward distribution, delegation, and penalties for non-compliance embedded within the protocol.
Privileged roles
TokenFactory.AdminRole: can create and mint ERC20 tokens
TokenFactory.OwnerRole: admin of the role AdminRole
Vault.AdminRole: can add/remove to/from whitelist, release ERC20/native tokens
Vault.OwnerRole: admin of the role AdminRole
Validator.owner is the staking contract. Most user action on Validator need to pass by the Staking contract
Staking.admin: can make validators registration permissionless, and change the foundation pool address
Executive Summary
Documentation quality
The total Documentation Quality score is 7 out of 10.
Functional requirements are present, but only at a high-level.
Technical description is not complete.
Code quality
The total Code Quality score is 8 out of 10.
The code duplicates commonly known contracts instead of reusing them.
Best practice violations.
Test coverage
Code coverage of the project is 62.5% (branch coverage).
Security score
Upon auditing, the code was found to contain 0 critical, 0 high, 0 medium, and 1 low severity issues, leading to a security score of 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 7.8. This score reflects the combined evaluation of documentation, code quality, test coverage, and security aspects of the project.
Risks
No additional risks were identified.
Findings
Code ― | Title | Status | Severity | |
|---|---|---|---|---|
| F-2024-1549 | ReStaking() and reDelegation() lead to ERC20 token lock | fixed | High | |
| F-2024-1566 | Coarse grained access control in Vault contract leads to redundant whitelist feature | accepted | Low | |
| F-2024-1554 | Missing address validation for _foundationPool in Staking contract's initialise function | fixed | Low | |
| F-2024-1335 | Missing validation of beneficiary address can lead to token locked | fixed | Low | |
| F-2024-1562 | CEI violation in validatorClaimAny function in Validator.sol contract | fixed | Observation | |
| F-2024-1558 | Public function should be external | fixed | Observation | |
| F-2024-1557 | The LazyPunishRecord struct in Staking.sol contract can be optimized | accepted | Observation | |
| F-2024-1556 | The updateActiveValidatorSet function in Staking.sol contract can be optimised | fixed | Observation | |
| F-2024-1552 | Missing decimal check for brcToken in the Staking contract | accepted | Observation | |
| F-2024-1550 | Add supply cap feature to CustomERC20 contract for enhanced security | accepted | Observation |
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 | |
|---|---|
| Repository | https://github.com/bitlayer-org/bitlayer-contracts→ |
| Commit | 751c34b1072b7539c1a063b38522cf7606c9268a |
| Whitepaper | - |
| Requirements | File name: Audit content description.pdf; SHA3: 8b659ffa690b7fa2733a7d9ab557b8d41892fd82fb96fa514f771ba6a7e64b40 |
| Technical Requirements | File name: Audit content description.pdf; SHA3: 8b659ffa690b7fa2733a7d9ab557b8d41892fd82fb96fa514f771ba6a7e64b40 |
Scope Details
- Commit
- 751c34b1072b7539c1a063b38522cf7606c9268a
- Whitepaper
- -
- Requirements
- File name: Audit content description.pdf; SHA3: 8b659ffa690b7fa2733a7d9ab557b8d41892fd82fb96fa514f771ba6a7e64b40
- Technical Requirements
- File name: Audit content description.pdf; SHA3: 8b659ffa690b7fa2733a7d9ab557b8d41892fd82fb96fa514f771ba6a7e64b40