Return-Path: Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id E42E5C002A for ; Mon, 1 May 2023 13:11:22 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id C629660E78 for ; Mon, 1 May 2023 13:11:22 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org C629660E78 Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=G3AblKoS X-Virus-Scanned: amavisd-new at osuosl.org X-Spam-Flag: NO X-Spam-Score: -2.098 X-Spam-Level: X-Spam-Status: No, score=-2.098 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id im-GECjQeZMW for ; Mon, 1 May 2023 13:11:20 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org AC9A060B71 Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by smtp3.osuosl.org (Postfix) with ESMTPS id AC9A060B71 for ; Mon, 1 May 2023 13:11:20 +0000 (UTC) Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-547705d6197so1470230eaf.3 for ; Mon, 01 May 2023 06:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682946679; x=1685538679; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=NohhQtkS3D776C6r/FcmunrfUlybdvC9qQr3xpqeUvY=; b=G3AblKoSyebtmNOPRfeUuivpuTbEV11uLc/mInnW24wB9M0HtSXzK2MlM8DrP76Ssu aVGD1t/VrJi+JMPwZ1VImAmT04k/++M2iZuYjRTAd1ZM85Y0DCMH2A/TlVbK0wrZGeJU 00H2GyWgCVsApIcve0pAUMWqMo0tN5CziZsAH57S1cg9vUv9mgmuA6b62SydKYf+gaaP moxT1/i0oIAWCOxOTvyf1CnXXSmMGia+2bLurSroqPiqyHq0fuWAjSVEhT+zrW4wm9qt yJYsqJ+bQlbaECAUmDKiQAMBip0084BWfm6ahhqOTWnG879vzYTFaxdTcmUxLI8gmZ04 zSpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682946679; x=1685538679; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NohhQtkS3D776C6r/FcmunrfUlybdvC9qQr3xpqeUvY=; b=TAvV4Tc9fJ4qg0Pn9zP80Du60lYTzvxZajbIJU4Vi1H7V0pnY1PUYZkSDeYLmn2RFn kHnCOWarRro6sq2F2rcm/xWt12dx8ek0Tk8BcWczKNmg5hJYmcfS6Rl3gfOzOnPmUaaj W+jySZV7kNMXeCxpS2UWlCvfHxo6lpLCPR2JQKV4nUNzIbi+h4GwkXCkzrv69Kha2Do4 pKCUQjrC5v2UM3vFaiGeLTHjGaoxhouaOulcVt0G4Kg7nI3dytkrZrAa1NRb00D8J/4m VPgCBjIrG9dO22Eq8zDexr/DeamGxZeVlAqWakV9ij833MYZfxeCLa5r09rx/+yUlvxi zVvw== X-Gm-Message-State: AC+VfDwqjkOGyvPlkCS9NZ5yOej3q6UuZkQ267Ob66wP/MxBgl7q8Xs2 cBesudKItCSKAgEVobwynxeBcHMDF67vTIZH78RsW2BNPhAMbA== X-Google-Smtp-Source: ACHHUZ6biVTS3L3lb881cWDx/iL9zL/MLjLptAoGGIeCh8m5pyudWNXZ51fHSzMRtppYkdl4wObxwvjTBLI39eAoHTw= X-Received: by 2002:a4a:d688:0:b0:546:3aa4:3db8 with SMTP id i8-20020a4ad688000000b005463aa43db8mr6570485oot.5.1682946679366; Mon, 01 May 2023 06:11:19 -0700 (PDT) MIME-Version: 1.0 References: <0f352f70-c93a-614f-e443-67d198ec2c26@protonmail.com> <7f3674d1-c1ad-9a82-e30f-7cf24d697faf@protonmail.com> In-Reply-To: From: Salvatore Ingala Date: Mon, 1 May 2023 15:11:08 +0200 Message-ID: To: =?UTF-8?Q?Johan_Tor=C3=A5s_Halseth?= , Bitcoin Protocol Discussion Content-Type: multipart/alternative; boundary="000000000000ffe94505faa18eb7" X-Mailman-Approved-At: Mon, 01 May 2023 14:37:03 +0000 Subject: Re: [bitcoin-dev] Merkleize All The Things X-BeenThere: bitcoin-dev@lists.linuxfoundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Bitcoin Protocol Discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 May 2023 13:11:23 -0000 --000000000000ffe94505faa18eb7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Johan, Thanks for your message. I think games where all the possible futures can be enumerated are not ideal to showcase MATT, as one could just fully represent them with just CTV or COCV, and not use the "data embedding" at all. Perhaps rock-paper-scissors could be a better academic example. [1] I'm not sure this will fully address your question; however I think it's quite an instructive example, and I wanted to work it out for quite some time. It would be interesting to explore some contracts where the size of the embedded data is substantially larger, and that could be a natural next step to think about. ### Rock paper scissors We want a protocol between Alice and Bob, where they bet 1 coin each: 1. Alice chooses and publishes her move; 2. Bob chooses his move, and the pot is adjudicated as per the rules. Of course, if implemented naively, this wouldn't be a very fun game: Bob would just wait to see Alice's move and play accordingly. That's easy to fix, though: 1. Alice publishes a commitment to her move 2. Bob publishes his move in clear 3. Alice reveals her move, and the pot is adjudicated. We can encode Rock =3D 0, Paper =3D 1, Scissors =3D 2. Let m_A, m_B be Alice's and Bob's move, respectively. Then, it's easy to verify that: =E2=88=92 m_B - m_A =3D=3D 0 (mod 3) =3D=3D> it's a tie =E2=88=92 m_B - m_A =3D=3D 1 (mod 3) =3D=3D> Bob wins =E2=88=92 m_B - m_A =3D=3D 2 (mod 3) =3D=3D> Alice wins In order to create a hiding commitment for Alice, she can choose a 256-bit random number r_A, and compute: c_A =3D SHA256(m_A || r_A) With that in mind, the full protocol can go like this: 1. Alice chooses her move m_A and a large random number r_A; she posts c_A computed as above; 2. Bob chooses m_B and publishes it; 3. Alice publishes m_A and r_A, then the winner is adjudicated. ### MATT playing RPS To implement this with CICV/COCV, we can use just 3 transactions: in fact, Alice can already compute c_A and share it with Bob before they both commit their coins into an encumbered UTXO. That also means that c_A can actually be hardcoded in the Scripts, rather than taking space in the UTXO's embedded data. Therefore, they both put one coin each, and they send to an output whose script is the state S0 described below. We assume that the keypath in the P2TR defined below is either a NUMS point, or perhaps a Musig2 aggregate key that can be used to settle the game collaboratively. Note that there are 3 possible payout options that are fully known when the game starts: either Alice takes all the money, or they split evenly, or Bob takes all the money. Similarly to the vault implementation [2], this seems to be another case where CTV fits very well, as it allows to very efficiently describe the three possible outcomes by their CTV hashes. Let them be , , , respectively. Therefore, this avoids the need for 64-bit maths, and explicit amount introspection =E2=88=92 at least for these contracts. [State S0] (Start of the game, Alice moved; Bob's turn) Spending conditions: - after , Alice takes the money // (Bob forfaits) - Bob posts m_B (0, 1 or 2); the next output is [S1] with data m_B The first script is: // witness: [] OP_CHECKSEQUENCEVERIFY OP_DROP OP_CHECKTEMPLATEVERIFY The second is // witness: [ ] OP_DUP 0 3 OP_WITHIN // check that m_B is 0, 1 or 2 OP_SWAP OP_CHECKOUTPUTCONTRACTVERIFY // check that the output is correct OP_CHECKSIG [State S1] (Alice reveals m_A and adjudicates) - after , Bob takes the money // (Alice forfaits) - Alice posts correct m_A and r_A compatible with c_A; The first script is symmetric to Bob's forfait script above. The second condition can be split into three leaf scripts, one for each possible value of m_B - m_A (mod 3): // witness: [ ] OP_OVER OP_DUP OP_TOALTSTACK // save m_A 0 3 OP_WITHIN OP_VERIFY // check that m_A is 0, 1 or 2 // check that SHA256(m_A || r_A) equals c_A OP_2DUP OP_CAT OP_SHA256 OP_EQUALVERIFY OP_DUP , OP_SWAP OP_CHECKINPUTCONTRACTVERIFY OP_FROMALTSTACK OP_SUB // stack now contains m_B - m_A OP_DUP // if the result is negative, add 3 0 OP_LESSTHAN OP_IF 3 OP_ADD OP_ENDIF {0, 1, 2} // draw / Bob wins / Alice wins, respectively OP_EQUALVERIFY {, , } // respectively OP_CHECKTEMPLATEVERIFY ### Comments In general, we would have to worry about the possible malleability of the witness elements, when they are not signatures or preimages themselves. Here, in particular, it might seem that's an issue when is provided while spending the state [S0]. However, here the value of is also committed to in the output thanks to COCV; therefore, Bob's signature prevents malleability also for m_B. In general, it seems to be the case in MATT contracts that one would want the signature of the authorized party performing a transition to some other state of the smart contract with contains embedded data; this makes the malleability issue less of a problem in practice than I initially thought. If the internal_pubkey is a musig-aggregated key of Alice and Bob, the game can be settled entirely offline after the first transaction. Simply, Bob communicates his move to Alice, Alice reveals her move to Bob, and they can settle the bet. The game would be played without any script being executed, therefore all transactions could look like any other P2TR, with the only possible fingerprinting being due to the input amounts. It should be possible to generalize the protocol so that many rounds can be played off-chain within the same UTXO, but I didn't try to figure out the details. Best, Salvatore Ingala [1] - https://en.wikipedia.org/wiki/Rock_paper_scissors [2] - https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2023-April/021588.h= tml On Fri, 28 Apr 2023 at 10:48, Johan Tor=C3=A5s Halseth = wrote: > Hi, Salvatore. > > I find this proposal very interesting. Especially since you seemingly > can achieve such powerful capabilities by such simple opcodes. > > I'm still trying to grok how this would look like on-chain (forget > about the off-chain part for now), if we were to play out such a > computation. > > Let's say you have a simple game like "one player tic-tac-toe" with > only two tiles: [ _ | _ ]. The player wins if he can get two in a row > (pretty easy game tbh). > > Could you give a complete example how you would encode one such state > transition (going from [ X, _ ] -> [ X, X ] for instance) in Bitcoin > script? > > Feel free to choose a different game or program if you prefer :) > > Thanks! > Johan > > > > On Tue, Dec 13, 2022 at 2:08=E2=80=AFPM Billy Tetrud via bitcoin-dev > wrote: > > > > Re Verkle trees, that's a very interesting construction that would be > super useful as a tool for something like Utreexo. A potentially > substantial downside is that it seems the cryptography used to get those > nice properties of Verkle trees isn't quantum safe. While a lot of things > in Bitcoin seems to be going down the path of quantum-unsafe (I'm looking > at you, taproot), there are still a lot of people who think quantum safet= y > is important in a lot of contexts. > > > > On Thu, Dec 1, 2022 at 5:52 AM Salvatore Ingala via bitcoin-dev < > bitcoin-dev@lists.linuxfoundation.org> wrote: > >> > >> Hello Rijndael, > >> > >> > >> > >> On Wed, 30 Nov 2022 at 23:09, Rijndael > wrote: > >>> > >>> Hello Salvatore, > >>> > >>> I found my answer re-reading your original post: > >>> > During the arbitration phase (say at the i-th leaf node of M_T), an= y > party can win the challenge by providing correct values for tr_i =3D (st_= i, > op_i, st_{i + 1}). Crucially, only one party is able to provide correct > values, and Script can verify that indeed the state moves from st_i to > st_{i + 1} by executing op_i. The challenge is over. > >> > >> You are correct, the computation step encoded in a leaf needs to be > simple enough for Script to verify it. > >> > >> For the academic purpose of proving completeness (that is, any > computation can be successfully "proved" by the availability of the > corresponding fraud proof), one can imagine reducing the computation all > the way down to a circuit, where each step (leaf) is as simple as what ca= n > be checked with {OP_NOT, OP_BOOLAND, OP_BOOLOR, OP_EQUAL}. > >> > >> In practice, you would want to utilize Script to its fullest, so for > example you wouldn't compile a SHA256 computation to something else =E2= =80=93 you'd > rather use OP_SHA256 directly. > >> > >>> > >>> That raises leads to a different question: Alice initially posts a > commitment to an execution trace of `f(x) =3D y`, `x`, and `y`. Bob Disag= rees > with `y` so starts the challenge protocol. Is there a commitment to `f`? = In > other words, the dispute protocol (as I read it) finds the leftmost step = in > Alice and Bob's execution traces that differ, and then rewards the coins = to > the participant who's "after-value" is computed by the step's operation > applied to the "before value". But if the participants each present valid > steps but with different operations, who wins? In other words, Alice coul= d > present [64, DECREMENT, 63] and Bob could present [64, INCREMENT, 65]. > Those steps don't match, but both are valid. Is there something to ensure > that before the challenge protocol starts, that the execution trace that > Alice posts is for the right computation and not a different computation > that yields a favorable result for her (and for which she can generate a > valid merkle tree)? > >> > >> > >> The function f is already hard-coded in the contract itself, by means > of the tree of scripts =E2=88=92 that already commits to the possible fut= ures. > Therefore, once you are at state S14, you know that you are verifying the > 6th step of the computation; and the operation in the 6th step of the > computation depends solely on f, not its inputs. In fact, you made me > realize that I could drop op_i from the i-th leaf commitment, and just > embed the information in the Script of that corresponding state. > >> > >> Note that the states S0 to S14 of the 256x game are not _all_ the > possible states, but only the ones that occurred in that execution of the > contract (corresponding to a path from the root to the leaf of the Merkle > tree of the computation trace), and therefore the ones that materialized = in > a UTXO. Different choices made by the parties (by providing different dat= a, > and therefore choosing different branches) would lead to a different leaf= , > and therefore to different (but in a certain sense "symmetric") states. > >> > >> =3D=3D=3D=3D=3D=3D=3D=3D > >> > >> Since we are talking about the fact that f is committed to in the > contract, I'll take the chance to extend on this a bit with a fun > construction on top. > >> It is well-known in the academic literature of state channels that you > can create contracts where even the function ("program", or "contract") i= s > not decided when the channel is created. > >> > >> Since f is generic, we can choose f itself to be a universal Turing > machine. That is, we can imagine a function f(code, data) that executes a > program ("code") on the "data" given to it as input. > >> Since we can do fraud proofs on statements "f(code, data) =3D=3D outpu= t", > we could build contracts where the "code" itself is chosen later. > >> > >> For example, one could build a universal state channel, where parties > can enter any contract among themselves (e.g.: start playing a chess game= ) > entirely inside the channel. The state of this universal channel would > contain all the states of the individual contracts that are currently ope= n > in the channel, and even starting/closing contracts can happen entirely > off-chain. > >> > >> I believe these constructions are practical (the code of universal > Turing machines is not really complicated), so it might be worth explorin= g > further to figure out useful applications of this approach (supercharging > lightning?). > >> > >> We should probably start by implementing testnet rock-paper-scissors i= n > MATT, though :) > >> > >> Best, > >> Salvatore Ingala > >> _______________________________________________ > >> bitcoin-dev mailing list > >> bitcoin-dev@lists.linuxfoundation.org > >> https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev > > > > _______________________________________________ > > bitcoin-dev mailing list > > bitcoin-dev@lists.linuxfoundation.org > > https://lists.linuxfoundation.org/mailman/listinfo/bitcoin-dev > --000000000000ffe94505faa18eb7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Johan,

