Q2 2026 Security & Compliance Report67 incidents, $764M in losses, 88% from operational failures.
Get the report →

Audit name:

[SCA] Aark Digital | DEX | Apr2023

Date:

Apr 26, 2023

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 V2X / Aark Digital team for the collaborative engagement that enabled the execution of this Smart Contract Security Assessment.

Aark Digital is the first-of-its-kind Leverage Everything Perpetual DEX for professional traders/LPs on Arbitrum. Their vision is to find the right formula to incorporate the best of DEX and CEXs. At its end, Aark will bring all onchain assets into a single liquidity pool to provide an unprecedented leverage experience.

titlecontent
PlatformArbitrum
LanguageSolidity
TagsPerpetual DEX, LP
Timeline06/04/2023 - 25/04/2023
Methodologyhttps://hackenio.cc/sc_methodology→

    Review Scope

    Repositoryhttps://github.com/Aark-Digital/aark-contracts→
    Commitfdb0048638f4fe9c787abae3f76aaa82b3b15833

    Audit Summary

    Total8.5/10
    Security Score

    10/10

    Test Coverage

    81.74%

    Code Quality Score

    7/10

    Documentation Quality Score

    8/10

    20Total Findings
    4Resolved
    0Accepted
    2Mitigated

    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 V2X / Aark Digital
    Audited ByHacken
    Websitehttps://aark.digital/→
    Changelog06/04/2023 – Initial Review
    25/04/2023 – Second Review
    • Document

      Name
      Smart Contract Code Review and Security Analysis Report for V2X / Aark Digital
      Audited By
      Hacken
      Changelog
      06/04/2023 – Initial Review
      25/04/2023 – Second Review

    System Overview

    A platform that aims to provide a perpetual DEX with the following characteristics:

    • Providing CEX level of UI/UX.

    • Virtual liquidity pool, quoted in USD.

    • Stability against market conditions.

    • Fair distribution of rewards to community.

    Aark Digital provides clear solutions to the problems of the current perpetual DEX market:

    For Traders:

    • More than 50 Trading Pairs.

    • Cross-Margin Trading.

    • Any Asset Collateral.

    • Continuous Funding Fee.

    For Liquidity Providers:

    • Leveraged Liquidity Providing.

    • Delta neutral LP (preserving collateral quantity).

    User Interaction

    Request a futures market order

    • In order to request a futures market order, users don’t need to have any collateral. The balance is not checked in the order creation function.

    • Market orders have to be settled in 60 seconds by the OFFCHAINFEEDERROLE. Otherwise, orders will be canceled.

    Offchain Feeder Interaction

    Futures market order settling

    • User’s tier config is obtained and the user’s leverage is checked according to that. Also, a fee rate is calculated depending on the tier level. This fee is taken as a percentage from the paid value and includes the fixed fee to the protocol.

    • Only the admin is allowed to set tier and the corresponding leverages. The leverage can be 255 at maximum.

    • Global pending funding fee, which is the amount of funding paid or received by all users with open positions in the market is updated here. globalPendingFundingFee = (Market funding rate x Time passed after the last accumulation) x Open Interest.

    • Paid value is calculated. For long positions (-), short positions (+). paid value= (-/+)order quantity x entry price.

    • User’s position gets updated.

    • Max leverage is checked if needed.

    User Interaction

    Request a futures limit order

    • In order to request a futures limit order, users do not need to have any collateral. The balance is not checked in the order creation function.

    • Limit orders have to be settled in 604800 seconds (7 days) by any trader. Otherwise, orders will be canceled.

    Offchain Feeder Interaction

    Futures limit order settling

    For both maker and taker, settlement(following lines) is executed.

    • User’s tier config is obtained and the user’s leverage is checked according to that. Also, a fee rate is calculated depending on the tier level. This fee is taken as a percentage from the paid value and includes the fixed fee to the protocol.

    • Only the admin is allowed to set tier and the corresponding leverages. The leverage can be 255 at maximum.

    • Global pending funding fee, which is the amount of funding paid or received by all users with open positions in the market is updated here. globalPendingFundingFee = (Market funding rate x Time passed after the last accumulation) x Open Interest.

    • Paid value is calculated. For long positions (-), short positions (+). paid value= (-/+)order quantity x entry price.

    • User’s position gets updated.

    • Max leverage is checked if needed.

    • Funding rate is updated since it is a limit order.

    Funding Fee & Funding Rate

    A fee that is paid by one side of a futures contract to the other side at regular intervals. This fee is intended to keep the price of the futures contract aligned with the underlying asset's spot price.

    • Funding Rate = (market price- index price) * amplifier / 3600 / 8

    Funding rate is updated in every futures market order settlement.

    Skewness

    Skewness where a value of 1 means the market is long-skewed (open interest is biased towards buying = there are more buyers than sellers) and a value of 0 means it is short-skewed (open interest is biased towards selling = there are more sellers than buyers).

    Market Price

    The market price represents the expected price at which a futures contract would be traded in the market. Market price is determined based on various factors, including the index price (current LP price of the underlying asset), net open interest (total number of outstanding contracts), and depth factor (a factor that reflects the market's liquidity or trading depth).

    • Mark Price = Index Price + Premium Premium = Index Price * (long open interest - short open interest) / depth factor / 100

    Settlement Price

    The settlement price is the price at which a futures contract is settled at the end of its term. It is used to determine the final settlement amount that one party pays to the other. The settlement price is calculated based on the market price.

    • Settlement Price = Index Price + Premium

    • Premium = Index Price * (long open interest - short open interest + order quantity / 2) / depth factor / 100

    Liquidating a position

    Every user can try to liquidate a position. A liquidator bonus gets paid as an incentive. Account value(usd balance + total collateral value) must be negative value or at least less than the maintenance margin to be able to be liquidated.

    Futures Market Orders Settlement

    In the futures system, market orders are settled at a price provided by the off-chain feeder role, which is then verified by the STORK oracle, which is out-of-scope. There is no slippage limit for orders.

    The files in the scope

    • MasterRouter.sol - The MasterRouter contract serves as the main entry point for interacting with the system.

    • FuturesRouter.sol - Inherited by MasterRouter.sol. The FuturesRouter serves as the main entry point for interacting with the Futures system.

    • LpRouter.sol - Inherited by MasterRouter.sol. The LpRouter contract provides functions for interacting with the LP Manager contract.

    • Vault.sol - This contract implements the IVault interface and manages the deposit and withdrawal of assets, as well as the accumulation and withdrawal of protocol fees.

    • FuturesManager.sol - This contract manages the settlement of futures orders, updates user and market positions, and calculates various values related to the orders.

    • LpManager.sol - This contract manages liquidity providing and lp collateral for protocol.

    • CommonManager.sol - Contract containing the common business logic for Futures and LP Contract management.

    • InsuranceManager.sol - A smart contract that manages the insurance fund for a decentralized exchange. This contract allows LPs and futures traders to add and remove liquidity from the insurance fund, and allows the insurance fund to perform subrogation on LPs and futures traders.

    • PriceOracle.sol - This contract is used to store and retrieve price feeds. It supports both internal and external oracles.

    • FuturesManagerStorage.sol - This contract manages the storage variables for the FuturesManager contract.

    • LpManagerStorage.sol - This contract stores the state variables and common functions used by the LpManager contract and its child contracts.

    • InsuranceStorage.sol - Contract to manage insurance fund storage.

    • ReserveStorage.sol - Storage contract for managing reserve configuration data.

    • TierStorage.sol - Contract for managing tier configuration of user tier data.

    • CommonManagerStorage.sol - Storage used by LpManager.sol and FuturesManager.sol.

    • Observer.sol - Contract that maintains a cache of valid contract addresses, to be used by other contracts for calling external functions.

    • AddressCache.sol - A contract that stores the addresses of other contracts in the system.

    • AccessController.sol - This contract controls access and roles.

    • IVault.sol - Interface of the Vault contract.

    • IObserver.sol - Interface of the Observer contract.

    • IAddressCache.sol - Interface of the AddressCache contract.

    • ICollateralManager.sol - Interface of CollateralManager contract. Inherited by FuturesManager.sol and LpManager.sol.

    • IFuturesManager.sol - Interface of FuturesManager contract. Inherited by FuturesManager.sol.

    • IInsuranceManager.sol - Interface of InsuranceManager contract.

    • ILpManager.sol - Interface of LPManager contract. Inherited by LpManager.sol.

    • IAggregatorV3Interface.sol - Chainlink interface. Inherited by priceOracle.sol.

    • IPriceOracle.sol - Interface of PriceOracle contract. Inherited by PriceOracle.sol.

    • IFuturesRouter.sol - Interface of FuturesRouter contract. Inherited by FuturesRouter.sol.

    • IWETH.sol - WETH interface.

    • IToken.sol - ERC20 interface.

    • DataTypes.sol - A library of data types.

    • CollateralLogic.sol - Library to manage collateral logic.

    • FundingFeeLogic.sol - Library for calculating and updating funding fees for perpetual markets.

    • FuturesLogic.sol - Library containing the core logic for the futures manager contract.

    • InsuranceLogic.sol - Library for updating the share value of an insurance fund based on user deposits and withdrawals.

    • LpLogic.sol - Library containing the logic for managing liquidity provider positions in a system.

    • ValidationLogic.sol - Library containing validation logic to check leverage and slippage not to exceed limits.

    • MathUtil.sol - A library for math operations with decimal precision.

    • AccountUpdator.sol - A library that manages updating user’s account data.

    • MarketUpdator.sol - A library that manages updating markets’ accumulating funding factor and config.

    • PositionUpdator.sol - A library that manages updating users positions’ quantity and last accumulated funding factor variables of a specific market.

    • FuturesOrderParser.sol - A library that provides functions to extract and modify the values in bit ranges of different parameters of the futures orders that are encoded in uint256 data variable.

    • LiquidationConfig.sol - A library that provides functions to extract and modify the values in bit ranges of different parameters such as liquidation bonus ratio and maint margin fraction that are encoded in uint256 data variable.

    • ManagerGlobalConfig.sol - A library that provides functions to extract and modify the values in bit ranges of different parameters, revenue ratio and insurance bonus that are encoded in uint256 data variable.

    • MarketConfig.sol - A library that provides functions to extract and modify the values in bit ranges of different parameters, depth factor, funding rate update timestamp and OI hard cap that are encoded in uint256 data variable.

    • ReserveConfig.sol - A library that provides functions to extract and modify the values in bit ranges of different parameters, such as oracle ID, initial weight, total weight and liquidation bonus ratio that are encoded in uint256 data variable.

    • ReserveSummaryConfig.sol - A library that provides functions to extract and modify the values in bit ranges of different parameters, frozen and allowance that are encoded in uint256 data variable.

    • TierConfig.sol - A library that provides functions to extract and modify the values in bit ranges of different parameters of tier config that are encoded in uint256 data variable.

    • UserConfig.sol - A library that provides functions to extract and modify the values in bit ranges of different parameters of user config that are encoded in uint256 data variable.

    • UserStatus.sol - A library that provides functions to extract and modify the values in bit ranges of different parameters of user status that are encoded in uint256 data variable.

    • PriceOracleStorage.sol - This contract is used to store and retrieve price feeds.

    • FeedVerifier.sol - A contract that verifies the signed price from Stork oracle.

    • IFeedVerifier.sol - The interface of FeedVerifier.sol.

    Privileged roles

    MasterRouter

    \-Owner:

    • Can initialize the contract (only once).

    FuturesRouter

    \-Default Admin Role:

    • Can set the base fee for futures orders.

    • Can withdraw the remaining base fees from the contract.

    \-Off-Chain feeder Role:

    • Can settle pending futures orders for a given market.

    FuturesManager

    \-Owner:

    • Can initialize the contract (only once).

    \-Router:

    • Can settle order (futures).

    • Can settle limit order.

    • Can add collateral to a user's account.

    • Can remove collateral from a user’s position.

    • Can liquidate a user’s position.

    • Can liquidate a user's collateral to repay a specified amount of debt.

    • Can execute a deleverage order.

    \-Insurance Manager:

    • Can perform subrogation on behalf of a liquidated account.

    LpManager:

    \-Owner:

    • Can initialize the contract (only once).

    \-Router:

    • Can set the price of a LP position and settle the order.

    • Can add collateral to a user's account.

    • Can remove collateral from a user’s position.

    • Can liquidate a leveraged position of a user, transferring the collateral and notional amount to the liquidator.

    • Can liquidate a user's collateral at market price.

    \-Insurance Manager:

    • Can initiate subrogation for a given user with a specified maximum value.

    CommonManager

    \-User Tier Manager Role:

    • Can set user tier.

    InsuranceManager

    \-Owner:

    • Can initialize the contract (only once).

    \-Managers:

    • Can receive a liquidation bonus and add it to the insurance fund's value.

    Vault

    \-Default Admin Role:

    • Can withdraw the protocol fee.

    \-Managers:

    • Can initiate a withdrawal request.

    • Can initiate a deposit request.

    • Can cumulate the protocol fee.

    \-Owner:

    • Can initialize the contract (only once).

    FuturesManagerStorage

    \-Default Admin Role:

    • Can create or update a market configuration and liquidation configuration.

    \-Depth Factor Manager Role:

    • Can update the depth factor for a given market.

    InsuranceStorage

    \-Default Admin Role:

    • Can update the withdrawal factors.

    ReserveStorage

    \-Default Admin Role:

    • Can store the token address that will be treated as USD in the protocol.

    • Can add a new reserve to the protocol with the specified configuration.

    • Can edit the configuration of an existing reserve.

    TierStorage

    \-Default Admin Role:

    • Can set the fee rate for a given tier.

    • Can set the maximum leverage for a given tier.

    PriceOracle

    \-Default Admin Role (Owner):

    • Can initialize the contract (only once).

    • Can switch the given oracle's feed mode to internal.

    • Can switch the given oracle's feed mode to external.

    • Can set the Chainlink price feed address for the given oracle ID.

    \-Off-Chain feeder Role:

    • Can set the price for the given oracle ID.

    Observer

    \-Default Admin Role (Owner):

    • Can initialize the contract (only once).

    • Can set the address of the futures manager contract.

    • Can set the address of the lp manager contract.

    • Can set the address of the price oracle contract.

    • Can set the address of the vault contract.

    • Can set the address of the MasterRouter contract.

    • Can set the address of the InsuranceManager contract.

    • Can set the address of the Feed verifier contract.

    AddressCache

    \-Observer

    • Can store the addresses of the contracts in the AddressCache contract.

    Executive Summary

    Documentation quality

    The total Documentation quality score is 8 out of 10.

    • NatSpecs are very good overall but missing in some libraries.

    • Technical documentation is good but limited to entry contracts.

    • Functional documentation is good.

    • There are some contradictions in NatSpecs.

    Code quality

    The total Code quality score is 7 out of 10.

    • Development environment is set up correctly.

    • Solidity style guidelines are followed perfectly.

    • There are some unused code and other code quality issues.

    Test coverage

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

    • Negative cases coverage is missed.

    • Interactions by several users are not tested thoroughly.

    • Some tests are not implemented correctly (ex : “Limit order canceled due to time expiration”).

    Security score

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

    Risks

    The project is using Gnosis Safe Multi-Sigs to handle access role management. The Gnosis Safe Multi-Sigs implementation is not in the scope of this audit and, therefore, can not be verified in this audit.

    The project is using OpenZeppelin Defender Timelock to handle access role management. The OpenZeppelin Defender Timelock implementation is not in the scope of this audit and, therefore, can not be verified in this audit.

    The protocol has developed its own market maker model to implement price impact. The price is calculated off-chain. In order to avoid price manipulation, this off-chain price is validated using STORK oracles. However, the calculation of this price and the oracle can not be verified in this audit as it is done off-chain and is not in the scope of this audit.

    Orders requested by the users are settled via an off-chain mechanism. Therefore, the whole system relies on off-chain centralized management, which is not in the scope of this audit.

    Findings

    F-2023-1014 Requirements Violation
    Status
    mitigated
    Severity

    Critical
    F-2023-1013Data Consistency - Centralized Price Mechanism
    Status
    fixed
    Severity

    Critical
    F-2023-1016 Undocumented Behavior
    Status
    mitigated
    Severity

    High
    F-2023-101Undocumented Behavior
    Status
    fixed
    Severity

    High
    F-2023-101Interfaces Mismatch
    Status
    fixed
    Severity

    Medium
    F-2023-1017Inefficient Gas Model - Modifier with a Lot of Logic
    Status
    fixed
    Severity

    Medium
    F-2023-1032Missing Event for Critical Value Update
    Status
    unfixed
    Severity

    Low
    F-2023-1031Redundant Struct Declaration
    Status
    unfixed
    Severity

    Low
    F-2023-1030Variables that Can Be Declared Immutable
    Status
    unfixed
    Severity

    Low
    F-2023-1029 Redundant Inherit
    Status
    unfixed
    Severity

    Low
    Code
    ―
    Title
    Status
    Severity
    F-2023-1014 Requirements Violation
    mitigated

    Critical
    F-2023-1013Data Consistency - Centralized Price Mechanism
    fixed

    Critical
    F-2023-1016 Undocumented Behavior
    mitigated

    High
    F-2023-101Undocumented Behavior
    fixed

    High
    F-2023-101Interfaces Mismatch
    fixed

    Medium
    F-2023-1017Inefficient Gas Model - Modifier with a Lot of Logic
    fixed

    Medium
    F-2023-1032Missing Event for Critical Value Update
    unfixed

    Low
    F-2023-1031Redundant Struct Declaration
    unfixed

    Low
    F-2023-1030Variables that Can Be Declared Immutable
    unfixed

    Low
    F-2023-1029 Redundant Inherit
    unfixed

    Low
    1-10 of 20 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/Aark-Digital/aark-contracts→
    Commitfdb0048638f4fe9c787abae3f76aaa82b3b15833
    WhitepaperNot provided
    RequirementsProvided→
    Technical RequirementsProvided→

    Contracts in Scope

    contracts
    core
    common
    AddressCache.sol - contracts › core › common › AddressCache.sol
    FeedVerifier.sol - contracts › core › common › FeedVerifier.sol
    Observer.sol - contracts › core › common › Observer.sol
    Vault.sol - contracts › core › common › Vault.sol
    AccessController.sol - contracts › core › common › AccessController.sol
    managers
    CommonManager.sol - contracts › core › managers › CommonManager.sol
    FuturesManager.sol - contracts › core › managers › FuturesManager.sol
    InsuranceManager.sol - contracts › core › managers › InsuranceManager.sol
    LpManager.sol - contracts › core › managers › LpManager.sol
    price-oracle
    PriceOracle.sol - contracts › core › price-oracle › PriceOracle.sol
    router
    FuturesRouter.sol - contracts › core › router › FuturesRouter.sol
    LpRouter.sol - contracts › core › router › LpRouter.sol
    MasterRouter.sol - contracts › core › router › MasterRouter.sol
    storages
    CommonManagerStorage.sol - contracts › core › storages › CommonManagerStorage.sol
    FuturesManagerStorage.sol - contracts › core › storages › FuturesManagerStorage.sol

    Disclaimer