10

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

1 Answer 1

12

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

4
  • 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, 2017 at 21:29
  • @TripleSpeeder Yes, throw is being deprecated.
    – eth
    Oct 17, 2017 at 10:30
  • 2
    @eth what s the gas cost of revert itself? Jul 24, 2019 at 6:16
  • 1
    @user2284570 according to this answer require(which essentially wraps revert) does though very little, about 23 gas: stackoverflow.com/a/48085107/10261711
    – MShakeG
    Feb 14, 2022 at 17:10

Your Answer

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

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