Thanks for y= our message.

I think games where all the possible futures can be enu= merated are
not ideal to showcase MATT, as one could just fully represen= t them
with just CTV or COCV, and not use the "data embeddin= g" at all.

Perhaps rock-paper-scissors could be a better academ= ic example. [1]

I'm not sure this will fully address your questi= on; however I think
it's quite an instructive example, and I = wanted to work it out for
quite some time.

It would be interesting to explore some contracts where the size
of the embedded data is substantially larger, and that could be
a natural next step to=C2=A0think=C2=A0about.

### Rock paper scissors

We want a protocol between Alice and Bob, = where they bet 1 coin each:

1. Alice chooses and publishes her move;=
2. Bob chooses his move, and the pot is adjudicated as per the rules.
Of course, if implemented naively, this wouldn't be a very fun ga= me:
Bob would just wait to see Alice's move and play accordingly.
That's easy to fix, though:

1. Alice publishes a commitment= to her move
2. Bob publishes his move in clear
3. Alice reveals her = move, and the pot is adjudicated.

We can encode Rock =3D 0, Paper = =3D 1, Scissors =3D 2. Let m_A, m_B be
Alice's and Bob's move, r= espectively. Then, it's easy to verify that:
=E2=88=92 m_B - m_A =3D= =3D 0 (mod 3) =3D=3D> it's a tie
=E2=88=92 m_B - m_A =3D=3D 1 (mo= d 3) =3D=3D> Bob wins
=E2=88=92 m_B - m_A =3D=3D 2 (mod 3) =3D=3D>= Alice wins

