2. Timeline
● Bitcoin
● Transaction life cycle
● Wallet
● Keys: private key, public key, bitcoin address
● Non-determisnitc and deterministic wallet
3. Timeline
● Hierarchical deterministic wallet (HD wallet)
● How to generate keys in HD wallet
● Transaction Input and Output
● Unloncking and Locking Script
8. Transaction Life Cycle
Move transaction to transaction pool
BTC From To Spent
12 Alice Bob No
Transaction pool
9. Transaction Life Cycle
Miner will move transactions in the pool
to a block.
BTC From To Spent
12 Alice Bob No
BTC From To Spent
2 Jane Upin No
86 Bran Jen No
37 Stan Lily No
10. Transaction Life Cycle
Miner compete to validate the block.
BTC From To Spent
2 Jane Upin No
86 Bran Jen No
37 Stan Lily No
12 Alice Bob No
11. Transaction Life Cycle
The mined block will be published to global blockchain. Miners who
win will be rewarded with new issued Bitcoin.
BTC From To Spent
2 Jane Upin No
86 Bran Jen No
37 Stan Lily No
12 Alice Bob No
22. Wallet
● Data structure used to store and manage keys
● Consists of:
○ Non-deterministic
○ Deterministic wallet
23. Non-deterministic Wallet
● Keys are independently generated, stored in wallet.
● Drawback:
○ Back up too many keys ==> storage heavy.
○ Address reuse ==> trace back private key.
25. Deterministic Wallet
● Store seed + index or chain of code only (lighter)
● Can recover all key
● If lose the seed, lose all key ==> lose all bitcoin
31. Create children key
● Parent key, chain code and index are combined and hashed to
generate children keys
32. Transaction Input and Output
● There are no coins, no senders, no recipients, no balances, no
accounts, no addresses.
33. Transaction Output
UTXO: unspent transaction output.
Transaction outputs consist of 2 part:
● an amount of bitcoin, denominated in satoshis
● a cryptographic puzzle, known as locking script, witness script
or a scriptPubKey, that determines the conditions required to
spend the output
34. Transaction Input
● Transaction inputs identify (by reference) which UTXO will be
consumed and provide proof of ownership through an
unlocking script.
● Wallet create input pointing to UTXO and unlock it with
unlocking script.
35. Transaction Input
Transaction input include:
● Reference to UXTD being spent
● Index of the output in UXTD
● Unlocking script scriptSig
● Sequence
36. Transaction Fee
● According to size and capacity of the network
● Higher money, higher priority
● If forget to create change output, change => fee.
37. Transaction script and scripting language
Turing incompleteness:
● Prevent loops, logic bombs
● Prevents transaction validation mechanism from being used as
vulnerability
38. Transaction script and scripting language
Stateless Verification:
● Predictably, if script execute on your system, it works on other
system.
39. Transaction script and scripting language
Example of a simple script:
Locking script Unlocking script
41. Transaction script and scripting language
Valid:
● Top of stack is True
Invalid:
● Any non-zero value
● Stack is empty after script execution
● Halted explicitly by OP_RETURN
45. Digital Signature (Elliptic Curve Digital Signature
Algorithm)
Purpose:
● proves ownership of private key (authorization)
● proof of authorization is undeniable (nonrepudiation)
● proves transaction has not been modified by anyone after it
has been signed (integrity)
47. Digital Signature (Elliptic Curve Digital Signature
Algorithm)
Consists 2 part:
● Algo to create signature from message
● Algo to verify signature given message and public key