You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 24, 2023. It is now read-only.
Uncalculated gas while swapping tokens will make the keeper lose funds on withdrawals
Summary
While calculating the gas that is estimated for withdrawals, it does not calculate also the gas of the swapPath for none of both tokens, long and short. Those paths are addresses from the struct CreateWithdrawalParams used for creating a withdrawal.
Vulnerability Detail
The following struct is used with creating a withdrawal order:
As you can see in the previous snippets, there is no calculation or whatsoever of the gas that will cost swapping the tokens through the previously inputted paths. Specially if the path is long, the gas used for swapping will compound charging the keeper because they were unexpected costs. These gas will be deducted directly from the contract, draining it slowly due to the missed calculation
Impact
High. The contract (the keeper)will be charged the gas that is not accounted for those swapPaths, draining the contracts native currency slowly.
Add a gas calculation for the swapPaths of both, the long and short token. Consider calculating that amount taking into account the lenght of each path, because that will increase/decrease the gas costs.
0xAmanda
high
Uncalculated gas while swapping tokens will make the keeper lose funds on withdrawals
Summary
While calculating the gas that is estimated for withdrawals, it does not calculate also the gas of the swapPath for none of both tokens,
long and short
. Those paths are addresses from the structCreateWithdrawalParams
used for creating a withdrawal.Vulnerability Detail
The following struct is used with creating a withdrawal order:
https://github.com/sherlock-audit/2023-02-gmx/blob/main/gmx-synthetics/contracts/withdrawal/WithdrawalUtils.sol#L46
The following 2 params:
are not accounted in the calculation of the gas to execute the tx.
https://github.com/sherlock-audit/2023-02-gmx/blob/main/gmx-synthetics/contracts/withdrawal/WithdrawalUtils.sol#L163
Calculation using the withdrawal request:
As you can see in the previous snippets, there is no calculation or whatsoever of the gas that will cost swapping the tokens through the previously inputted paths. Specially if the path is long, the gas used for swapping will compound charging the keeper because they were unexpected costs. These gas will be deducted directly from the contract, draining it slowly due to the missed calculation
Impact
High. The contract (the keeper)will be charged the gas that is not accounted for those swapPaths, draining the contracts native currency slowly.
Code Snippet
https://github.com/sherlock-audit/2023-02-gmx/blob/main/gmx-synthetics/contracts/gas/GasUtils.sol#L149
Tool used
Manual Review
Recommendation
Add a gas calculation for the swapPaths of both, the long and short token. Consider calculating that amount taking into account the lenght of each path, because that will increase/decrease the gas costs.
Duplicate of #195
The text was updated successfully, but these errors were encountered: