What is the equivalent of gas in preventing DoS attacks? What happens if an attacker writes a recursion that never stops in Plutus? Someone asked the question before.
The execution costs of a contract need to be covered by the included transaction fees. Additionally, a collateral needs to be included. The value of the collateral determines the script execution budget. As soon as execution costs exceed the collateral:
- script execution is aborted,
- the transaction is not accepted (i.e. does not make it to the blockchain),
- the collateral is collected by the validating node.
Because it is impossible to determine in advance if a program/script will succeed or not (halting problem), the script needs to be executed to find out. Because script execution is deterministic on Cardano, the constructor of the transaction can, however, make sure that transaction fees and collateral have the correct values. Execution failure and collateral collection are therefore only to protect against ill intentioned actors, and do not impact well behaving actors.
In this blogpost you can find more about the collateral mechanism on Cardano: link