In order to create a hiding commitment for Alice, she ca= n choose a
256-bit random number r_A, and compute:

=C2=A0 c_A =3D= SHA256(m_A || r_A)

With that in mind, the full protocol can go like= this:

1. Alice chooses her move m_A and a large random number r_A;<= br>=C2=A0 =C2=A0she posts c_A computed as above;
2. Bob chooses m_B and = publishes it;
3. Alice publishes m_A and r_A, then the winner is adjudic= ated.


### MATT playing RPS

To implement this w= ith CICV/COCV, we can use just 3 transactions: in
fact, Alice can alread= y compute c_A and share it with Bob before they
both commit their coins = into an encumbered UTXO. That also means that
c_A can actually be hardco= ded in the Scripts, rather than taking
space in the UTXO's embedded = data.

Therefore, they both put one coin each, and they send to an ou= tput
whose script is the state S0 described below.

We = assume that the keypath in the P2TR defined below is either a NUMS
point= , or perhaps a Musig2 aggregate key that can be used to settle
the game = collaboratively.

Note that there are 3 possible payout op= tions that are fully known
when the game starts: either Alice takes all = the money, or they split
evenly, or Bob takes all the money.
Similarl= y to the vault implementation [2], this seems to be another
case where C= TV fits very well, as it allows to very efficiently
describe the three p= ossible outcomes by their CTV hashes. Let them
be <ctv-alice-wins>= , <ctv-split>, <ctv-bob-wins>, respectively.

