<oembed><type>rich</type><version>1.0</version><author_name>npub1lpkmxpl2zhk0w30vtdz7s64ml9644k785eggmjsjgs7wman3szzqac74n4</author_name><author_url>https://nostr.ae/npub1lpkmxpl2zhk0w30vtdz7s64ml9644k785eggmjsjgs7wman3szzqac74n4</author_url><provider_name>njump</provider_name><provider_url>https://nostr.ae</provider_url><html>📅 Original date posted:2022-11-08&#xA;📝 Original message:Hi list,&#xA;&#xA;I have been working on some notes to describe an approach that uses&#xA;covenants in order to enable general smart contracts in bitcoin. You can&#xA;find them here:&#xA;&#xA;    https://merkle.fun&#xA;&#xA;The approach has a number of desirable features:&#xA;&#xA;- small impact to layer 1;&#xA;- not application-specific, very general;&#xA;- it fits well into P2TR;&#xA;- it does not require new cryptographic assumptions, nor any construction&#xA;that has not withstood the test of time.&#xA;&#xA;This content was presented at the BTCAzores unconference, where it received&#xA;the name of MATT − short for Merkleize All The Things.&#xA;In fact, no other cryptographic primitive is required, other than Merkle&#xA;trees.&#xA;&#xA;I believe this construction gets close to answering the question of how&#xA;small a change on bitcoin&#39;s layer 1 would suffice to enable arbitrary smart&#xA;contracts.&#xA;&#xA;It is not yet at the stage where a formal proposal can be made, therefore&#xA;the proposed specs are only for illustrative purposes.&#xA;&#xA;The same content is reformatted below for the mailing list.&#xA;&#xA;Looking forward to hearing about your comments and improvements.&#xA;Salvatore Ingala&#xA;&#xA;&#xA;==========================================&#xA;&#xA;&#xA;# General smart contracts in bitcoin via covenants&#xA;&#xA;Covenants are UTXOs that are encumbered with restrictions on the outputs of&#xA;the transaction spending the UTXO. More formally, we can define a covenant&#xA;any UTXO such that at least one of its spending conditions is valid only if&#xA;one or more of the outputs’ scriptPubKey satisfies certain restrictions.&#xA;&#xA;Generally, covenant proposals also add some form of introspection (that is,&#xA;the ability for Script to access parts of the inputs/outputs, or the&#xA;blockchain history).&#xA;&#xA;In this note, we want to explore the possibilities unleashed by the&#xA;addition of a covenant with the following properties:&#xA;&#xA;- introspection limited to a single hash attached to the UTXO (the&#xA;“covenant data”), and input/output amounts;&#xA;- pre-commitment to every possible future script (but not their data);&#xA;- few simple opcodes operating with the covenant data.&#xA;&#xA;We argue that such a simple covenant construction is enough to extend the&#xA;power of bitcoin’s layer 1 to become a universal settlement layer for&#xA;arbitrary computation.&#xA;&#xA;Moreover, the covenant can elegantly fit within P2TR transactions, without&#xA;any substantial increase for the workload of bitcoin nodes.&#xA;&#xA;A preliminary version of these notes was presented and discussed at the&#xA;BTCAzores Unconference [1], on 23rd September 2022.&#xA;&#xA;&#xA;# Preliminaries&#xA;&#xA;We can think of a smart contract as a “program” that updates a certain&#xA;state according to predetermined rules (which typically include access&#xA;control by authorizing only certain public keys to perform certain&#xA;actions), and that can possibly lock/unlock some coins of the underlying&#xA;blockchain according to the same rules.&#xA;&#xA;The exact definition will be highly dependent on the properties of the&#xA;underlying blockchain.&#xA;&#xA;In bitcoin, the only state upon which all the nodes reach consensus is the&#xA;UTXO set; other blockchains might have other data structures as part of the&#xA;consensus, like a key-value store that can be updated as a side effect of&#xA;transaction execution.&#xA;&#xA;In this section we explore the following concepts in order to set the&#xA;framework for a definition of smart contracts that fits the structure of&#xA;bitcoin:&#xA;&#xA;- the contract’s state: the “memory” the smart contract operates on;&#xA;- state transitions: the rules to update the contract’s state;&#xA;- covenants: the technical means that can allow contracts to function in&#xA;the context of a bitcoin UTXO.&#xA;&#xA;In the following, an on-chain smart contract is always represented as a&#xA;single UTXO that implicitly embeds the contract’s state and possibly&#xA;controls some coins that are “locked” in it. More generally, one could&#xA;think of smart contracts that are represented in a set of multiple UTXOs;&#xA;we leave the exploration of generalizations of the framework to future&#xA;research.&#xA;&#xA;## State&#xA;&#xA;Any interesting “state” of a smart contract can ultimately be encoded as a&#xA;list, where each element is either a bit, a fixed-size integers, or an&#xA;arbitrary byte string.&#xA;&#xA;Whichever the choice, it does not really affect what kinds of computations&#xA;are expressible, as long as one is able to perform some basic computations&#xA;on those elements.&#xA;&#xA;In the following, we will assume without loss of generality that&#xA;computations happen on a state which is a list of fixed length S = [s_1,&#xA;s_2, …, s_n], where each s_i is a byte string.&#xA;&#xA;### Merkleized state&#xA;&#xA;By constructing a Merkle tree that has the (hashes of) the elements of S in&#xA;the leaves, we can produce a short commitment h_S to the entire list S with&#xA;the following properties (that hold for a verifier that only knows h_S):&#xA;&#xA;- a (log n)-sized proof can prove the value of an element s_i;&#xA;- a (log n + |x|)-sized proof can prove the new commitment h_S’, where S’&#xA;is a new list obtained by replacing the value of a certain leaf with x.&#xA;&#xA;This allows to compactly commit to a RAM, and to prove correctness of RAM&#xA;updates.&#xA;&#xA;In other words, a stateful smart contract can represent an arbitrary state&#xA;in just a single hash, for example a 32-byte SHA256 output.&#xA;&#xA;### State transitions and UTXOs&#xA;&#xA;We can conveniently represent a smart contract as a finite state machine&#xA;(FSM), where exactly one node can be active at a given time. Each node has&#xA;an associated state as defined above, and a set of transition rules that&#xA;define:&#xA;&#xA;- who can use the rule;&#xA;- what is the next active node in the FSM;&#xA;- what is the state of the next active node.&#xA;&#xA;It is then easy to understand how covenants can conveniently represent and&#xA;enforce the smart contracts in this framework:&#xA;&#xA;- The smart contract is instantiated by creating a UTXO encumbered with a&#xA;covenant; the smart contract is in the initial node of the FSM.&#xA;- The UTXO’s scriptPubKey specifies the current state and the valid&#xA;transitions.&#xA;- The UTXO(s) produced after a valid transition might or might not be&#xA;further encumbered, according to the rules.&#xA;&#xA;Therefore, what is necessary in order to enable this framework in bitcoin&#xA;Script is a covenant that allows the enforcement of such state transitions,&#xA;by only allowing outputs that commit to a valid next node (and&#xA;corresponding state) in the FSM.&#xA;&#xA;It is not difficult to show that arbitrary computation is possible over the&#xA;committed state, as long as relatively simple arithmetic or logical&#xA;operations are available over the state.&#xA;&#xA;Remark: using an acyclic FSM does not reduce the expressivity of the smart&#xA;contracts, as any terminating computation on bounded-size inputs which&#xA;requires cycles can be unrolled into an acyclic one.&#xA;&#xA;### Merkleized state transitions&#xA;&#xA;Similarly to how using Merkle trees allows to succinctly represent&#xA;arbitrary data with a short, 32-byte long summary, the same trick allows to&#xA;succinctly represent arbitrary state transitions (the smart contract’s&#xA;code) with a single 32-byte hash. Each of the possible state transitions is&#xA;encoded as a Script which is put in a leaf of a Merkle tree; the Merkle&#xA;root of this tree is a commitment to all the possible state transitions.&#xA;This is exactly what the taptree achieves in Taproot (see BIP-0341 [2]).&#xA;&#xA;Later sections in this document will suggest a possible way of how both the&#xA;contract’s state and valid transition rules could be represented in UTXOs.&#xA;&#xA;## On-chain computation?!&#xA;&#xA;Should the chain actually do computation?&#xA;&#xA;If naively designed, the execution of a contract might require a large&#xA;number of transactions, which is not feasible.&#xA;&#xA;While the covenant approach does indeed enable a chain of transactions to&#xA;perform arbitrary computation, simple economic considerations will push&#xA;protocol designers to perform any non-trivial computation off-chain, and&#xA;instead use the blockchain consensus only to verify the computation; or, if&#xA;possible, skip the verification altogether.&#xA;&#xA;The fundamental fact that a blockchain’s layer 1 never actually needs to&#xA;run complex programs in order to enable arbitrary complex smart contracting&#xA;was observed in the past, for example in a 2016 post by Greg Maxwell [3].&#xA;&#xA;Vitalik Buterin popularized the concept of &#34;functionality escape velocity&#34;&#xA;[4] to signify the minimum amount of functionality required on layer 1 in&#xA;order to enable anything else to be built on top (that is, on layer 2 and&#xA;beyond).&#xA;&#xA;In the following section, we will argue that a simple covenant construction&#xA;suffices to achieve the functionality escape velocity in the UTXO model.&#xA;&#xA;&#xA;# Commitments to computation and fraud challenges&#xA;&#xA;In this section, we explore how a smart contract that requires any&#xA;non-trivial computation f : X --&gt; Y (that is too expensive or not feasible&#xA;with on-chain Script state transitions) can be implemented with the simple&#xA;covenants described in the previous section.&#xA;&#xA;The ideas in this section appeared in literature; the reader is referred to&#xA;the references for a more comprehensive discussion.&#xA;&#xA;We want to be able to build contracts that allow conditions of the type&#xA;&#34;f(x) = y&#34;; yet, we do not want layer 1 to be forced to perform any&#xA;expensive computation.&#xA;&#xA;In the following, we assume for simplicity that Alice and Bob are the only&#xA;participants of the covenant, and they both locked some funds bond_A and&#xA;bond_B (respectively) inside the covenant’s UTXO.&#xA;&#xA;1. Alice posts the statement “f(x) = y”.&#xA;2. After a challenge period, if no challenge occurs, Alice is free to&#xA;continue and unlock the funds; the statement is true.&#xA;3. At any time before the challenge period expires, Bob can start a&#xA;challenge: “actually, f(x) = z”.&#xA;&#xA;In case of a challenge, Alice and Bob enter a challenge resolution&#xA;protocol, arbitrated by layer 1; the winner takes the other party’s bond&#xA;(details and the exact game theory vary based on the type of protocol the&#xA;challenge is part of; choosing the right amount of bonds is crucial for&#xA;protocol design).&#xA;&#xA;The remainder of this section sketches an instantiation of the challenge&#xA;protocol.&#xA;&#xA;## The bisection protocol for arbitrary computation&#xA;&#xA;In this section, we sketch the challenge protocol for an arbitrary&#xA;computation f : X --&gt; Y.&#xA;&#xA;### Computation trace&#xA;&#xA;Given the function f, it is possible to decompose the entire computation in&#xA;simple elementary steps, each performing a simple, atomic operation. For&#xA;example, if the domain of x and y is that of binary strings of a fixed&#xA;length, it is possible to create a boolean circuit that takes x and&#xA;produces y; in practice, some form of assembly-like language operating on a&#xA;RAM might be more efficient and fitting for bitcoin Script.&#xA;&#xA;In the following, we assume each elementary operation is operating on a&#xA;RAM, encoded in the state via Merkle trees as sketched above. Therefore,&#xA;one can represent all the steps of the computation as triples tri = (st_i,&#xA;op_i, st_{i + 1}), where st_i is the state (e.g. a canonical Merkle tree of&#xA;the RAM) before the i-th operation, st_{i + 1} is the state after, and op_i&#xA;is the description of the operation (implementation-specific; it could be&#xA;something like “add a to b and save the result in c).&#xA;&#xA;Finally, a Merkle tree M_T is constructed that has as leaves the values of&#xA;the individual computation steps T = {tr_0, tr_1, …, tr_{N - 1}} if the&#xA;computation requires N steps, producing the Merkle root h_T. The height of&#xA;the Merkle tree is log N. Observe that each internal node commits to the&#xA;portion of the computation trace corresponding to its own subtree.&#xA;&#xA;Let’s assume that the Merkle tree commitments for internal nodes are&#xA;further augmented with the states st_{start} and st_{end}, respectively the&#xA;state before the operation of in the leftmost leaf of the subtree, and&#xA;after the rightmost leaf of the subtree.&#xA;&#xA;### Bisection protocol&#xA;&#xA;The challenge protocol begins with Alice posting what she claims is the&#xA;computation trace h_A, while Bob disagrees with the trace h_B != h_A;&#xA;therefore, the challenge starts at the root of M_T, and proceeds in steps&#xA;in order to find a leaf where Alice and Bob disagree (which is guaranteed&#xA;to exist, hence the disagreement). Note that the arbitration mechanism&#xA;knows f, x and y, but not the correct computation trace hash h_T.&#xA;&#xA;(Bisection phase): While the challenge is at a non-leaf node of M_T, Alice&#xA;and Bob take turns to post the two hashes corresponding to the left and&#xA;right child of their claimed computation trace hash; moreover, they post&#xA;the start/end state for each child node. The protocol enforces that Alice’s&#xA;transaction is only valid if the posted hashes h_{l; A} and h_{r; A}, and&#xA;the declared start/end state for each child are consistent with the&#xA;commitment in the current node.&#xA;&#xA;(Arbitration phase): If the protocol has reached the i-th leaf node, then&#xA;each party reveals (st_i, op_i, st_{i + 1}); in fact, only the honest party&#xA;will be able to reveal correct values, therefore the protocol can&#xA;adjudicate the winner.&#xA;&#xA;Remark: there is definitely a lot of room for optimizations; it is left for&#xA;future work to find the optimal variation of the approach; moreover,&#xA;different challenge mechanisms could be more appropriate for different&#xA;functions f.&#xA;&#xA;### Game theory (or why the chain will not see any of this)&#xA;&#xA;With the right economic incentives, protocol designers can guarantee that&#xA;playing a losing game always loses money compared to cooperating.&#xA;Therefore, the challenge game is never expected to be played on-chain. The&#xA;size of the bonds need to be appropriate to disincentivize griefing attacks.&#xA;&#xA;### Implementing the bisection protocol&#39;s state transitions&#xA;&#xA;It is not difficult to see that the entire challenge-response protocol&#xA;above can be implemented using the simple state transitions described above.&#xA;&#xA;Before a challenge begins, the state of the covenant contains the value of&#xA;x, y and the computation trace computed by Alice. When starting the&#xA;challenge, Bob also adds its claim for the correct computation trace, and&#xA;the covenant enters the bisection phase.&#xA;&#xA;During the bisaction phase, the covenant contains the claimed computation&#xA;trace for that node of the computation protocol, according to each party.&#xA;In turns, each party has to reveal the corresponding computation trace for&#xA;both the children of the current node; the transaction is only valid if the&#xA;hash of the current node can be computed correctly from the information&#xA;provided by each party about the child nodes. The protocol repeats on one&#xA;of the two child nodes on whose computation trace the two parties disagree&#xA;(which is guaranteed to exist). If a leaf of M_T is reached, the covenant&#xA;enters the final arbitration phase.&#xA;&#xA;During the arbitration phase (say at the i-th leaf node of M_T), any party&#xA;can win the challenge by providing correct values for tr_i = (st_i, op_i,&#xA;st_{i + 1}). Crucially, only one party is able to provide correct values,&#xA;and Script can verify that indeed the state moves from st_i to st_{i + 1}&#xA;by executing op_i. The challenge is over.&#xA;&#xA;At any time, the covenant allows one player to automatically win the&#xA;challenge after a certain timeout if the other party (who is expected to&#xA;“make his move”) does not spend the covenant. This guarantees that the&#xA;protocol can always find a resolution.&#xA;&#xA;### Security model&#xA;&#xA;As for other protocols (like the lightning network), a majority of miners&#xA;can allow a player to win a challenge by censoring the other player’s&#xA;transactions. Therefore, the bisection protocol operates under the honest&#xA;miner majority assumption. This is acceptable for many protocols, but it&#xA;should certainly be taken into account during protocol design.&#xA;&#xA;&#xA;# MATT covenants&#xA;&#xA;We argued that the key to arbitrary, fully general smart contracts in the&#xA;UTXO model is to use Merkle trees, at different levels:&#xA;&#xA;1. succinctly represent arbitrary state with a single hash. Merkleize the&#xA;state!&#xA;2. succinctly represent the possible state transitions with a single hash.&#xA;Merkleize the Script!&#xA;3. succinctly represent arbitrary computations with a single hash.&#xA;Merkleize the execution!&#xA;&#xA;(1) and (2) alone allow contracts with arbitrary computations; (3) makes&#xA;them scale.&#xA;&#xA;   Merkleize All The Things!&#xA;&#xA;In this section we sketch a design of covenant opcodes that are&#xA;taproot-friendly and could easily be added in a soft fork to the existing&#xA;SegWitv1 Script.&#xA;&#xA;## Embedding covenant data in P2TR outputs&#xA;&#xA;We can take advantage of the double-commitment structure of taproot outputs&#xA;(that is, committing to both a public key and a Merkle tree of scripts) to&#xA;compactly encode both the covenant and the state transition rules inside&#xA;taproot outputs.&#xA;&#xA;The idea is to replace the internal pubkey Q with a key Q’ obtained by&#xA;tweaking Q with the covenant data (the same process that is used to commit&#xA;to the root of the taptree). More precisely, if d is the data committed to&#xA;the covenant, the covenant-data-augmented internal key Q’ is defined as:&#xA;&#xA;    Q’ = Q + int(hashTapCovenantData(Q || h_{data}))G&#xA;&#xA;where h_{data} is the sha256-hash of the covenant data. It is then easy to&#xA;prove that the point is constructed in this way, by repeating the&#xA;calculation.&#xA;&#xA;If there is no useful key path spend, similarly to what is suggested in&#xA;BIP-0341 [5] for the case of scripts with no key path spends, we can use&#xA;the NUMS point:&#xA;    H =&#xA;lift_x(0x0250929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0).&#xA;&#xA;TODO: please double check if the math above is sound.&#xA;&#xA;## Changes to Script&#xA;&#xA;The following might be some minimal new opcodes to add for taproot&#xA;transactions in order to enable the construction above. This is a very&#xA;preliminary proposal, and not yet complete nor correct.&#xA;&#xA;- OP_SHA256CAT: returns the SHA256 hash of the concatenation of the second&#xA;and the first (top) element of the stack. (redundant if OP_CAT is enabled,&#xA;even just on operands with total length up to 64 bytes)&#xA;- OP_CHECKINPUTCOVENANTVERIFY: let x, d be the two top elements of the&#xA;stack; behave like OP_SUCCESS if any of x and d is not exactly 32 bytes;&#xA;otherwise, check that the x is a valid x-only pubkey, and the internal&#xA;pubkey P is indeed obtained by tweaking lift_x(x) with d.&#xA;- OP_INSPECTNUMINPUTS, OP_INSPECTNUMOUTPUTS, OP_INSPECTINPUTVALUE and&#xA;OP_INSPECTOUTPUTVALUE - opcodes to push number on the stack of&#xA;inputs/outputs and their amounts.&#xA;- OP_CHECKOUTPUTCOVENANTVERIFY: given a number out_i and three 32-byte hash&#xA;elements x, d and taptree on top of the stack, verifies that the out_i-th&#xA;output is a P2TR output with internal key computed as above, and tweaked&#xA;with taptree. This is the actual covenant opcode.&#xA;&#xA;TODO:&#xA;&#xA;- Many contracts need parties to provide additional data; simply passing it&#xA;via the witness faces the problem that it could be malleated. Therefore, a&#xA;way of passing signed data is necessary. One way to address this problem&#xA;could be to add a commitment to the data in the annex, and add an opcode to&#xA;verify such commitment. Since the annex is covered by the signature, this&#xA;removes any malleability. Another option is an OP_CHECKSIGFROMSTACK opcode,&#xA;but that would cost an additional signature check.&#xA;- Bitcoin numbers in current Script are not large enough for amounts.&#xA;&#xA;Other observations:&#xA;&#xA;- OP_CHECKINPUTCOVENANTVERIFY and OP_CHECKOUTPUTCOVENANTVERIFY could have a&#xA;mode where x is replaced with a NUMS pubkey, for example if the first&#xA;operand is an empty array of bytes instead of a 32 byte pubkey; this saves&#xA;about 31 bytes when no internal pubkey is needed (so about 62 bytes for a&#xA;typical contract transition using both opcodes)&#xA;- Is it worth adding other introspection opcodes, for example&#xA;OP_INSPECTVERSION, OP_INSPECTLOCKTIME? See Liquid&#39;s Tapscript Opcodes [6].&#xA;- Is there any malleability issue? Can covenants “run” without signatures,&#xA;or is a signature always to be expected when using spending conditions with&#xA;the covenant encumbrance? That might be useful in contracts where no&#xA;signature is required to proceed with the protocol (for example, any party&#xA;could feed valid data to the bisection protocol above).&#xA;- Adding some additional opcodes to manipulate stack elements might also&#xA;bring performance improvements in applications (but not strictly necessary&#xA;for feasibility).&#xA;&#xA;Remark: the additional introspection opcodes available in Blockstream&#xA;Liquid [6] do indeed seem to allow MATT covenants; in fact, the opcodes&#xA;OP_CHECKINPUTCOVENANTVERIFY and OP_CHECKOUTPUTCOVENANTVERIFY could be&#xA;replaced by more general opcodes like the group {OP_TWEAKVERIFY,&#xA;OP_INSPECTINPUTSCRIPTPUBKEY, OP_PUSHCURRENTINPUTINDEX,&#xA;OP_INSPECTOUTPUTSCRIPTPUBKEY }.&#xA;&#xA;### Variant: bounded recursivity&#xA;&#xA;In the form described above, the covenant essentially allows fully&#xA;recursive constructions (an arbitrary depth of the covenant execution tree&#xA;is in practice equivalent to full recursion).&#xA;&#xA;If recursivity is not desired, one could modify the covenants in a way that&#xA;only allows a limited depth: a counter could be attached to the covenant,&#xA;with the constraint that the counter must be decreased for&#xA;OP_CHECKOUTPUTCOVENANTVERIFY. That would still allow arbitrary fraud proofs&#xA;as long as the maximum depth is sufficient.&#xA;&#xA;However, that would likely reduce its utility and prevent certain&#xA;applications where recursivity seems to be a requirement.&#xA;&#xA;The full exploration of the design space is left for future research.&#xA;&#xA;&#xA;# Applications&#xA;&#xA;This section explores some of the potential use cases of the techniques&#xA;presented above. The list is not exhaustive.&#xA;&#xA;Given the generality of fraud proofs, some variant of every kind of smart&#xA;contracts or layer two construction should be possible with MATT covenants,&#xA;although the additional requirements (for example the capital lockup and&#xA;the challenge period delays) needs to be accurately considered; further&#xA;research is necessary to assess for what applications the tradeoffs are&#xA;acceptable.&#xA;&#xA;## State channels&#xA;&#xA;A state channel is a generalization of a payment channel where,&#xA;additionally to the balance at the end of each channel, some additional&#xA;state is stored. The state channel also specifies what are the rules on how&#xA;to update the channel’s state.&#xA;&#xA;For example, two people might play a chess game, where the state encodes&#xA;the current configuration of the board. The valid state transitions&#xA;correspond to the valid moves; and, once the game is over, the winner takes&#xA;a specified amount of the channel’s money.&#xA;&#xA;With eltoo-style updates, such a game could be played entirely off-chain,&#xA;as long as both parties are cooperating (by signing the opponent’s state&#xA;update).&#xA;&#xA;The role of the blockchain is to guarantee that the game can be moved&#xA;forward and eventually terminated in case the other party does not&#xA;cooperate.&#xA;&#xA;In stateful blockchain, this is simply achieved by publishing the latest&#xA;state (Merkleized or not) and then continuing the entire game on-chain.&#xA;This is expensive, especially if the state transitions require some complex&#xA;computation.&#xA;&#xA;An alternative that avoids moving computations on-chain is the use of a&#xA;challenge-response protocol, as sketched above.&#xA;&#xA;Similarly to the security model of lightning channels, an honest party can&#xA;always win a challenge under the honest-majority of miners. Therefore, it&#xA;is game-theoretically losing to attempt cheating in a channel.&#xA;&#xA;## CoinPool&#xA;&#xA;Multiparty state channels are possible as well; therefore, constructions&#xA;like CoinPool [7] should be possible, enabling multiple parties to share a&#xA;single UTXO.&#xA;&#xA;## Zero knowledge proofs in L2 protocols&#xA;&#xA;Protocols based on ZK-proofs require the blockchain to be the verifier; the&#xA;verifier is a function that takes a zero-knowledge proof and returns&#xA;true/false based on its correctness.&#xA;&#xA;Instead of an OP_STARK operator in L1, one could think of compiling the&#xA;OP_STARK as the function f in the protocol above.&#xA;&#xA;Note that covenants with a bounded “recursion depth” are sufficient to&#xA;express OP_STARK, which in turns imply the ability to express arbitrary&#xA;functions within contracts using the challenge protocol.&#xA;&#xA;One advantage of this approach is that no new cryptographic assumptions are&#xA;added to bitcoin’s layer 1 even if OP_STARK does require it; moreover, if a&#xA;different or better OP_STARK2 is discovered, the innovation can reach layer&#xA;2 contracts without any change needed in layer 1.&#xA;&#xA;## Optimistic rollups&#xA;&#xA;John Light recently posted a research report on how Validity Rollups could&#xA;be added to bitcoin’s layer 1 [8]. While no exact proposal is pushed&#xA;forward, the suggested changes required might include a combination of&#xA;recursive covenants, and specific opcodes for validity proof verification.&#xA;&#xA;Fraud proofs are the core for optimistic rollups; exploring the possibility&#xA;of implementing optimistic rollups with MATT covenants seems a promising&#xA;direction. Because of the simplicity of the required changes to Script,&#xA;this might answer some of the costs and risks analyzed in the report, while&#xA;providing many of the same benefits. Notably, no novel cryptography needs&#xA;to become part of bitcoin’s layer 1.&#xA;&#xA;Optimistic Rollups would probably require a fully recursive version of the&#xA;covenant (while fraud proofs alone are possible with a limited recursion&#xA;depth).&#xA;&#xA;&#xA;# Acknowledgments&#xA;&#xA;Antoine Poinsot suggested an improvement to the original proposed covenant&#xA;opcodes, which were limited to taproot outputs without a valid key-path&#xA;spend.&#xA;&#xA;The author would also like to thank catenocrypt, Antoine Riard, Ruben&#xA;Somsen and the participants of the BTCAzores unconference for many useful&#xA;discussions and comments on early versions of this proposal.&#xA;&#xA;&#xA;# References&#xA;&#xA;The core idea of the bisection protocol appears to have been independently&#xA;rediscovered multiple times. In blockchain research, it is at the core of&#xA;fraud proof constructions with similar purposes, although not focusing on&#xA;bitcoin or covenants; see for example:&#xA;&#xA;- Harry Kalodner et al. “Arbitrum: Scalable, private smart contracts.” −&#xA;27th USENIX Security Symposium. 2018.&#xA;https://www.usenix.org/system/files/conference/usenixsecurity18/sec18-kalodner.pdf&#xA;- Jason Teutsch and Christian Reitwiessner. “A scalable verification&#xA;solution for blockchains” − TrueBit protocol. 2017.&#xA;https://people.cs.uchicago.edu/~teutsch/papers/truebit.pdf&#xA;&#xA;The same basic idea was already published prior to blockchain use cases;&#xA;see for example:&#xA;&#xA;Ran Canetti, Ben Riva, and Guy N. Rothblum. “Practical delegation of&#xA;computation using multiple servers.” − Proceedings of the 18th ACM&#xA;conference on Computer and communications security. 2011.&#xA;http://diyhpl.us/~bryan/papers2/bitcoin/Practical%20delegation%20of%20computation%20using%20multiple%20servers.pdf&#xA;&#xA;&#xA;&#xA;# Footnotes&#xA;&#xA;[1] - https://btcazores.com&#xA;[2] - https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki&#xA;[3] -&#xA;https://bitcointalk.org/index.php?topic=1427885.msg14601127#msg14601127&#xA;[4] - https://vitalik.ca/general/2019/12/26/mvb.html&#xA;[5] -&#xA;https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki#constructing-and-spending-taproot-outputs&#xA;[6] -&#xA;https://github.com/ElementsProject/elements/blob/master/doc/tapscript_opcodes.md&#xA;[7] - https://coinpool.dev/v0.1.pdf&#xA;[8] - https://bitcoinrollups.org&#xA;-------------- next part --------------&#xA;An HTML attachment was scrubbed...&#xA;URL: &lt;http://lists.linuxfoundation.org/pipermail/bitcoin-dev/attachments/20221108/d6f2d8a3/attachment-0001.html&gt;</html></oembed>