4 ms·
I have actually tested this attack technique (using my own contracts on a local test chain), and I've been in discussions with some Solidity developers and the
by DennisP 10y ago
I have actually tested this attack technique (using my own contracts on a local test chain), and I've been in discussions with some Solidity developers and the guy who first published the attack. The situation is not as bad as this article claims.
For starters, you can use address.send(x) instead of address.call.value(x)(). All computations on Ethereum have to be funded with "gas" (transaction fees), and send() only forwards a small amount of gas. The recipient can write to the log but that's about it. TheDAO used .value() which forwards all the available gas.
If you do use .value(), then you can do it safely by doing it only once per method, as the very last step, and only using it in top-level methods. Then any sort of reentrant callback will find any required state changes already done. E.g. subtract from the user's balance, send the funds, and if the send fails then throw. The recipient can call back but the balance is already decremented. Using a mutex is another option. I've tested all this and it works.
There are a lot of reasons Ethereum is designed this way. The most common reason for a contract to run code when receiving funds is to prevent users from accidentally losing their money. E.g. in any contract that holds ether and maintains a ledger with balances for multiple users, if anyone sends ether to the contract address, they'll lose it, unless the contract either throws an exception or automatically adds to the user's balance on its ledger.
User addresses and contract addresses are interchangeable, because it lets you do things like use a multisig timelocked vault to receive funds and anything can send to it just as if it were a regular user account.
All that said, the devs are working on improvements too.
- amaks 10y ago> All computations on Ethereum have to be funded with "gas" (transaction fees) But that's what was wrong with the exploited DAO code - it didn't use gas. The point of the article is that it's very hard or impossible to verify the correctness of the smart contracts.
- aakilfernandes 10y ago> it didn't use gas this is incorrect
- amaks 10y agoWell perhaps but I read this article (http://vessenes.com/deconstructing-thedao-attack-a-brief-code-tour/ http://vessenes.com/deconstructing-thedao-attack-a-brief-cod...) and it says: "OK, here we go. _recipient.call.value()() is called without a gas amount. That is easily attackable with an attacking wallet."
- deleted 10y ago[deleted]
- aakilfernandes 10y agoAh, that means the exact opposite ie "use as much gas as needed". This is different from the default _recipient.send() which would be limited to 2300 gas
- goldenkey 10y agoIt doesn't matter if it uses gas when you are getting free eth...
- yarrel 10y agoSend at the end is like return-once or tail recursion. Does - http://www.joeykrug.com/home/a-serpent-send-exploit http://www.joeykrug.com/home/a-serpent-send-exploit change things at all?
- DennisP 10y agoNope, Serpent is a different language that compiles to the EVM, and Krug just noticed that by default, a send in Serpent includes more gas than Solidity does, opening a door to unexpected attacks. Solidity is the official supported language, Serpent is an earlier and slightly lower-level language that some people still use. I expect they'll fix the gas default.
- curiousgal 10y agoWell Well Well, what do you know, someone who has actually looked into things and not just basing their statements on their anti-crypto beliefs.
- ianpurton 10y agoThe situation is not as bad as this article claims. Well it kind of is actually. The people that wrote the DAO script had the script checked by lots of Ethereum experts and the bug slipped through. So if the Ethereum experts can't stop things like this happening then what chance do individual developers have. Basically creating a turing complete scripting language on the blockchain is not secure. No financial institution will risk creating smart contracts on this platform.
- deleted 10y ago[deleted]
- tomw1808 10y agoWhenever I hear "expert" I think of https://www.youtube.com/watch?v=BKorP55Aqvg https://www.youtube.com/watch?v=BKorP55Aqvg
- Cyph0n 10y agoThis is the video I was expecting.
- curiousgal 10y agoIt can actually be done. https://www.youtube.com/watch?v=B7MIJP90biM https://www.youtube.com/watch?v=B7MIJP90biM
- wickedlogic 10y agoNot a knock on your post, but "checked by experts" is like saying "QA looked at it". If the tools aren't in place to warn/prevent, re:"stop things like this", unintended executions are only going to continue. It is the brave new old world.
- ianpurton 10y agoThat's exactly it. The current op codes allow for this kind of mistake. So mistakes like this will happen.