I am studying the following code

contract Mutex {
bool locked;
modifier noReentrancy() {
    locked = true;
    locked = false;
 function f(unit256 amount) public noReentrancy returns (uint) {

Below is the execution flow that I am following (Please let me know if I am wrong):

  1. The attacker contract calls the vulnerable function to withdraw 10 ether.
  2. The victim contract executes the opcode and transfers 10 ether to the attackers contract.
  3. The fall back func gets executed in the attacker contract.
  4. The fall back func calls the withdraw function again.
  5. But require statement catches the attack and reverts the whole transaction.

My question is: Would revert statement also revert the ether flow in step 2. If yes, How? because ether has already been deposited into the attackers account.

  • It's all a part of the same (atomic) transaction, either everything takes effect and goes into the blockchain or everything doesn't take effect and stays out of the blockchain. As a side note, I'd say that modifiers are normally used just for condition checking, not for state changing, so you may as well put that stuff inside the function. A question very similar to yours is here. – goodvibration May 13 at 2:35
  • Okay. I got it. Thanks. – Skynet May 13 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.