Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify notebooks' setup by using a configuration file #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "3ca0e780",
"metadata": {},
"source": [
"## Setup \n",
"\n",
"### Requirements\n",
"For this exercise we'll need Bitcoin Core. This notebook has been tested with [v24.0.1](https://github.com/bitcoin/bitcoin/releases/tag/v24.0.1).\n",
"\n",
"Below, set the paths for:\n",
"1. The bitcoin core functional test framework directory.\n",
"2. The directory containing bitcoin-tx-tutorial.\n",
"\n",
"**You'll need to edit these next two lines for your local setup.**"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "752d005e",
"metadata": {},
"outputs": [],
"source": [
"path_to_bitcoin_functional_test = \"/Users/dariuscognac/bitcoin/test/functional\"\n",
"path_to_bitcoin_tx_tutorial = \"/Users/dariuscognac/Documents/Github/bitcoin-tx-tutorial\"\n",
"\n",
"import sys\n",
"\n",
"# Add the functional test framework to our PATH\n",
"sys.path.insert(0, path_to_bitcoin_functional_test)\n",
"from test_framework.test_shell import TestShell\n",
"\n",
"# Add the bitcoin-tx-tutorial functions to our PATH\n",
"sys.path.insert(0, path_to_bitcoin_tx_tutorial)\n",
"from functions import *\n",
"from functions.bip_0340_reference import *"
]
Expand Down Expand Up @@ -101,7 +73,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "2f212482",
"metadata": {},
"outputs": [],
Expand All @@ -120,18 +92,10 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "54b533fc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"pubkey: (55066263022277343669578718895168534326250603453777594175500187360389116729240, 32670510020758816978083085130507043184471273380659243275938904335757337482424)\n"
]
}
],
"outputs": [],
"source": [
"privkey_int = int_from_bytes(privkey)\n",
"pubkey = point_mul(G, privkey_int)\n",
Expand Down Expand Up @@ -180,19 +144,10 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "468b6795",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Uncompressed pubkey: 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8\n",
"Compressed pubkey: 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798\n"
]
}
],
"outputs": [],
"source": [
"# using the same privkey value from above\n",
"pubkey = point_mul(G, privkey_int)\n",
Expand Down Expand Up @@ -226,23 +181,10 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "a56fe6dc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"original_pubkey: (115780575977492633039504758427830329241728645270042306223540962614150928364886, 78735063515800386211891312544505775871260717697865196436804966483607426560663)\n",
"y coordinate is odd\n",
"\n",
"Negating the private key..\n",
"new_pubkey: (115780575977492633039504758427830329241728645270042306223540962614150928364886, 37057025721515809211679672464182131982009266967775367602652617524301408111000)\n",
"y coordinate is even\n"
]
}
],
"outputs": [],
"source": [
"# This private key has been chosen as it'll produce a public key with an odd y-coordinate\n",
"original_privkey = bytes.fromhex(\"0000000000000000000000000000000000000000000000000000000000000006\")\n",
Expand Down Expand Up @@ -289,20 +231,10 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"id": "c7cd1861",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Pubkey generated from summing private keys: (112711660439710606056748659173929673102114977341539408544630613555209775888121, 25583027980570883691656905877401976406448868254816295069919888960541586679410)\n",
"Pubkey generated from summing public keys: (112711660439710606056748659173929673102114977341539408544630613555209775888121, 25583027980570883691656905877401976406448868254816295069919888960541586679410)\n",
"Success!\n"
]
}
],
"outputs": [],
"source": [
"# Define private keys and convert to int\n",
"privkey_a = bytes.fromhex(\"0000000000000000000000000000000000000000000000000000000000000001\")\n",
Expand All @@ -323,11 +255,27 @@
"assert(pubkey_ab == pubkey2)\n",
"print(\"Success!\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "10adecc4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "fa1bf7c9",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -341,7 +289,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
"version": "3.8.16"
}
},
"nbformat": 4,
Expand Down
86 changes: 16 additions & 70 deletions appendix/hash-functions.ipynb → 0.2-hash-functions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,10 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "1da041f0",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953\n"
]
}
],
"outputs": [],
"source": [
"import hashlib\n",
"\n",
Expand All @@ -52,18 +44,10 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "51287990",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"226821c2f5423e11fe9af68bd285c249db2e4b5a\n"
]
}
],
"outputs": [],
"source": [
"output = hashlib.new('ripemd160', data).digest()\n",
"print(output.hex())"
Expand All @@ -82,7 +66,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "f30433e5",
"metadata": {},
"outputs": [],
Expand All @@ -106,18 +90,10 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "f4e6ca67",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"00000000000000001e8d6829a8a21adc5d38d0a473b144b6765798e61f98bd1d\n"
]
}
],
"outputs": [],
"source": [
"# The block header from block 125552\n",
"header_hex = (\n",
Expand Down Expand Up @@ -152,7 +128,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "0288b375",
"metadata": {},
"outputs": [],
Expand All @@ -175,18 +151,10 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"id": "41c06d0b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ca61e52e881d41374e640f819cd118cc153b21a7\n"
]
}
],
"outputs": [],
"source": [
"pubkey = bytes.fromhex(\"11\")\n",
"pkh = hash160(pubkey)\n",
Expand Down Expand Up @@ -229,21 +197,10 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"id": "a87080b9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'596711e622bf8dc1d6b892863d56504003f39bb0ee482d6d1715e590e58b35bc'"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"tx_hex = \"0100000001399434f3943d776250cf4b4c2b3fa2cac259dd5551a822e1976d25a2d9e0231d010000006b483045022100a628f785b81d04e3b5d2f4a554c839acab64215935a0558dda1e33d0120dada30220616acf4b1c796cebe11f30dd53bbb4354899d924a4791c8fd7c0ae3da0c4782c0121034f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aaffffffff0280d1f008000000001976a9143bc28d6d92d9073fb5e3adf481795eaf446bceed88ac80f0fa02000000001976a914531260aa2a199e228c537dfa42c82bea2c7c1f4d88ac00000000\"\n",
"tx = bytes.fromhex(tx_hex)\n",
Expand All @@ -261,21 +218,10 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"id": "28392546",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'fc7250a211deddc70ee5a2738de5f07817351cef'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"pk = bytes.fromhex(\"034f355bdcb7cc0af728ef3cceb9615d90684bb5b2ca5f859ab0f0b704075871aa\")\n",
"hash160(pk).hex()"
Expand All @@ -292,7 +238,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -306,7 +252,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
"version": "3.8.16"
}
},
"nbformat": 4,
Expand Down
8 changes: 4 additions & 4 deletions appendix/bitcoin-script.ipynb → 0.3-bitcoin-script.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "881e4514",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -76,7 +76,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "d8c9fd61",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -204,7 +204,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -218,7 +218,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
"version": "3.8.16"
}
},
"nbformat": 4,
Expand Down
Loading