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 :-)


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. Jul 1 '17 at 21:29
  • @TripleSpeeder Yes, throw is being deprecated.
    – eth
    Oct 17 '17 at 10:30
  • 1
    @eth what s the gas cost of revert itself? Jul 24 '19 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.