I am trying to understand the following contract sample:

// Refund contract for trust DAO #16

contract DAO {
    function balanceOf(address addr) returns (uint);
    function transferFrom(address from, address to, uint balance) returns (bool);
    uint public totalSupply;

contract WithdrawDAO {
    DAO constant public mainDAO = DAO(0x200450f06520bdd6c527622a273333384d870efb);
    address public trustee = 0x7c81d252d9d1295058cd3620835f37e0eedd8840;

    function withdraw(){
        uint balance = mainDAO.balanceOf(msg.sender);

        if (!mainDAO.transferFrom(msg.sender, this, balance) || !msg.sender.send(balance))

    function trusteeWithdraw() {
        trustee.send((this.balance + mainDAO.balanceOf(this)) - mainDAO.totalSupply());

I am a bit confused about the withdraw function. What if the first transfer transferFrom always failed due to certain reason? Would it somehow lock the fund and therefore the second fund transfer can never happen? Thanks a lot!


First of all, in Solidity x || y is evaluated in lazy way, so in case x is true, y is not evaluated at all. This means, that in case transferFrom will fail, send will not be called.

Also, throw "reverts" the transaction, i.e. rolls back all changes made be the transaction, including any ether or token transfers. So if transferFrom will fail, the transaction will be reverted, and no changes made by it will be persisted in blockchain.

Though, the fact that transaction was (unsuccessfully) executed will be persisted, and transaction publisher will pay fee for this, and this fee will be collected by miner as a reward for (unsuccessfully) executing the transaction. This is fair, because miner anyway spent resources on this transaction.

  • Thank you! One thing I am thinking about is whether this could cause some security issue. For instance, a malicious miner could upload a DAO refund contract that seems valid, but however, make the transferFrom fails everytime, then users cannot get refund via the send, but still need to pay the miner a certain amount of fee. Does that sounds reasonable to you? – lllllllllllll Apr 1 '19 at 21:55
  • Yes. The idea is that smart contract's byte code is public and contract's behavior is fully determined by this byte code. So, before using smart contract one may inspect its byte code to make sure contract really does what it is supposed to do. Also one may execute transaction locally (the same way as miners will execute it) and make sure it succeeds, before publishing the transaction to blockchain. Local execution is free, but is not 100% reliable, because execution success may depend on quickly changing or unpredictable factors such current time, block hash, or smart contract's state. – Mikhail Vladimirov Jun 10 '19 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.