What is a stateful covenant in Kaspa, and how does it work?
A stateful covenant in Kaspa is a locking script that not only controls who can spend a coin, but also enforces that a piece of data attached to the transaction was updated by a specific rule before the spend is valid. The KIP-17 proposal illustrates this with a counter: the script verifies that the new transaction's payload equals the previous transaction's payload plus one, that the output goes to the same locking script, and that there is exactly one output — all checked in script using introspection opcodes. In more general terms, any state-transition function δ can be encoded this way, where the script validates that δ applied to the old payload produces the new payload. This matters to beginners because it means Kaspa's scripting layer can enforce multi-step on-chain protocols — games, channels, counters — purely through script rules, without relying on a separate execution environment.