user7939: 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.

user5926: One of the features of Plutus contracts is that fees of all valid Plutus contracts must be able to be determined at compile time. That means that anything for which this cannot be determined is not a valid Plutus contract. Therefore, contracts containing infinite loops are not valid.

user2537: 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

7939: <p>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 <a href="https://www.reddit.com/r/CardanoDevelopers/comments/po7s6g/what_is_cardanos_equivalent_to_gas_metering/" rel="nofollow noreferrer">the question</a> before.</p>
 5926: <p>One of the features of Plutus contracts is that fees of all valid Plutus contracts must be able to be determined at compile time. That means that anything for which this cannot be determined is not a valid Plutus contract. Therefore, contracts containing infinite loops are not valid.</p>
 2537: <p>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:</p>
<ul>
<li>script execution is aborted,</li>
<li>the transaction is not accepted (i.e. does not make it to the blockchain),</li>
<li>the collateral is collected by the validating node.</li>
</ul>
<p>Because it is impossible to determine <em>in advance</em> 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.</p>
<p>In this blogpost you can find more about the collateral mechanism on Cardano: <a href="https://iohk.io/en/blog/posts/2021/09/07/no-surprises-transaction-validation-part-2/" rel="nofollow noreferrer">link</a></p>