= Therefore, this avoids the need for 64-bit maths, and explicit amount
=
introspection =E2=88=92 at least for these contracts.


[Stat= e S0] (Start of the game, Alice moved; Bob's turn)
Spending conditio= ns:
=C2=A0- after <forfait-delay>, Alice takes the money =C2=A0 = =C2=A0// (Bob forfaits)
=C2=A0- Bob posts m_B (0, 1 or 2); the next outp= ut is [S1] with data m_B

The first script is:
=C2=A0 // witness: = []
=C2=A0 <forfait-delay>
=C2=A0 OP_CHECKSEQUENCEVERIFY
=C2= =A0 OP_DROP
=C2=A0 <ctv-alice-wins>
=C2=A0 OP_CHECKTEMPLATEVERI= FY

The second is
=C2=A0 // witness: [<bob_sig> <m_B>]=
=C2=A0 OP_DUP 0 3 OP_WITHIN =C2=A0 =C2=A0 // check that m_B is 0, 1 or = 2

=C2=A0 <internal_pubkey> OP_SWAP
=C2=A0 <S1's tapt= ree>
=C2=A0 OP_CHECKOUTPUTCONTRACTVERIFY // check that the output is = correct

=C2=A0 <bob_pubkey>
=C2=A0 OP_CHECKSIG

[State S1] (Alice reveals m_A and adjudicates)
=C2=A0- after <f= orfait-timeout>, Bob takes the money =C2=A0 =C2=A0// (Alice forfaits)=C2=A0- Alice posts correct m_A and r_A compatible with c_A; =C2=A0

The first script is symmetric to Bob's forfait script above.
The second condition can be split into three leaf scripts, one for
eac= h possible value of m_B - m_A (mod 3):

=C2=A0 // witness: [<m_B&g= t; <m_A> <r_A>]

=C2=A0 OP_OVER OP_DUP OP_TOALTSTACK =C2= =A0// save m_A
=C2=A0 0 3 OP_WITHIN OP_VERIFY =C2=A0 =C2=A0 =C2=A0 // ch= eck that m_A is 0, 1 or 2

=C2=A0 // check that SHA256(m_A || r_A) eq= uals c_A
=C2=A0 OP_2DUP
=C2=A0 OP_CAT OP_SHA256
=C2=A0 <c_A>=
=C2=A0 OP_EQUALVERIFY

=C2=A0 OP_DUP
=C2=A0 <internal_pubke= y>, OP_SWAP
=C2=A0 OP_CHECKINPUTCONTRACTVERIFY

=C2=A0 OP_FROMA= LTSTACK
=C2=A0 OP_SUB =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 // stack now co= ntains m_B - m_A

=C2=A0 OP_DUP =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 //= if the result is negative, add 3
=C2=A0 0 OP_LESSTHAN
=C2=A0 OP_IF=C2=A0 =C2=A0 3
=C2=A0 =C2=A0 OP_ADD
=C2=A0 OP_ENDIF

=C2=A0 = {0, 1, 2} =C2=A0 =C2=A0 =C2=A0 // draw / Bob wins / Alice wins, respectivel= y
=C2=A0 OP_EQUALVERIFY

=C2=A0 {<ctv-split>, <ctv-bob-wi= ns>, <ctv-alice-wins>} =C2=A0// respectively
=C2=A0 OP_CHECKTEM= PLATEVERIFY


### Comments

In general, we would have to wor= ry about the possible
malleability of the witness elements, when they ar= e not signatures
or preimages themselves. Here, in particular, it might = seem that's
an issue when <m_B> is provided while spend= ing the state [S0].
However, here the value of <m_B> is als= o committed to in the output
thanks to COCV; therefore, Bob's signat= ure prevents malleability
also for m_B.

In general, it see= ms to be the case in MATT contracts that one would
want the signature of= the authorized party performing a transition to
some other state of the= smart contract with contains embedded data;
this makes the malleability= issue less of a problem in practice than
I initially thought.
If the internal_pubkey is a musig-aggregated key of Alice and Bob,
= the game can be settled entirely offline after the first transaction.
Si= mply, Bob communicates his move to Alice, Alice reveals her move to
Bob,= and they can settle the bet. The game would be played without
any scrip= t being executed, therefore all transactions could look like
any = other P2TR,=C2=A0with the only possible fingerprinting being due to the
input amounts.

It should be possible to generalize the protoc= ol so that many rounds
can be played off-chain within the same UTXO, but= I didn't try to
figure out the details.

Best,
Salvatore I= ngala


[1] - https://en.wikipedia.org/wiki/Rock_paper_scissors
[2] - https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2023-= April/021588.html

On Fri, 28 Apr 2023 at 10:48, Johan Tor=C3= =A5s Halseth <johanth@gmail.com= > wrote:
Hi, = Salvatore.

I find this proposal very interesting. Especially since you seemingly
can achieve such powerful capabilities by such simple opcodes.

I'm still trying to grok how this would look like on-chain (forget
about the off-chain part for now), if we were to play out such a
computation.

