Security review · September 2025
Token OFT Adapter for GMX
Guardian's review of Token OFT Adapter for GMX, published September 2025. The report records 9 findings across 2 review rounds, including 6 medium and 3 informational.
See how Guardian runs a perp DEX smart contract audit.
- Published
- Review window
- August 14 to September 18, 2025
- Rounds
- Main Review, Remediation Review
- Language
- Solidity
- Chains
- Arbitrum
- Sector
- Perpetuals
- 0 Critical
- 0 High
- 6 Medium
- 0 Low
- 3 Informational
Scope
2 files in scope · 124 nSLOC
| File | nSLOC | Lines |
|---|---|---|
contracts/GMX_Adapter.sol | 52 | 116 |
layerzero.config.ts | 72 | 89 |
Findings 9
Main Review
7 findings · August 14 to 18, 2025-
M-01 Medium Incorrect Enforced Options In layerzero.config.ts File Configuration Resolved
Description
In
layerzero.config.tstheenforcedOptionstuple for some connections does not match the target chain type. The 5th element thatgenerateConnectionsConfig([...])expects (per your sample) is ordered as:[ /* Chain B enforcedOptions */, /* Chain A enforcedOptions */ ]However, the current file mixes up Solana/EVM option sets and also uses a misleading comment (“Chain A enforcedOptions, Chain B enforcedOptions”), causing EVM chains to receive
SOLANA_ENFORCED_OPTIONSand/or Solana to receiveEVM_ENFORCED_OPTIONS. This miswiring makes the executor run with the wrong units (EVM: gas/wei vs. Solana: compute units/lamports), leading to under‑provisioned execution, reverts, or stuck messages. Examples (current vs. fixed) Arbitrum (A, EVM) ↔ Avalanche (B, EVM) — must be EVM on both sides. Current (wrong — A gets Solana options):[EVM_ENFORCED_OPTIONS, SOLANA_ENFORCED_OPTIONS]Fixed (both sides EVM):
[EVM_ENFORCED_OPTIONS, EVM_ENFORCED_OPTIONS]Solana (A) ↔ Arbitrum (B, EVM) — B must get EVM, A must get Solana. Current (wrong — B gets Solana, A gets EVM):
[SOLANA_ENFORCED_OPTIONS, EVM_ENFORCED_OPTIONS]Fixed (match sample order [B, A]):
[EVM_ENFORCED_OPTIONS, SOLANA_ENFORCED_OPTIONS]Solana (A) ↔ Avalanche (B, EVM) — already correct if using [B, A] order:
[ EVM_ENFORCED_OPTIONS, SOLANA_ENFORCED_OPTIONS ]Reference: https://docs.layerzero.network/v2/developers/evm/technical-reference/simple-config
Recommendation
Correct the tuples to match the sample’s order [Chain B, Chain A] and to use Solana options for Solana and EVM options for EVM.
-
M-02 Medium SOLANA_V2_TESTNET Instead Of SOLANA_V2_MAINNET Configuration Resolved
Description
In
layerzero.config.tsthe Solana contract entry is wired to testnet while the EVM peers are on mainnet. This mixes environments inside the same connection matrix and will cause wiring failures, message delivery errors, or accidental testnet minting when operating from mainnet.Recommendation
Point Solana to mainnet and load the mainnet OFT Store address:
const solanaContract: OmniPointHardhat = { eid: EndpointId.SOLANA_V2_MAINNET, // ✅ mainnet EID address: getOftStoreAddress(EndpointId.SOLANA_V2_MAINNET), // ✅ mainnet OFT Store } -
M-03 Medium Non‑normalized Send Accounting Inflate Rate‑limit Rounding Resolved
Description
The adapter counts inbound and outbound volume using different units/rounding. On receive, the limiter charges the normalized amount in local denomination (LD) derived from the packet’s shared‑decimals (SD) payload:
super._outflow(_origin.srcEid, _toLD(_message.amountSD()));but on
sendit credits the limiter with the raw_amountLD:super._inflow(_dstEid, _amountLD);In OFT, packets carry amounts in SD. Conversions are:
_toSD(_amountLD) = floor(_amountLD / 10^(LD−SD)) _toLD(_amountSD) = _amountSD * 10^(LD−SD)Every inbound charge is therefore an exact multiple of the conversion rate, while outbound credits can include a remainder (“dust”)
< 10^(LD−SD). For example, withLD=18,SD=8,cv=10^10:sending _amountLD = cv + (cv−1) = 19,999,999,999transmits only 1 SD, yet the limiter credits19,999,999,999on send but charges only10,000,000,000per matching receive. Repeating this with high‑dust amounts accumulates extra headroom inside the window, allowing more inbound packets than intended under a net‑flow limiter.Recommendation
Normalize send‑side accounting to the same basis used on receive so both directions use identical units and rounding:
super._inflow(_dstEid, _toLD(_toSD(_amountLD))); -
M-04 Medium Unsafe Layer Zero Configuration Configuration Resolved
Description
The current confirmation settings defined in the
layerzero.config.tsfile for Solana - Arbitrum are 32 for sending and 20 for receiving:[32, 20], // [A to B confirmations, B to A confirmations]. Given the default values used by LayerZero, defined here https://layerzeroscan.com/tools/defaults?version=V2, this is correct: (Figure. See the PDF report.) However for Solana - Avalanche, sending confirmations are set to 10 for sending and 12 for receiving:[10, 12], // [A to B confirmations, B to A confirmations]The recommended defaults by LayerZero are 32 for sending and 12 for receiving: (Figure. See the PDF report.) Finally, for Arbitrum - Avalanche, sending confirmations are set to 20 while receiving confirmations are set to 12. These are exactly the recommended default values by LayerZero.Recommendation
Update the Solana - Avalanche configuration and use the LayerZero default values: 32 confirmations for sending and 12 for receiving.
-
M-05 Medium Asymmetric Capacity Accounting Configuration Resolved
Description
GMX_Adapter._debitreduces the rate‑limiter’s in‑flight amount on send unconditionally, even if the_fromaddress is part of theexemptAddresses:super._inflow(_dstEid, _amountLD);while
_lzReceiveskips increasing in‑flight for exempt recipients (and overridable GUIDs):if (!exemptAddresses[toAddress] && !guidOverrides[_guid]) { super._outflow(_origin.srcEid, _toLD(_message.amountSD())); }This breaks symmetry. Any transfer whose destination
toAddressis exempt will not add to in‑flight on receive, yet it does decrease in‑flight on send. While it makes sense to not apply the rate limit on certain addresses when they receive tokens, these same addresses should, at the same time, not decrease the rate limit when they send tokens.Recommendation
Consider updating the
_debitfunction to not callsuper._inflowwhen the_fromaddress is part of theexemptAddressesmapping in the destination chain. -
I-01 Informational Rate Limits Are Not Applied Correctly Validation Acknowledged
Description
The
_inflow()function is designed to reduce theamountInFlightby the_amountpassed to it (inflowAmount), with a lower bound of zero:function _inflow(uint32 _srcEid, uint256 _amount) internal virtual { RateLimit storage rl = rateLimits[_srcEid]; rl.amountInFlight = _amount >= rl.amountInFlight ? 0 : rl.amountInFlight - _amount; }However, let's imagine the following two scenarios:
RateLimiter.RateLimitConfig(1337, 1000, 100);
Scenario 1
<table header-row="true"> <tr> <td>Step</td> <td>Action</td> <td>amountInFlight</td> <td>amountCanBeSent</td> </tr> <tr> <td>0</td> <td>Initial State</td> <td>0</td> <td>1000</td> </tr> <tr> <td>1</td> <td>
outflow(500)</td> <td>500</td> <td>500</td> </tr> <tr> <td>2</td> <td>inflow(1000)</td> <td>0</td> <td>1000</td> </tr> <tr> <td>3</td> <td>outflow(500)</td> <td>500</td> <td>500</td> </tr> </table>Scenario 2
<table header-row="true"> <tr> <td>Step</td> <td>Action</td> <td>amountInFlight</td> <td>amountCanBeSent</td> </tr> <tr> <td>0</td> <td>Initial State</td> <td>0</td> <td>1000</td> </tr> <tr> <td>1</td> <td>
outflow(500)</td> <td>500</td> <td>500</td> </tr> <tr> <td>2</td> <td>outflow(500)</td> <td>1000</td> <td>0</td> </tr> <tr> <td>3</td> <td>inflow(1000)</td> <td>0</td> <td>1000</td> </tr> </table> Despite both scenarios involving a total of 1000 units of outflow and 1000 units of inflow processed in the same timestamp, the remaining rate limit differs based on the order of operations. This inconsistency proves that the rate limiter behaves differently when the sequence of inflow and outflow operations changes, even though the net effect is the same. Users performing the same net actions will experience different rate limits based solely on the sequence of their operations. Moreover, it is expected that users will deliberately arrange operations to maximize their rate limits. A rate limiter should apply limits consistently, regardless of the order of operations, as long as the net effect is the same.Recommendation
Instead of simply setting to 0 the
rl.amountInFlightwhen_amount >= rl.amountInFlightconsider declaringrl.amountInFlightas anint256. This allows the rate limiter to accurately track the net balance of inflows and outflows, ensuring that the rate limit is applied consistently regardless of the order of operations. By allowingamountInFlightto become negative, it is possible to account for scenarios where inflows exceed outflows within the rate limiting window. This approach ensures that the remaining rate limit (amountCanBeSent) reflects the true net activity over time, eliminating discrepancies caused by the sequence of inflow and outflow operations. -
I-02 Informational Inbound Rate Limit Is Effectively “Net‑Flow” Warning Acknowledged
Description
GMX_Adaptertries to enforce an inbound throttle by swapping LayerZero’s rate‑limiter calls:// On SEND (outbound) function _debit(...) internal override returns (...) { super._inflow(_dstEid, _amountLD); // returns capacity return super._debit(_from, _amountLD, _minAmountLD, _dstEid); } // On RECEIVE (inbound) function _lzReceive(Origin calldata _origin, bytes32 _guid, bytes calldata _message, ...) internal override { address toAddress = _message.sendTo().bytes32ToAddress(); if (!exemptAddresses[toAddress] && !guidOverrides[_guid]) { super._outflow(_origin.srcEid, _toLD(_message.amountSD())); // consumes capacity } super._lzReceive(_origin, _guid, _message, _executor, _extraData); }LayerZero’s limiter uses a single bucket per EID (
amountInFlight)._outflow(amount)increases the bucket._inflow(amount)decreases it but floors at zero (returns headroom). Because the adapter calls_inflowon sends and_outflowon receives, the bucket measuresnet = inbound − outboundwithin the window, not inbound alone. As a consequence an actor can alternate receive→send→receive to keep the bucket ≤ limit while pulling in more than the intended inbound cap. Concrete example (window limit L = 1000 from chain A; start bucket = 0):- Receive 1000 from A → _outflow(+1000) → bucket = 1000
- Send 1000 to A → _inflow(−1000) floors to 0 → bucket = 0
- Receive 1000 from A → bucket = 1000
- Send 1000 to A → bucket = 0
- Receive 1000 from A → bucket = 1000
Within one window, the adapter received 3000, yet the bucket never exceeded 1000. This defeats an “inbound‑only” throttle: total inbound allowed becomes
L + outbound_in_same_window.
- If your policy goal is “throttle inbound mint/credit pressure regardless of outbound”, the current scheme fails: an actor can exceed the inbound cap as long as they also send roughly the same amount back out during the window.
- If your policy goal is “limit net bandwidth”, then the behavior is expected, but then it’s not an “inbound cap.”
Recommendation
Enforce a true inbound‑only limit by not returning capacity on outbound sends. In practice, remove the
_inflowcall from_debitand keep the_outflowon_lzReceiveonly. This uses the limiter as an inbound‑only bucket persrcEid.
Remediation Review
2 findings · September 18, 2025-
M-01 Medium amountReceivedLD Burnt Instead Of amountSentLD Logical Error Resolved
Description
The
GMX_MintBurnAdapter’s_debitimplementation burnsamountReceivedLDeven though the OFT core deliberately splits_debitView’s output into two values:amountSentLD(the amount actually deducted on the source chain) andamountReceivedLD(the post-adjustment amount that should be minted/unlocked on the destination). Right now_debitViewreturns identical numbers for both slots, but the API is designed so custom adapters can diverge them, for example to apply protocol fees, handle fee-on-transfer tokens, tweak dust rounding, or refund rate-limit penalties. Once such a customization makesamountSentLDgreater thanamountReceivedLD, burning onlyamountReceivedLDleaves the excess tokens on the source chain while the remote side still mints the lower amount. Over time that silently inflates the global supply relative to what is minted elsewhere, breaking the accounting guarantees of the OFT mesh.Recommendation
Burn
amountSentLD, in line with the upstreamMintBurnOFTAdapter, so every unit deducted on the source chain is destroyed regardless of downstream adjustments. If you want to keep the current behaviour until divergence is formally supported, enforcerequire(amountSentLD == amountReceivedLD)before burning to fail fast instead of letting inflation slip through silently. -
I-01 Informational Lack Of A Double Step Transfer Ownership Pattern Best Practices Acknowledged
Description
The current ownership transfer process for the
OverridableInboundRateLimiterwhich is inheriting from theOwnablecontract involves the current owner calling thetransferOwnershipfunction:function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _transferOwnership(newOwner); }If the nominated EOA account is not a valid account, it is entirely possible that the owner may accidentally transfer ownership to an uncontrolled account, losing the access to all functions with the
onlyOwnermodifier.Recommendation
It is recommended to implement a two-step process transfer ownership process where the owner nominates an account and the nominated account needs to call an
acceptOwnershipfunction for the transfer of the ownership to fully succeed. This ensures the nominated EOA account is a valid and active account. This can be easily achieved by using OpenZeppelin’s Ownable2Step contract.
No findings match.
More from GMX
All 60 reports-
Morpho Liquidation Module
3 findings 3 findings: 3 informational -
RewardRouterV3 & RewardRouterUtils
20 findings1 high 20 findings: 1 high, 8 low, 11 informational -
V2.2.1 Review
102 findings8 high 102 findings: 8 high, 37 medium, 49 low, 8 informational -
Incentives Contracts
17 findings 17 findings: 3 medium, 3 low, 11 informational
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.
