Bits, Booleans,
Battlestar Galactica
How bitvm works
Outline
What bitvm is
What bitvm can and can’t do
Boolean circuits
Putting them in bitcoin addresses
How hashlocks and taproot fix everything
What bitvm is
��Bitvm is a virtual computer
Like real computers, it can run programs
Its programs go inside btc addresses
What bitvm is
�Bitvm programs typically run “off chain”
Two counterparties both run the program
If a party runs it wrong, they lose sats be-�cause the code is *also* in a btc address
What bitvm is
This bitvm address has an “addition” program in it
bc1gh3395j0asmng9498qkf
Yeah, we funded it together & we both checked the code
What bitvm is
I assert that 1 + 1 = 3
bc1gh3395j0asmng9498qkf
K, send me “bit commitments” for each number
What bitvm is
0 0 0 1 + 0 0 0 1 = 0 0 1 1
Whoa, my copy of bitvm says your equation is false!
What bitvm is
Rats, you caught me!
bc1gh3395j0asmng9498qkf
I can prove your error on bitcoin and take your money!
What bitvm can do
Currently: add, compare, and count
In theory: run any (converted) program
I see a path to do these things:
Bitvm limitations
Bitvm contracts need at least�2 parties: a prover and a verifier
Bitvm contracts need interactive�setup and execution
Bonded covenants can be broken�for a high price
Bitvm limitations
Optimistic sidechains trust at�least 1 person (but it can be you!)
Disputing a large program would�likely be very expensive
A mining pool with a hashrate�majority can steal from bitvm
A very basic computer
AND
GATE
A very basic computer
AND
GATE
A very basic computer
AND
GATE
A very basic computer
AND
GATE
A very basic computer
AND
GATE
Logic gates
1� 1
1
0� 1
1
1� 1
0
0� 1
0
A 2 bit adder
AND
GATE
XOR
GATE
0
0
A 2 bit adder
AND
GATE
XOR
GATE
0
1
A 2 bit adder
AND
GATE
XOR
GATE
0
1
A 2 bit adder
AND
GATE
XOR
GATE
1
0
An 8 bit adder
An IBM cpu
An IBM cpu
Anatomy of a “regular” bitcoin transaction
0100000001186f9f998a5aa6f048e51dd8419a14d8a0f1a8a2836dd734d2804fe65fa35779000000008b483045022100884d142d86652a3f47ba4746ec719bbfbd040a570b1deccbb6498c75c4ae24cb02204b9f039ff08df09cbe9f6addac960298cad530a863ea8f53982c09db8f6e381301410484ecc0d46f1918b30928fa0e4ed99f16a0fb4fde0735e7ade8416ab9fe423cc5412336376789d172787ec3457eee41c04f4938de5cc17b4a10fa336a8d752adfffffffff0260e31600000000001976a914ab68025513c3dbd2f7b92a94e0581f5d50f654e788acd0ef8000000000001976a9147f9b1a7fb68d60c536c2fd8aeaa53a8f3cc025a888ac00000000
Anatomy of a “regular” bitcoin transaction
0100000001186f9f998a5aa6f048e51dd8419a14d8a0f1a8a2836dd734d2804fe65fa35779000000008b483045022100884d142d86652a3f47ba4746ec719bbfbd040a570b1deccbb6498c75c4ae24cb02204b9f039ff08df09cbe9f6addac960298cad530a863ea8f53982c09db8f6e381301410484ecc0d46f1918b30928fa0e4ed99f16a0fb4fde0735e7ade8416ab9fe423cc5412336376789d172787ec3457eee41c04f4938de5cc17b4a10fa336a8d752adfffffffff0260e31600000000001976a914ab68025513c3dbd2f7b92a94e0581f5d50f654e788acd0ef8000000000001976a9147f9b1a7fb68d60c536c2fd8aeaa53a8f3cc025a888ac00000000
The “script sig” aka “witness stack”
0100000001186f9f998a5aa6f048e51dd8419a14d8a0f1a8a2836dd734d2804fe65fa35779000000008b483045022100884d142d86652a3f47ba4746ec719bbfbd040a570b1deccbb6498c75c4ae24cb02204b9f039ff08df09cbe9f6addac960298cad530a863ea8f53982c09db8f6e381301410484ecc0d46f1918b30928fa0e4ed99f16a0fb4fde0735e7ade8416ab9fe423cc5412336376789d172787ec3457eee41c04f4938de5cc17b4a10fa336a8d752adfffffffff0260e31600000000001976a914ab68025513c3dbd2f7b92a94e0581f5d50f654e788acd0ef8000000000001976a9147f9b1a7fb68d60c536c2fd8aeaa53a8f3cc025a888ac00000000
Spending via a “sum to 3” program
0100000001186f9f998a5aa6f048e51dd8419a14d8a0f1a8a2836dd734d2804fe65fa357790000000006515203935387ffffffff0260e31600000000001976a914ab68025513c3dbd2f7b92a94e0581f5d50f654e788acd0ef8000000000001976a9147f9b1a7fb68d60c536c2fd8aeaa53a8f3cc025a888ac00000000
06 = 6 byte # 52 = OP_2 93 = OP_ADD �03 = 3 byte # the program = 935387 53 = OP_3�51 = OP_1 its anatomy = 935387 87 = OP_EQUAL
Bitcoin Script’s built-in functions
Boolean AND program in bitcoin script
Use this library: https://www.npmjs.com/package/@cmdcode/tapscript�var script = [� 'OP_BOOLAND'
];�var address = tapscript.Address.p2wsh.fromScript(script, "testnet");�console.log(address);�//tb1qqczaz56whzv4l68u0h83ltqzt6j7ym7zd443lsk8n2s0qs2eaaqsh92y5r
Spending via a “boolean AND” program
0100000001186f9f998a5aa6f048e51dd8419a14d8a0f1a8a2836dd734d2804fe65fa3577900000000045151019affffffff0260e31600000000001976a914ab68025513c3dbd2f7b92a94e0581f5d50f654e788acd0ef8000000000001976a9147f9b1a7fb68d60c536c2fd8aeaa53a8f3cc025a888ac00000000
04 = 4 byte # the program = 9a� 51 = OP_1 9a = OP_BOOLAND� 01 = 1 byte #
A few problems
The witness stack is malleable
Need >100 megabytes
Can’t use >400 kilobytes
Solution
Hashlocks and taproot fix this
How taproot helps
One address, many scripts
Each script has an identifier
Normally, the spender picks�which one to use
But hashlocks allow Vicky to�pick a script on Paul’s behalf
Transferring state with hashlocks
Address A
Show Preimage X or Preimage Y
Then the sats must go to Address B
Address B
Preimage X = 0�Preimage Y = 1
Vicky can spend w/ both preimages
Our logic gate is bigger now (1/3): NOT gate
OP_SHA256 //this hashlock ensures Vicky picks the script� 99ebdc5d4b54fe94a5750bb887d3944 OP_EQUALVERIFY� OP_SHA256 //the next two one let Paul pick a 1 or a 0� a93ef3a7b083e2d631f6f4d1c9053549 OP_EQUAL� OP_IF� OP_1� OP_ELSE� 64c319be85f63748e891d5d7785e2e95 OP_EQUALVERIFY� OP_0� OP_ENDIF
Our logic gate is bigger now (2/3): NOT gate
OP_NOT� OP_SWAP� OP_SHA256� 47217b232be277635ea84b85f63748e OP_EQUAL� OP_IF� OP_1� OP_ELSE� 980ce21ed17038ec7c1f3254f4064d65 OP_EQUALVERIFY� OP_0� OP_ENDIF
Our logic gate is bigger now (3/3): NOT gate
OP_EQUAL� OP_IF //continue the challenge/response game� OP_0� <pauls_pubkey> OP_CHECKSIGADD� <vickys_pubkey> OP_CHECKSIGADD� OP_2 OP_EQUAL� OP_ELSE //otherwise let Vicky spend the money unilaterally� <2 weeks> OP_CHECKSEQUENCEVERIFY� <vickys_pubkey> OP_CHECKSIG� OP_ENDIF
Hooking Logic Gates Together
AND
GATE
XOR
GATE
Hooking Logic Gates Together
� A/B� C/D
AND
GATE
XOR
GATE
E/F
G/H
Hooking Logic Gates Together
� A/B� C/D
AND
GATE
XOR
GATE
E/F
G/H
NAND
GATE
Response Addresses
Every response address�has multiple script paths
Paul wins if Vicky is slow
Vicky wins if Paul equivocated
Or Vicky can challenge again�but only by unlocking a hashlock
Hashlock 150 for Vicky
Hashlock 150 for Paul
Binary Search aka Bisection
AND
GATE
XOR
GATE
NAND
GATE
XOR
GATE
AND
GATE
XOR
GATE
NAND
GATE
References