Is there a reference that describes the usage of Revert and what it does in Sway?
The effect of using
Revert in Sway is described in the Fuel specification here. Whenever
revert() operation is used in your smart contract, it halts execution and reverts back the state changes.
I’ll just add that this goes for chains of contract calls as well, for example:
ContractA, which updates storage, transfers some tokens somewhere, and then calls
ContractB, updating its storage and then finally calling
ContractC. If the code execution in
ContractC hits a
revert, the whole chain of calls and effects is undone.
The entire transaction is atomic , meaning that if any part of it fails, the entire thing fails and reverts back to how things were before the attempted transaction.
There is only one effect that is persistent after a
revert: Any gas spent trying to execute the above TX is spent & gone