• Post category:StudyBullet-16
  • Reading time:10 mins read


Dive deep into the cryptography and digital signatures that keep Bitcoin secure

What you will learn

Developers looking to learn about Bitcoin basics

Learn how elliptic curves and private keys work

Understand the parameters for secp256k1

Implement ECDSA in Python

Learn about Bitcoin Sighash flags

Write P2PK, P2PKH, and P2WPKH scripts

Make and spend a multisig Bitcoin transaction

Description

So you’ve heard about bitcoin? Ever wondered what’s going on with the data in a transaction, or how bitcoin gets locked up and transferred from one holder to another?

This course by Base58 instructor niftynei, will take you on a deep dive of the fields, bytes, and scripts that make up the bitcoin blockchain data. In an software engineer focused manner, we’ll go over everything you need to know to build your own bitcoin transaction parser, write your very own custom bitcoin locking scripts, and adapt your transactions to the modern SegWit format.

Step 1: Let’s learn about Elliptic Curve Cryptogaphy

First we figure out what the building blocks for making digital signatures on blockchains are: elliptic curves! We’ll do a very basic walk through of how these work and work through where Bitcoin’s secp256k1 curve comes from. Finally we’ll pick some private keys and learn how to find the public key version of it.

Topics: elliptic curves over finite fields, secp256k1, public and private keys

Step 2: P2PK, P2PKH: Locking Bitcoin up to Public Keys

Now that we’ve got some private and public keys, we’re ready to learn about standard Bitcoin scripts with signatures. We’ll write some P2PK, P2PKH, and P2WPKH scripts and lock bitcoin up to them (so we can unlock it later).

Topics: compressed keys, P2PK, P2PKH, P2WPKH

Step 3: Digital Signatures


Get Instant Notification of New Courses on our Telegram channel.


Now that we’ve got Bitcoin locked up to some public keys, we need to learn how to make signatures to unlock it. We’ll walk through how ECDSA works.

Topics: digital siganatures, ECDSA

Step 4: Sighashes

Now that we’ve got ECDSA under our belt, we’re ready to make signatures to spend the bitcoin we locked to our public keys. Here we use sighashes to build the message to sign with ECDSA. Sighashes are how we commit to data in a transaction, to prevent anyone else from tampering with the data on its way into a block.

Topics: sighashes, SegWit, legacy, SIGHASH_ALL, SIGHASH_NONE, SIGHASH_SINGLE

Step 5: Multisig

Finally, we’ll take a look at how you can lock bitcoin up to threshold signatures using OP_CHECKMULTISIG.

Topics: multisigs, OP_CHECKMULTISIG, Script

English
language

Content

Introduction

Welcome To Base 58’s Bitcoin Developer Basics: Digital Signatures
Prerequisites and Additional Resources
OPTIONAL: Bitcoin Script & TX Parsing Overview

Housekeeping

What You’ll Need for this Class
Setting Up bitcoind + bitcoin-cli (Mac edition)
Verifying bitcoind (Mac edition)
Setting up a new Replit with bitcoind + bitcoin-cli (Browser edition)
Using the Base58 Replit with bitcoind + bitcoin-cli (Browser edition)
Project 1: Setting up a Regtest Bitcoin Node (Replit)
Project 1: Solution // Walk-Through
How to Use a Block Explorer
Using a Block Explorer
Nifty’s Bitcoin Coding Environment

Elliptic Curves And secp256k1

Intro to Elliptic Curves + Cryptography
Elliptic Curve Equations
More Rigorous: Elliptic Curve Equations
Finite Fields
Elliptic Curves Over Finite Fields
secp256k1
What is a Generator Point
Compressed + Uncompressed Point Encodings
Python: Implementing find_y
Visualizing Elliptic Curve Addition
Visualizing Elliptic Curve Multiplication
Elliptic Curve Arithmetic

Public Keys with Python & Bitcoin

Section Overview: Making our first Pubkey Script
Public Key Math with Python
Project 2A: secp256k1 public/private key challenges
Project 2A: Solution // Walk-Through
Project 2B: Use Your Code
What Public Key Cryptography Proves
Pay to Public Key
Unlocking from a Pay to Pubkey Bitcoin Script
Project 2B: P2PK
Project 2B: Solution // Walk-Through

Elliptic Curve Digital Signature Algorithm (ECDSA)

Intro to Signing Algorithms
ECDSA
Multiplicative Inverses on Finite Fields
ECDSA: Making a Signature
ECDSA: Verifying a Signature
Project 3: ECDSA Sign + Verify
Project 3: Solution // Walk-Through
DER Encoded Signatures
Project 4: DER Encoding Parsers
Project 4: Solution // Walk-Through
Low-S in ECDSA Signatures

Creating Message Digests from Bitcoin Transactions (Legacy)

Verifying the Signature of a Bitcoin Transaction
Verifying the Signature of a Bitcoin Transaction, continued
Sighash Example Setup (Three Inputs, Two Outputs)
SIGHASH_ALL Message Digest Construction
SIGHASH_SINGLE Message Digest Construction
SIGHASH_NONE Message Digest Construction
Turning Digests into Signatures
SIGHASH_SINGLE: Fatal edge case
SIGHASH_ANYONECANPAY
Project 5a: SIGHASH Builder
Project 5a: Solution // Walk – Through
Project 5b: Stealing a faulty SIGHASH_SINGLE input
Project 5b: Solution // Walk – Through

Paying to Public Key Hashes (Legacy + SegWit)

P2PKH
Building a P2PKH
Spending a P2PKH
P2PKH
P2WPKH
P2WPKH

Creating Message Digests from Bitcoin Transactions (SegWit)

BIP143 Sighash Algo
BIP143 ScriptCodes
Signing and Sending the Sighash Digest
BIP143: Sighash Flags (NONE, SINGLE, ACP)
BIP143: Why use hashes? (hashPrevouts/hashSequence/hashOutputs)
Enter SegWit Sighashes: BIP143
Project 6: Segwit v0 Sighash Implementation
Project 6: Solution // Walk-Through
Project 6b: Spending a P2WPKH
Project 6b: Solution // Walk-Through

Multisigs (OP_CHECKMULTISIG)

Intro to Multisig + Thresholds
Making a OP-CHECKMULTISIG script
Writing a Tx to Spend Multisig Outputs
Spending Multisig (bare multisig, P2SH, P2WSH)
Witness Stack Data vs ScriptSig Data
OP-CHECKMULTISIG Script Execution Walk Through
Final Exam: Spend a P2WSH Multisig

Wrap Up: Bitcoin Digital Signatures Course

Recap of What We’ve Learned and Built
Next Steps on Your Path to Bitcoin Wizardry
Thank You!