Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdamSzymanski - Insufficient Reentrancy Protection in ripcord Function Due to Reliance on onlyEOA Modifier #44

Open
sherlock-admin4 opened this issue Oct 21, 2024 · 0 comments

Comments

@sherlock-admin4
Copy link
Contributor

sherlock-admin4 commented Oct 21, 2024

AdamSzymanski

Medium

Insufficient Reentrancy Protection in ripcord Function Due to Reliance on onlyEOA Modifier

Summary

Very similar issue as in this Sherlock report

The ripcord function in the MorphoLeverageStrategyExtension contract relies on the onlyEOA modifier to restrict access to externally owned accounts (EOAs). However, this check is insufficient as a reentrancy guard. Without proper reentrancy protection, the function is vulnerable to reentrancy attacks, which could lead to unintended state changes or financial loss.

Root Cause

The contract uses the onlyEOA modifier, which checks msg.sender == tx.origin, to ensure that only EOAs can call the ripcord function. This approach is not a substitute for a reentrancy guard because it does not prevent contracts from re-entering functions during execution. Additionally, future Ethereum proposals like EIP-3074 could allow contracts to impersonate EOAs, rendering the onlyEOA check ineffective.

Code Location

  • File: MorphoLeverageStrategyExtension.sol
  • Function: ripcord
modifier onlyEOA() {
    require(msg.sender == tx.origin, "Must be EOA address");
    _;
}

function ripcord(string memory _exchangeName) external onlyEOA {
    // Function logic...
    uint256 etherTransferred = _transferEtherRewardToCaller(incentive.etherReward);
    //...
}

Internal Pre-conditions

  • The contract holds an Ether balance sufficient to pay the incentive reward.
  • The ripcord function is callable and intended to be used during high leverage situations.

External Pre-conditions

  • An attacker can deploy a malicious contract designed to exploit reentrancy.
  • The attacker is motivated to drain the contract's Ether balance or manipulate its state.

Attack Path

  1. Preparation: The attacker deploys a malicious contract capable of re-entering the ripcord function.
  2. Invocation: The attacker calls the ripcord function via their malicious contract.
  3. Reentrancy: During the Ether transfer in _transferEtherRewardToCaller, the attacker re-enters the ripcord function.
  4. Exploitation: The attacker repeats this process to drain Ether rewards or manipulate the contract state.

Impact

  • Financial Loss: The attacker can drain the Ether balance allocated for rewards.
  • State Manipulation: Unintended changes to leverage positions or other sensitive state variables.
  • Contract Disruption: The contract may behave unpredictably or enter an invalid state.

Estimated Loss

The attacker could potentially drain all Ether allocated for incentives. The exact amount depends on the contract's Ether balance but could be significant.

Mitigation

  • Implement Reentrancy Guard: Use a reentrancy guard, such as OpenZeppelin's ReentrancyGuard, to prevent reentrancy attacks.

    import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
    
    contract MorphoLeverageStrategyExtension is BaseExtension, ReentrancyGuard {
        //...
    
        function ripcord(string memory _exchangeName) external nonReentrant onlyEOA {
            // Function logic...
        }
    }
  • Avoid Reliance on onlyEOA: Do not rely solely on onlyEOA for security-critical functions.

Conclusion

The reliance on the onlyEOA modifier in the ripcord function is insufficient for reentrancy protection. Implementing proper reentrancy guards ensures the function is secure against reentrancy attacks, both now and in the future, even if Ethereum's capabilities evolve.

@sherlock-admin2 sherlock-admin2 changed the title Odd Hotpink Antelope - Insufficient Reentrancy Protection in ripcord Function Due to Reliance on onlyEOA Modifier AdamSzymanski - Insufficient Reentrancy Protection in ripcord Function Due to Reliance on onlyEOA Modifier Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant