The GMXCompound.sol
contract contains a vulnerability related to reentrancy risk due to its interaction with external contracts. The code doesn't follow the "Checks-Effects-Interactions" pattern, which can create reentrancy risks.
GMXCompound.sol
contract file interacts with external contracts, such as GMXManager.swapExactTokensForTokens
and GMXManager.addLiquidity
, without using the "Checks-Effects-Interactions" pattern. This pattern ensures that state changes are made before interacting with external contracts. The absence of this pattern can potentially create reentrancy risks.
In the GMXCompound.sol
contract, the vulnerability related to reentrancy risk is present in the compound
function. Identified the code block where this vulnerability occurs:
The state changes are made within the same block as the interaction with an external contract (GMXManager.addLiquidity
). This can create a reentrancy risk because the state changes should typically be made before interacting with external contracts, following the "Checks-Effects-Interactions" pattern to minimize reentrancy risks. To mitigate this vulnerability, the state changes should be finalized before calling external contracts, as recommended in the previous response.
Reentrancy attacks can result in unexpected behavior and potential loss of funds. An attacker could exploit this vulnerability to call functions from external contracts that modify the state of the GMXCompound
contract before its state changes are applied.
Manual
Recommend to follow the "Checks-Effects-Interactions" pattern when interacting with external contracts. This involves ensuring that state changes are made before any interactions with external contracts. Additionally, consider using the "ReentrancyGuard" pattern to further mitigate reentrancy risks.
By applying the "Checks-Effects-Interactions" pattern, the contract ensures that state changes are made before any external interactions, reducing reentrancy risks. This pattern should be consistently applied throughout the contract's functions.
Showing how the code can be modified to follow the "Checks-Effects-Interactions" pattern:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.