Then at some point it terminates itself before emptying the source account (and thereby causing a rollback that would cascade back?)
Then at some point it terminates itself before emptying the source account (and thereby causing a rollback that would cascade back?)
What made this particularly devastating is that there was a second bug which allowed the attacker to transfer their token that represented that first ether back to the DAO. So instead of 30x return, they could eventually drain the whole DAO (although they stopped after the discussion of a fork began).
I'm largely basing my understanding off this article: http://vessenes.com/deconstructing-thedao-attack-a-brief-cod...
send(theEther, childDao)
deduct(theEther, tokenHolder)
But that you can get it to overflow the stack in between the two so that the send completes but the deduction no longer happens.Do the deduct before the send, and the whole problem goes away.
The send returns false if it fails. So if you check for that, you can throw an exception, which rolls back the whole transaction just like in SQL.
The reason the send doesn't automatically throw is that if you were doing lots of sends in a loop, you'd actually want to ignore the exception, so if one send fails it doesn't block everybody.
This sounds like the wrong default behaviour. If we're talking about sending money, and there's a list of people to send money to, I would say that the default behaviour should be to throw an exception, because if not you could end up having money not be properly redistributed.
For example, a simple smart contract to share costs. If one member not longer participates then shouldn't their cut be given to the remaining participants?
The fact that it doesn't roll back everything by default concerns me quite a bit...
The best pattern is not to put sends in a loop at all. Just update a ledger inside the contract, and have each user call a withdraw() function to get their money. That way if you're careful you can even use call.value, so users can include as much gas as required, and can withdraw the money directly into any sort of contract they like.
http://hackingdistributed.com/2016/06/18/analysis-of-the-dao...