bitcoin notes

 
bitcoin 
 
the original paper by satoshi nakamoto: "Bitcoin: A Peer-to-Peer Electronic Cash System" 
a good book:  "Mastering Bitcoin" by Andreas Antonopoulos 
 
 
### 
###  background: how to make payments without a trusted third party 
### 
 
in person, with physical currency, a buyer can just pay cash to a seller in exchange for a commodity/service. done. 
online, seller needs protection from fraud. so there needs to be a trusted third party (a financial institution) that mediates disputes. 
but having a trusted third party (mediation cost) increases transaction cost. 
in fact, a certain percentage of fraud is accepted as unavoidable. 
 
hence 
- an electronic payment system based on cryptographic proof of work(transaction), instead of trust. 
- transaction consensus built in p2p community 
 
### 
###  double-spending problem 
### 
 
in physical currency, you can have only one copy of your paper money, so you cannot double spend it. 
but digital currency, one can attempt to double spend like you buy a book from amazon and buy a jacket from macy's online and use the same bitcoin before they clear the transaction. 
one way to avoid this is to have a cenralized clearing house, that detects an illicit double-spending practice, or to encode all transaction log (ledger) in a chain. 
a block basically consists of info of transactions (pub addr of seller/buyer, and timestamp of transaction, etc) then you chain it, to have a complete transaction history of a bitcoin. hence a blockchain. 
 
 
### 
###  a nonce 
### 
 
 
### 
###  wallet 
### 
 
- mycelium 
- coinbase 
- many others 
 
 
a bitcoin "node" - any system (e.g. a server, desktop app, a wallet app) that participates in the bitcoin NW by speaking the bitcoin protocl. 
 
######################### 
###   Bitcoin Core    ### 
######################### 
 
Satoshi Nakamoto's paper introduced the idea, and he even implemented the first version, but since then people developed different versions. 
Bitcoin Core is considered "the" reference implementation which gives authoritative reference to how each component should be implemented. 
 
src code:   https://github.com/bitcoin/bitcoin 
 
BIP = bitcoin improvement proposal   # kind of like RFC in the internet protocol 
                                     # e.g. developers are advised to build wallets using BIP-39/32 standards 
 
Note: it's not necessarily wise to use Bitcoin Core implementation directly for prod usage. 
 
## 
##  installing/running your Bitcoin Core 
## 
 
$ git clone https://github.com/bitcoin/bitcoin.git /path/to/some/working/dir/bitcoin 
# read  README.md for installation/compilation steps 
# lots of config options available. 
# note it will consume 125+GB disk space and 2+GB RAM. 
 
# bitcoin node (a daemon process) 
$ /usr/local/bin/bitcoind             #  configure your bitcoin.conf file 
 
 
Bitcoin Core client: 
- /usr/local/bin/bitcoin-cli 
- implements JSON RPC interface : many useful functions 
- JSON (javascript object notation): a format easy to parse/read by machine/human eyes. 
- RPC (remote procedure call) : client invokes a function and a server runs it. 
e.g. 
bitcoin-cli help         # list of available RPCs 
bitcoin-cli getinfo      # gives the status of your node 
 
# lots of more useful RPCs in bitcoin-cli 
e.g. 
getrawtransaction, decoderawtransaction 
getblockhash, getblock 
 
 
python API lib:  "python-bitcoinlib"  lets you use JSON RPCs 
- there are others, available in C/C++, js, ruby, java, C#, etc 
 
bitcoin port = 8332 
 
 
who decides transaction fee? in theory, transactor can, but the point is to give enough incentive miners to mine a block for your transaction. 
 
in the bitcoin system, trust is based on computation 
 
a good analogy to mining is a huge sudoku puzzle. 
solving it == mining a block (thus earning reward which consists of new bitcoins + transaction fee) 
key properties 
- computationally hard to solve, but easy to verify. 
- difficulty is adjustable so it takes ETA 10 min. (imagine you can change the size of rows/columns, or change the number of pre-populated cells in a soduku board, to control difficulty) 
- you can create a new puzzle quickly. 
 
a solution = proof of work 
 
who decides the difficulty & target ? 
so at any given time, there is a pool of unverified transactions shared by nodes in the NW. 
a miner decides how many of those unverified transactions to put into a new block (a candidate block) which he will try mine. 
how many transaction to put into a candidate block ? well, the incentive is to put as many or put the ones with higher transaction fee. 
recall the incentive is the combination of new bitcoin + transaction fee. 
 
 
################################ 
####    keys, addressing    #### 
################################ 
 
cryptography 
- encryption: encoding a secret 
- digital signature: proving knowledge of a secret without revealing a secret. 
- digital fingerprint: proving the authenticity of data. (bitcoin addr is a fingerprint) 
 
## 
##  public key cryptography  (aka assymetric cryptography) 
## 
- explores "irreversible" mathematical functions. i.e. you can not determine the input value from the output value. 
e.g. 
number exponentiation 
elliptic curve multiplication (ECM)   # bitcoin uses this 
many other one-way hash functions 
 
              (ECM)                 (one-way hash function) 
private key  ------->  public key  -----------------------> bitcoin addr 
 
note: most wallets keep pri/pub key pair, but theoretically, pub key can be derived from pri key. 
 
(Q) how do we achieve the properties (1) encryption, (2) digital signature, (3) digital fingerprint 
if the money is signed using your public key (can be signed by yourself or others who want to give money to you), then only you can unlock it. 
by unlock, to be precise, you apply your private key to digital fingerprint (the thing signed by your pub key) to produce a numeric "signature" which (obviously only the pri key owner can produce) can be verified using only pub key and the digital fingerprint. 
 
note: bitcoin addr can represent more than just pub key, like scripts 
note: private key is stored in your wallet. usually kept out of user's sight. 
 
To spend, you present your pub key and the signature (produced by applying pri key to the digital fingerprint of the prev transaction output from which you gained the bitcoin you intend to spend in the current transaction), so others can verify. 
note: here, "digital fingerprint" is aka "witness" 
 
 
## 
##  private key 
## 
- it's 256 bits long. (close to the number of atoms in the universe) 

 
## 
##  public key 
## 

 
 
 
e.g. 
$ bitcoin-cli getnewaddress 
<pub_key> 
$ bitclin-cli dumpprivkey <pub_key> 
<pri_key> 
 
 
 
####################### 
####    Mining     #### 
####################### 
 
 
 
## 
##  HW for mining 
## 
in the old days, a desktop CPU/CPU could compete but now they became useless. 
people use a specialized hardware called ASIC (application specific integrated circuit) that runs hundresds of mining algos (attempting hashing) printed in hardware concurrently. 
 
 
what is a replay attack ? 
 
 
what is segway ? 
 

  1. 2017-12-03 23:19:09 |
  2. Category : misc
  3. Page View:

Google Ads