Audit name:

[SCA] Gable Finance / Staking / Oct2023

Date:

Oct 31, 2023

Table of Content

Introduction

Audit Summary

Document Information

System Overview

Executive Summary

Risks

Findings

Appendix 1. Severity Definitions

Appendix 2. Scope

Disclaimer

Introduction

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

Gable is a protocol creating the liquidity market on Radix DLT. Users can borrow funds without collateral in the form of flash loans, as well as earn staking rewards and interest earnings from supplying their tokens to the protocol.

    Audit Summary

    Total8.7/10
    Security Score

    10/10

    Code Quality Score

    10/10

    Test Coverage

    66.66%

    Documentation Quality Score

    10/10

    13Total Findings
    13Resolved
    0Accepted
    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

      Name
      Smart Contract Code Review and Security Analysis Report for Gable Finance
      Audited By
      Hacken
      Changelog
      10/10/2023 - Initial Review
      01/11/2023 - Second Review

    System Overview

    Gable is a protocol creating the liquidity market on Radix DLT. Users can borrow funds without collateral in the form of flash loans, as well as earn staking rewards and interest earnings from supplying their tokens to the protocol.

    Users that are staking XRD on the Gable validator receive liquid staking units (LSU tokens) that can be deposited in the flashloan pool to earn some interest.

    Borrowers that take loans repay it with some interest that is then split 50-50 between the users that deposited LSU and the smart contract owner.

    Privileged roles

    • The owner of the contract could perform multiple administrative changes, like changing interest rates, updating suppliers key value store, deposit and withdraw liquidity to the pool directly, depositing and withdrawing validator node ownership token, as well as perform unstaking and claiming operations.

    • The admin role can perform most of the owner’s actions, except from depositing and withdrawing liquidity and validator node ownership token.

    Executive Summary

    Documentation quality

    The total Documentation quality score is 10 out of 10.

    • Functional and technical requirements were provided.

    • Technical description and diagrams were provided.

    • The code implements complex calculations logic with small amounts of descriptions and requirements.

    Code quality

    The total Code quality score is 10 out of 10.

    • The development environment is configured.

    • The code is readable and easy to digest.

    • Most of the methods are described with appropriate comments.

    • Test cases are well described with requirements.

    Test coverage

    Code coverage of the project could not be directly calculated with common tools likely due to the lack of support for Scrypto. Nevertheless, taking into account the functional coverage and the number of tests available in the code repository, the tests cover approximately 66.66% of the codebase.

    • Deployment and basic user interactions are covered with tests.

    • Negative cases coverage is missed.

    • Interaction with validator and methods associated with these operation are not covered

    Security score

    Upon auditing, the code was found to contain 0 critical, 1 high, 2 medium, and 5 low severity issues. Out of these, 8 issues have been addressed and resolved, 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 8.7. This score reflects the combined evaluation of documentation, code quality, test coverage, and security aspects of the project.

    Risks

    The smart contract could be upgraded and its functionality may be changed.

    Centralization and the owner's ability to withdraw the whole liquidity from the pool might be dangerous, if his wallet/badge will be compromised.

    Findings

    Code
    Title
    Status
    Severity
    F-2023-0151
    Owner could withdraw more than he has deposited as owner_liquidity
    Fixed

    High
    F-2023-0153
    Missing validations in multiple calculations could lead to unexpected state
    Fixed

    Medium
    F-2023-0152
    Missing upper bound on interest rate change
    Fixed

    Medium
    F-2023-0158
    Test functions should be removed
    Fixed

    Low
    F-2023-0157
    Floating Language Version
    Fixed

    Low
    F-2023-0156
    Wrong limit for the size of box
    Fixed

    Low
    F-2023-0155
    Owner is able to unlock and update royalties for function calls
    Fixed

    Low
    F-2023-0154
    Macros used for debugging should not be used in production code
    Fixed

    Low
    I-2023-0042
    Former name is mentioned
    Fixed

    Observation
    I-2023-0041
    Suggestions for idiomatic code style
    Fixed

    Observation
    1-10 of 13 findings

    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

      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:

    Contracts in Scope

    flashloan-pool
    src
    events.rs - flashloan-pool/src/events.rs
    lib.rs - flashloan-pool/src/lib.rs

    Disclaimer