10

When reading the solidity documentation (http://solidity.readthedocs.org/en/latest/solidity-by-example.html#voting), I came across this:

function giveRightToVote(address voter)
{
    if (msg.sender != chairperson || voters[voter].voted)
        // `throw` terminates and reverts all changes to
        // the state and to Ether balances. It is often
        // a good idea to use this if functions are
        // called incorrectly. But watch out, this
        // will also consume all provided gas.
        throw;
    voters[voter].weight = 1;
}

In particular, this part:

But watch out, this will also consume all provided gas.

Does this mean that, if you provide a large amount of excess Ether that it won't be refunded after a throw?

1 Answer 1

5

Does this mean that, if you provide a large amount of excess Ether that it won't be refunded after a throw?

Close. It means if you provide a large amount of excess GAS that the gas won't be refunded. For example, maxGas is about USD 1.20 right now, and if you sent maxGas all $1.20 would be consumed. (That's about 0.094 ether)

Throw aborts the transaction, so any Ether sent won't actually get sent.

Gas is what is used to fund the transaction. The actual state of the system other than Gas charges is unchanged if the transaction aborts.

2
  • And why is this designed that way? I call a function that I don't have permission to call, which throws and consumes $1.20? Why can't it just consume the gas that were actually used by the opcodes executed so far?
    – Peter Hall
    Commented Mar 23, 2016 at 11:53
  • 3
    I've spent an hour googling, I can't figure out why an exception consumes all gas. The Yellow Paper just stated it happens, it didn't say why. An ethereum core expert needs to weigh in here on the rationale. Also, I'm not 100% certain that "any Ether won't get sent" is true or not, I found one reference that says it will, another that says it won't...
    – Paul S
    Commented Mar 23, 2016 at 22:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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