Since assert would consume all gas and require would return all gas, Is there any reason to use assert not require? Use require to refund gas seems always a better choice than consuming them?

I saw some explanation in Difference between require and assert and the difference between revert and throw but I still don't get it, why choosing a command that consuming all gas, any benefit?


You can use assert (over require) to indicate your intention to source code analyzers such as oyente. While require is good to validate input, it can sometimes be false because the user did something innappropriate. assert, on the other hand, is meant to indicate something that should never be false under any circumstances. Knowing this, a source code analyzer can possibly detect a logical error in the system by discovering any situation in which the assert might not be true.

Hope it helps.


If you want to punish the naughty users who supply bad arguments to your functions, you should use up all their gas :-)

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.