I'm a newbie in blockchain. I am trying to repeat DAO attack using two different contracts, in my case DAO and Hacker. I want the 2 contracts belongs to 2 separated account, so I can see that the ethereum goes from DAO contract holder to Hacker contract holder in Genache. However, I got stuck since I can only migrate my contract using the same account based on command truffle --migrate -reset
Here are the contracts for both DAO and Hacker:
pragma solidity ^0.4.24;
contract Dao {
struct User {
address addr;
string name;
uint balence;
uint8 flag;
}
//Fetch User
mapping(address=>User) users; // create HashArray<address,User>, which can be random access
uint public userCount;
constructor() public {
//user = "hello"; just for testing
//addUser("wei");
//addUser("alex");
}
function addUser (address _addr, string _name, uint _balence, uint _flag) private {
users[_addr] = User(_addr,_name,0,1);
userCount++;
}
function addToBalence(string name) public payable{
if(users[msg.sender].flag != 1) addUser(msg.sender,name,0,1);
users[msg.sender].balence = users[msg.sender].balence + msg.value;
}
function showBalence(address) public returns (uint) {
return users[msg.sender].balence;
}
function withdraw(uint amount) public payable{
if(users[msg.sender].flag != 1) revert("user does not exist");
else if (users[msg.sender].balence >= amount){
msg.sender.call.value(amount)();
users[msg.sender].balence -= amount;
}
else return false;
}
}
}
contract Hacker {
// the address of the user, so the money can be transfered
Dao dao;
address userAddress;
string userName;
constructor(string name, address daoAddr) public {
dao = Dao(daoAddr);
userAddress = msg.sender;
userName = name;
}
function payout(uint amount) public payable{
dao.withdraw(amount);
}
}