Let's say you have a simple game like "one player tic-tac-toe"= ; with
only two tiles: [ _ | _ ]. The player wins if he can get two in a row
(pretty easy game tbh).

Could you give a complete example how you would encode one such state
transition (going from [ X, _ ] -> [ X, X ] for instance) in Bitcoin
script?

Feel free to choose a different game or program if you prefer :)

Thanks!
Johan



On Tue, Dec 13, 2022 at 2:08=E2=80=AFPM Billy Tetrud via bitcoin-dev
<bitcoin-dev@lists.linuxfoundation.org> wrote:
>
> Re Verkle trees, that's a very interesting construction that would= be super useful as a tool for something like Utreexo. A potentially substa= ntial downside is that it seems the cryptography used to get those nice pro= perties of Verkle trees isn't quantum safe. While a lot of things in Bi= tcoin seems to be going down the path of quantum-unsafe (I'm looking at= you, taproot), there are still a lot of people who think quantum safety is= important in a lot of contexts.
>
> On Thu, Dec 1, 2022 at 5:52 AM Salvatore Ingala via bitcoin-dev <bi= tcoin-dev@lists.linuxfoundation.org> wrote:
>>
>> Hello Rijndael,
>>
>>
>>
>> On Wed, 30 Nov 2022 at 23:09, Rijndael <rot13maxi@protonmail.com> wro= te:
>>>
>>> Hello Salvatore,
>>>
>>> I found my answer re-reading your original post:
>>> > During the arbitration phase (say at the i-th leaf node o= f M_T), any party can win the challenge by providing correct values for tr_= i =3D (st_i, op_i, st_{i + 1}). Crucially, only one party is able to provid= e correct values, and Script can verify that indeed the state moves from st= _i to st_{i + 1} by executing op_i. The challenge is over.
>>
>> You are correct, the computation step encoded in a leaf needs to b= e simple enough for Script to verify it.
>>
>> For the academic purpose of proving completeness (that is, any com= putation can be successfully "proved" by the availability of the = corresponding fraud proof), one can imagine reducing the computation all th= e way down to a circuit, where each step (leaf) is as simple as what can be= checked with {OP_NOT, OP_BOOLAND, OP_BOOLOR, OP_EQUAL}.
>>
>> In practice, you would want to utilize Script to its fullest, so f= or example you wouldn't compile a SHA256 computation to something else = =E2=80=93 you'd rather use OP_SHA256 directly.
>>
>>>
>>> That raises leads to a different question: Alice initially pos= ts a commitment to an execution trace of `f(x) =3D y`, `x`, and `y`. Bob Di= sagrees with `y` so starts the challenge protocol. Is there a commitment to= `f`? In other words, the dispute protocol (as I read it) finds the leftmos= t step in Alice and Bob's execution traces that differ, and then reward= s the coins to the participant who's "after-value" is compute= d by the step's operation applied to the "before value". But = if the participants each present valid steps but with different operations,= who wins? In other words, Alice could present [64, DECREMENT, 63] and Bob = could present [64, INCREMENT, 65]. Those steps don't match, but both ar= e valid. Is there something to ensure that before the challenge protocol st= arts, that the execution trace that Alice posts is for the right computatio= n and not a different computation that yields a favorable result for her (a= nd for which she can generate a valid merkle tree)?
>>
>>
>> The function f is already hard-coded in the contract itself, by me= ans of the tree of scripts =E2=88=92 that already commits to the possible f= utures. Therefore, once you are at state S14, you know that you are verifyi= ng the 6th step of the computation; and the operation in the 6th step of th= e computation depends solely on f, not its inputs. In fact, you made me rea= lize that I could drop op_i from the i-th leaf commitment, and just embed t= he information in the Script of that corresponding state.
>>
>> Note that the states S0 to S14 of the 256x game are not _all_ the = possible states, but only the ones that occurred in that execution of the c= ontract (corresponding to a path from the root to the leaf of the Merkle tr= ee of the computation trace), and therefore the ones that materialized in a= UTXO. Different choices made by the parties (by providing different data, = and therefore choosing different branches) would lead to a different leaf, = and therefore to different (but in a certain sense "symmetric") s= tates.
>>
>> =3D=3D=3D=3D=3D=3D=3D=3D
>>
>> Since we are talking about the fact that f is committed to in the = contract, I'll take the chance to extend on this a bit with a fun const= ruction on top.
>> It is well-known in the academic literature of state channels that= you can create contracts where even the function ("program", or = "contract") is not decided when the channel is created.
>>
>> Since f is generic, we can choose f itself to be a universal Turin= g machine. That is, we can imagine a function f(code, data) that executes a= program ("code") on the "data" given to it as input. >> Since we can do fraud proofs on statements "f(code, data) =3D= =3D output", we could build contracts where the "code" itsel= f is chosen later.
>>
>> For example, one could build a universal state channel, where part= ies can enter any contract among themselves (e.g.: start playing a chess ga= me) entirely inside the channel. The state of this universal channel would = contain all the states of the individual contracts that are currently open = in the channel, and even starting/closing contracts can happen entirely off= -chain.
>>
>> I believe these constructions are practical (the code of universal= Turing machines is not really complicated), so it might be worth exploring= further to figure out useful applications of this approach (supercharging = lightning?).
>>
>> We should probably start by implementing testnet rock-paper-scisso= rs in MATT, though :)
>>
>> Best,
>> Salvatore Ingala
>> _______________________________________________
>> bitcoin-dev mailing list
>> bitcoin-dev@lists.linuxfoundation.org
>> https://lists.linuxfoundation= .org/mailman/listinfo/bitcoin-dev
>
> _______________________________________________
> bitcoin-dev mailing list
> bitcoin-dev@lists.linuxfoundation.org
> https://lists.linuxfoundation.org= /mailman/listinfo/bitcoin-dev
--000000000000ffe94505faa18eb7--