Skip to content
$1,000,000 in security audit grants are live now, Apply here →

Security review · September 2024

Config Syncer

for GMX

Guardian's review of Config Syncer for GMX, published September 2024. The report records 7 findings across 2 review rounds, including 7 low.

Published
Review window
August 20 to 28, 2024
Rounds
Main Review, Remediation Review
Language
Solidity
Chains
Arbitrum, Avalanche
Sector
Perpetuals
  • 0 Critical
  • 0 High
  • 0 Medium
  • 7 Low
  • 0 Informational

7 resolved

Scope

Findings 7

Main Review

5 findings · August 20, 2024
  1. L-01 Low Duplicate allUpdateTypes Entries Validation Resolved
    Location
    RiskOracle.sol: 59
    Round
    Main Review

    Description

    In the constructor for the RiskOracle contract on Arbitrum Sepolia https://sepolia.arbiscan.io/address/0x526d6789fCb503F2F898f45912A7a24fe9dd48e4#code, a list of initialUpdateTypes may be passed where there are duplicate updateType strings. In this case the updateType string will be pushed to the allUpdateTypes list multiple times.

    This can lead to unexpected behavior for any systems relying on the allUpdateTypes list as it will have duplicate entries.

    Recommendation

    Consider validating that no duplicate entries have been made for the updateTypes in the RiskOracle constructor.

  2. L-02 Low Incorrect previousValue Stored Logical Error Resolved
    Location
    RiskOracle.sol: 151
    Round
    Main Review

    Description

    When creating the newUpdate object to be stored the previousValue is declared as the direct previous update no matter what market or updateType the previous update acted upon.

    This is incorrect or at least misleading as the previousValue serves little to no value if it merely references the previous update of any market/parameter. Instead the previousValue should pertain to the previous value of the market and updateType combination.

    Recommendation

    Query the last update for the particular market and parameter type via the latestUpdateIdByMarketAndType mapping and store this value as the previousValue.

  3. L-03 Low getLatestUpdateByType DoS DoS Resolved
    Location
    RiskOracle.sol: 170
    Round
    Main Review

    Description

    The getLatestUpdateByType function loops backwards through the updateHistory to find the most recent matching entry for the updateType.

    This can lead to an out of gas DoS for integrating contracts if a particular updateType has been performed before many other subsequent updates.

    Recommendation

    Be aware of this risk and avoid using the getLatestUpdateByType function in a Smart Contract. Otherwise consider refactoring the RiskOracle such that it stores the latestUpdateByType in a mapping so it can be easily queried.

  4. L-04 Low Lacking Market Validation Validation Resolved
    Location
    Global
    Round
    Main Review

    Description

    Throughout the GMX contracts a common pattern for configuration keys is to include the market which is being targeted in the additional key data.

    In the RiskOracle and ConfigSyncer it is assumed that the market which an update is supplied for is the one which it’s provided additionalData includes, however there is no validation to enforce this.

    Recommendation

    Be aware of this risk and put in place validations off-chain such that trusted parties will not commit updates for markets which are not included in the additionalData provided.

    Otherwise consider implementing validations at the contract level which do not allow market configurations which do not agree with the market address provided in the additionalData. Though this is likely not realistic to validate on-chain due to the many existing arbitrary key datas + new keys which will be introduced in the future.

  5. L-05 Low General Key Risk Validation Resolved
    Location
    Config.sol
    Round
    Main Review

    Description

    The following keys are not validated in the _validateRange function and belong to uint values which can potentially DoS or otherwise cause loss or harm to GMX V2 users.

    • MAX_SWAP_PATH_LENGTH
    • MIN_POSITION_SIZE_USD
    • MAX_POSITION_IMPACT_FACTOR_FOR_LIQUIDATIONS
    • MAX_ORACLE_PRICE_AGE
    • MAX_ORACLE_TIMESTAMP_RANGE
    • ORACLE_TIMESTAMP_ADJUSTMENT
    • MAX_ORACLE_REF_PRICE_DEVIATION_FACTOR
    • REQUEST_EXPIRATION_TIME
    • MIN_COLLATERAL_FACTOR_FOR_OPEN_INTEREST_MULTIPLIER
    • POSITION_IMPACT_FACTOR
    • MAX_POSITION_IMPACT_FACTOR
    • SWAP_IMPACT_FACTOR
    • MAX_AUTO_CANCEL_ORDERS
    • RESERVE_FACTOR
    • OPEN_INTEREST_RESERVE_FACTOR
    • MIN_FUNDING_FACTOR_PER_SECOND
    • THRESHOLD_FOR_STABLE_FUNDING
    • THRESHOLD_FOR_DECREASE_FUNDING
    • PRICE_FEED_HEARTBEAT_DURATION
    • All gas related keys

    Recommendation

    Carefully consider the risk of each of these keys being configured by the RiskOracle without any range validation. Where appropriate add the corresponding validations that the configured values are within an expected range.

Remediation Review

2 findings · August 28, 2024
  1. L-01 Low Missing Allowed Keys Warning Resolved
    Location
    ConfigSyncer.sol
    Round
    Remediation Review

    Description

    In the _initAllowedBaseKeys several keys have been excluded which are present in the MockRiskOracle file.

    Missing Keys from allowedBaseKeys:

    • SWAP_FEE_FACTOR
    • ATOMIC_SWAP_FEE_FACTOR
    • TOKEN_TRANSFER_GAS_LIMIT
    • MIN_COLLATERAL_FACTOR
    • MIN_COLLATERAL_FACTOR_FOR_OPEN_INTEREST_MULTIPLIER
    • MAX_PNL_FACTOR
    • MIN_PNL_FACTOR_AFTER_ADL
    • FUNDING_FACTOR
    • FUNDING_EXPONENT_FACTOR
    • THRESHOLD_FOR_STABLE_FUNDING
    • THRESHOLD_FOR_DECREASE_FUNDING
    • POSITION_FEE_FACTOR
    • MAX_POSITION_IMPACT_FACTOR_FOR_LIQUIDATIONS
    • MAX_POSITION_IMPACT_FACTOR

    These keys may be desired to be configured yet have not been allowed in the _initAllowedBaseKeys function.

    Also notably, The MAX_PNL_FACTOR key is present in the _validateMarketInData function, but not in the _initAllowedBaseKeys function.

    Recommendation

    Consider adding some or all of these keys to the _initAllowedBaseKeys function, and be aware of the risk if they are not currently validated in the Config._validateRange function.

  2. L-02 Low Additional Allowed Keys Warning Resolved
    Location
    ConfigSyncer.sol
    Round
    Remediation Review

    Description

    A few keys have been marked as allowed which are not included in the MockRiskOracle contract. This may be entirely expected, this finding only serves to point out this detail out of an abundance of caution that some keys may be unexpectedly allowed.

    • OPTIMAL_USAGE_FACTOR
    • BASE_BORROWING_FACTOR
    • ABOVE_OPTIMAL_USAGE_BORROWING_FACTOR

    Recommendation

    Consider if these keys are expected to be allowed in the ConfigSyncer.

More from GMX

All 44 reports
  1. Timelock Updates

    4 findings 4 findings: 3 low, 1 informational
  2. LayerZeroProvider Routing

    1 finding 1 finding: 1 medium
  3. Open Interest Updates

    5 findings 5 findings: 2 medium, 3 low
  4. Updates Branch

    2 findings 2 findings: 2 low

Put your code through the same review.

This review started with a conversation about scope. Tell us what you are building and we will plan yours with you.

Get a quote