6

According to the docs revert() will not consume any gas:

Note that assert-style exceptions consume all gas available to the call, while revert-style exceptions will not consume any gas starting from the Metropolis release.

But i frequently read that revert() will refund unused gas, e.g. in this answer.

I'm thinking refunding ALL gas will open gates for DOS-attacks, so I'm assuming only unused gas will be refunded. But I would like confirmation :-)

8

Just the remaining gas.

revert will keep unused gas: meaning the caller will have the unused gas to perform further computations. is different and you're correct that if revert gave back gas to the caller, that would allow DoS attacks (a caller could loop many times, then revert, loop, and revert infinitely).

  • So can we say that usage of revert() will be preferred over throw, as it saves the caller some gas? E.g. in cases the caller makes a mistake and provides wrong parameters, causing the contract to raise an error. – TripleSpeeder Jul 1 '17 at 21:29
  • @TripleSpeeder Yes, throw is being deprecated. – eth Oct 17 '17 at 10:30
  • @eth what s the gas cost of revert itself? – user2284570 Jul 24 at 6:16

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.