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

Reentry attack vulnerability in Campaign.sol #11

Open
sergeny opened this issue Aug 3, 2018 · 3 comments
Open

Reentry attack vulnerability in Campaign.sol #11

sergeny opened this issue Aug 3, 2018 · 3 comments

Comments

@sergeny
Copy link

sergeny commented Aug 3, 2018

   function finalizeRequest(uint index) public restricted {
        Request storage request = requests[index];

        require(request.approvalCount > (approversCount / 2));
        require(!request.complete);

        request.recipient.transfer(request.value);
        request.complete = true;
    }

When we are sending money to the recipient, nothing prevents a second recursive call to finalizeRequest. Even though the function is restricted, the recipient could pass control to the manager, who would then execute a recursive call. In this way, the manager, in cooperation with a vendor, could get an approval for a small amount, but withdraw many times that amount.

Technically, it would a solution to check that manager is a human and not a smart contract, but no such check is being done. Furthermore, one could make an innocent-looking smart contract, pretending it's just a convenience tool for the manager, in case someone decides to look, but keep it upgradable to leave a backdoor.

Update: the proposed solution is to interchange the last two lines, setting the flag to true before doing the transfer.

@JuiceyDuecy
Copy link

Just wondering what exactly was the fix?

@JuiceyDuecy
Copy link

Git diff I guess

@sergeny sergeny changed the title Reentry attack in Campaign.sol Reentry attack vulnerability in Campaign.sol Aug 3, 2018
@sergeny
Copy link
Author

sergeny commented Aug 3, 2018

You could swap the last two lines, setting complete to true before doing the transfer.

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

2 participants