Rob Magier
Mar 19, 2018 · 1 min read

Hi Gus, That’t s a good one. What would be the solution for it ?

Does it this code fix the problem.

We change this original code from this:

function get() {
if (!msg.sender.call.value(balances[msg.sender])()) {
throw;
}
balances[msg.sender] = 0;
}

to this:

function get() {
uint tmpbalance = balances[msg.sender];
if (balances[msg.sender] == 0 )
{
throw;
}
balances[msg.sender] = 0; if (!msg.sender.call.value(tmpbalance)()) {
//no need to revert balances[msg.sender] to tmpbalance
// because we throw.
throw;
}

}

But i guess this is better:

modifier nonReentrant() {
require(!reentrancy_lock);
reentrancy_lock = true;
_;
reentrancy_lock = false;
}

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade