require()
should be used for checking error conditions on inputs and return values while assert()
should be used for invariant checking. Between solc 0.4.10
and 0.8.0
, require()
used REVERT
(0xfd
) opcode which refunded remaining gas on failure while assert()
used INVALID (0xfe
) opcode which consumed all the supplied gas. (see here)
assert()
vsrequire()
-> Different Usagesassert()
-> Invariants- No Failures Expected
require()
-> Validation Failures Expected- Use Appropriately