Skip to content

Instantly share code, notes, and snippets.

"I'm verifying ownership of " + james@teachbitcoin.io + " at EarnCarrot."

Setup Guide

Setup Guide in Jupyter

  • Library Import
    • Extension of Bitcoin Core Test Framework
    • We will be using
      • Elliptic Curve in test_framework/key.py
      • Script in test_framework/script.py
      • Transaction in test_framework/messages.py
  • And other utilities.
@jachiang
jachiang / optech_taptree.md
Last active July 26, 2019 12:42
Optech Taptree

Taproot Tree Construction

Taproot Descriptors

optech_taptree_desc

Parsing a Taproot Tree from a Descriptor (Github):

tp_desc = "tp(026bf6d12e669cb96afb170daedcc0affe36fad226e9bf2b49c2ef9519361bb882,[ts(pk(026bf6d12e669cb96afb170daedcc0affe36fad226e9bf2b49c2ef9519361bb882)),[ts(pk(029f093894657d515646e23042e5ba198a11e8dd8c315deb55db62e7cbc4bab047)),[ts(pk(025a59322be1a5b2f0bfb496c7a4808baf55a9c51f4be98aa475c5592a0b915f7e)),ts(raw(0337062390b186749bd7012d75081ed5e6445fda91df0cf669dc924fd3731ad4ca))]]])"
@jachiang
jachiang / optech_tapscript.md
Last active July 26, 2019 14:28
Optech Tapscript

Tapscript

Note: Taproot descriptors in this chapter and associated demo library are illustrative of the ongoing design intent, but do not represent the final version. The taproot descriptors described below are based on this proposal.

Tapscript is a new Bitcoin output script language which is evaluated when the script path is used during the spending of a Taproot output. With a few noted exceptions (CHECKSIG opcodes), it carries many of the familiar op_codes and evaluation logic which applies to Bitcoin script.

Standard Tapscript Types.

Nonetheless, for most use-cases, a set of standard tapscripts can be described with the following tapscript descriptors. Tapscript descriptors are encapsulated with ts().

@jachiang
jachiang / TaprootKeyPathSpend.py
Created July 24, 2019 18:53
Taproot Key Path Spend
from test_framework.test_framework import BitcoinTestFramework
from test_framework.address import program_to_witness
from test_framework.script import CScript, TaprootSignatureHash, taproot_construct
from test_framework.script import OP_DUP, OP_HASH160, OP_EQUALVERIFY, OP_CHECKSIG
from test_framework.messages import CTxInWitness, CScriptWitness, COutPoint, CTxIn, CTxOut, CTransaction, sha256
from test_framework.util import hex_str_to_bytes
from test_framework.key import ECKey
import hashlib
from io import BytesIO
@jachiang
jachiang / TaprootScriptPathSpend.py
Created July 24, 2019 18:44
ChecksigAdd output spends
from test_framework.test_framework import BitcoinTestFramework
from test_framework.address import program_to_witness
from test_framework.script import CScriptOp, CScript, TaprootSignatureHash, taproot_construct
from test_framework.script import OP_DUP, OP_HASH160, OP_EQUAL, OP_EQUALVERIFY, OP_CHECKSIG, OP_CHECKSIGADD
from test_framework.messages import CTxInWitness, CScriptWitness, COutPoint, CTxIn, CTxOut, CTransaction, sha256
from test_framework.util import hex_str_to_bytes
from test_framework.key import ECKey
import hashlib
import itertools
@jachiang
jachiang / TaprootDescriptorProposal.md
Last active July 23, 2019 19:24
Taproot Output Descriptor Proposal

Taproot Descriptor Proposal

Status: Discussion

Co-Authors: Elichai Turkel (elichai.turkel@gmail.com), James Chiang (james.chiang@protonmail.com)

Output descriptor support in Bitcoin Core provides an intuitive language which simplifies how wallets determine which UTXOs they can sign and spend. A descriptor expression today expands to a single output script of a given output.

However, with the introduction of Taproot, a given output can now have multiple spending paths at different heights of the taproot tree. We wish to propose a taproot output descriptor which encapsulates both individual tapscripts and mid-level tapscript descriptors while encoding the intended taptree structure.

@jachiang
jachiang / TaprootProposal.md
Last active July 22, 2019 19:58
Taproot Proposal

Taproot Descriptor Proposal

Status: Proposal Co-Authors:

Output descriptor support in Bitcoin Core provide an intuitive language which simplifies how wallets determine which UTXOs they can sign and spend. A descriptor expression today expands to a single output script of a given output.

However, with the introduction of Taproot, a given output can now have multiple spending paths at different heights of a taproot tree. We wish to propose a taproot output descriptor which encapsulates both individual tapscripts and mid-level tapscript descriptors whilst encoding the intended taptree structure.

The proposed taproot descriptor design prioritizes:

@jachiang
jachiang / TaprootDescriptor.md
Created July 22, 2019 14:53
Huffman-Encoded Taproot Output Descriptor

Huffman-Encoded Taproot Output Descriptors

Motivation

Taproot outputs can feature complex merkle branches involving multiple participating wallets. We prepose a huffman-encoded taproot output descriptor which allows all participating wallets to solve for all merkle branch spending paths, without imposing any restrictions to possible tree structure and ensuring a unique descriptor-to-output mapping.

The design of the proposed output descriptor is also influenced by the desire to enable higher-level descriptor expressions which may compile to multiple tapscripts of potentially different execution probability.

Basic Design

@jachiang
jachiang / escrow.sol
Created May 25, 2019 09:16
Escrow Solidity Example
pragma solidity >= 0.4.0 <0.6.0;
contract escrow {
// State variables
uint256 escrow_balance;
address payout_address;
struct authority
{