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

Aniket
  • 3,545
  • 2
  • 20
  • 42
TripleSpeeder
  • 920
  • 9
  • 16

1 Answers1

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

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