Is the following function vulnerable to a reentrancy attack?

function withdraw() public {
     uint amount = pendingWithdrawals[msg.sender];
     // Remember to zero the pending refund before
     // sending to prevent re-entrancy attacks
     pendingWithdrawals[msg.sender] = 0;
     emit AmountWithdrawn(msg.sender, amount);

1 Answer 1


No, it is not vulnerable to a reentrancy attack. An event will not cause a function to throw.

The way you have it written is very secure, in that you are updating pendingWithdrawals prior to the sending of the amount.

In the future, try to keep the structure of all the functions you write very similar to this, in that you change the state prior to performing actions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.