If a contract hits a special `assert(false)` error, how much gas money does it get back compared to if it hit a `require(false)` or `revert()` error?
Gas is the unit of computational effort required to execute operations on the Ethereum blockchain, and every transaction requires a certain amount of gas, paid by the sender, to cover the resources consumed by the network. When a contract execution encounters an error that causes it to revert, all state changes made during that transaction are undone, as if the transaction never happened. The gas that was already consumed by the operations executed before the error point is never refunded, regardless of the error type. The difference in gas cost lies in how the *remainingunused gas is handled. If a contract hits a `require(false)` condition or executes a `revert()` instruction, it signals an expected error or an invalid condition, causing the transaction to fail and revert. In this scenario, any gas that was supplied by the sender as part of the transaction's gas limit but was *not yet consumedwhen the `require` or `revert` was hit *is returnedto the sender. This means the sender effectively only pays for the computational effort expended up to the point of the error, plus the intrinsic transaction cost. In contrast, if a contract hits an `assert(false)` condition, it signals an internal error or a violated invariant, indicating a bug in the contract's code that should theoretically never occur. When an `assert(false)` is triggered, the transaction also fails and reverts all state changes. However, unlike `require` or `revert`, an `assert(false)` causes *all remaining gassupplied with the transaction to be consumed. No gas refund is given for any of the unused gas, meaning the transaction sender pays for all gas consumed up to the point of the `assert` and also effectively pays for all the remaining gas that was supplied but not used by the execution. This results in the sender paying the full gas limit specified for the transaction, making it a significantly more expensive error for the sender compared to a `require` or `revert`.