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
Scope
Findings 7
Main Review
5 findings · August 20, 2024-
L-01 Low Duplicate allUpdateTypes Entries Validation Resolved
Description
In the constructor for the
RiskOraclecontract on Arbitrum Sepolia https://sepolia.arbiscan.io/address/0x526d6789fCb503F2F898f45912A7a24fe9dd48e4#code, a list ofinitialUpdateTypesmay be passed where there are duplicateupdateTypestrings. In this case theupdateTypestring will be pushed to theallUpdateTypeslist multiple times.This can lead to unexpected behavior for any systems relying on the
allUpdateTypeslist as it will have duplicate entries.Recommendation
Consider validating that no duplicate entries have been made for the
updateTypesin theRiskOracleconstructor. -
L-02 Low Incorrect previousValue Stored Logical Error Resolved
Description
When creating the
newUpdateobject to be stored thepreviousValueis 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
previousValueserves little to no value if it merely references the previous update of any market/parameter. Instead thepreviousValueshould pertain to the previous value of the market andupdateTypecombination.Recommendation
Query the last update for the particular market and parameter type via the
latestUpdateIdByMarketAndTypemapping and store this value as thepreviousValue. -
L-03 Low getLatestUpdateByType DoS DoS Resolved
Description
The
getLatestUpdateByTypefunction loops backwards through theupdateHistoryto find the most recent matching entry for theupdateType.This can lead to an out of gas DoS for integrating contracts if a particular
updateTypehas been performed before many other subsequent updates.Recommendation
Be aware of this risk and avoid using the
getLatestUpdateByTypefunction in a Smart Contract. Otherwise consider refactoring theRiskOraclesuch that it stores thelatestUpdateByTypein a mapping so it can be easily queried. -
L-04 Low Lacking Market Validation Validation Resolved
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
RiskOracleandConfigSyncerit is assumed that the market which an update is supplied for is the one which it’s providedadditionalDataincludes, 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
additionalDataprovided.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. -
L-05 Low General Key Risk Validation Resolved
Description
The following keys are not validated in the
_validateRangefunction and belong touintvalues which can potentially DoS or otherwise cause loss or harm to GMX V2 users.MAX_SWAP_PATH_LENGTHMIN_POSITION_SIZE_USDMAX_POSITION_IMPACT_FACTOR_FOR_LIQUIDATIONSMAX_ORACLE_PRICE_AGEMAX_ORACLE_TIMESTAMP_RANGEORACLE_TIMESTAMP_ADJUSTMENTMAX_ORACLE_REF_PRICE_DEVIATION_FACTORREQUEST_EXPIRATION_TIMEMIN_COLLATERAL_FACTOR_FOR_OPEN_INTEREST_MULTIPLIERPOSITION_IMPACT_FACTORMAX_POSITION_IMPACT_FACTORSWAP_IMPACT_FACTORMAX_AUTO_CANCEL_ORDERSRESERVE_FACTOROPEN_INTEREST_RESERVE_FACTORMIN_FUNDING_FACTOR_PER_SECONDTHRESHOLD_FOR_STABLE_FUNDINGTHRESHOLD_FOR_DECREASE_FUNDINGPRICE_FEED_HEARTBEAT_DURATION- All gas related keys
Recommendation
Carefully consider the risk of each of these keys being configured by the
RiskOraclewithout 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-
L-01 Low Missing Allowed Keys Warning Resolved
Description
In the
_initAllowedBaseKeysseveral keys have been excluded which are present in theMockRiskOraclefile.Missing Keys from
allowedBaseKeys:SWAP_FEE_FACTORATOMIC_SWAP_FEE_FACTORTOKEN_TRANSFER_GAS_LIMITMIN_COLLATERAL_FACTORMIN_COLLATERAL_FACTOR_FOR_OPEN_INTEREST_MULTIPLIERMAX_PNL_FACTORMIN_PNL_FACTOR_AFTER_ADLFUNDING_FACTORFUNDING_EXPONENT_FACTORTHRESHOLD_FOR_STABLE_FUNDINGTHRESHOLD_FOR_DECREASE_FUNDINGPOSITION_FEE_FACTORMAX_POSITION_IMPACT_FACTOR_FOR_LIQUIDATIONSMAX_POSITION_IMPACT_FACTOR
These keys may be desired to be configured yet have not been allowed in the
_initAllowedBaseKeysfunction.Also notably, The
MAX_PNL_FACTORkey is present in the_validateMarketInDatafunction, but not in the_initAllowedBaseKeysfunction.Recommendation
Consider adding some or all of these keys to the
_initAllowedBaseKeysfunction, and be aware of the risk if they are not currently validated in theConfig._validateRangefunction. -
L-02 Low Additional Allowed Keys Warning Resolved
Description
A few keys have been marked as allowed which are not included in the
MockRiskOraclecontract. 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_FACTORBASE_BORROWING_FACTORABOVE_OPTIMAL_USAGE_BORROWING_FACTOR
Recommendation
Consider if these keys are expected to be allowed in the
ConfigSyncer.
No findings match.
More from GMX
All 44 reportsPut 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.
