contract foster{
vulnerable v = new vulnerable();
attacker a = new attacker(address(v));
constructor() public payable{
// a.deposit(address(v)); // transferring 3 ethers to vulnerable contract and rest to the attacker contract
// v.addNominee(address(a));
}
function action() public payable{
a.deposit(address(v)); // transferring 3 ethers to vulnerable contract and rest to the attacker contract
v.addNominee(address(a));
}
function getTargetBalance() public view returns(uint256, uint256){
return (address(v).balance , address(this).balance);
}
function attack() public payable{
v.transact();
}
}
Here is what I wanna do. I have two contracts namely attacker
and vulnerable
with the following definitions.
contract attacker
contract attacker{
constructor(address payable _vulnerableContract) public{
vulnerable v = vulnerable(_vulnerableContract);
}
function deposit(address payable _addr) payable public{
_addr.transfer(msg.value);
}
function() external payable{
}
}
contract vulnerable
contract vulnerable{
mapping (address => uint256) balance;
uint256 _amount;
function() external payable{
}
function deposit() payable public{
address(this).transfer(_amount);
}
}
Here in the foster
contract, I want to create one instance each of vulnerable
and attacker
.
I want to make the function action
in the foster
contract to call a.deposit(address(v))
, and transfer the ethers from a's behalf to contract v
. So that the net ether is transferred from calling account to contract instance v
.
Then I want to add a
as a nominee to the v
instance.
When I am doing the thing I have done in the contract, the ether would go to contract foster
and not to v
. How can I make it happen?
My final aim is to trigger a failed send()
bug when I call, v.transact
, for that I need some ethers with the contract v
. I'll add some failure in the function() payable
of the contract a
later.