文章目錄
散列hashing
- 定義: Converts a digital object of arbitrary length, like a document, an image into a single string of fixed length, called a hash.
- 性質:
- not continuous, two similar documents result in very different hashes;
- it is very hard to reverse engineer.
- 什麼是SHA256和RIPEMD160
- SHA256 is a novel hash functions computed with 32-bit words;
- RIPEMD160 has a 160-bit hash value so it is used for shorted hash.
比特幣地址Bitcoin address
- 定義:a bitcoin address is a string of 26-35 alphanumeric characters in Base58Check encoding, begining with the number 1 or 3.
- 如何獲取:
- it is a hash of a public key------>P2PKH(Pay-to-Public-Key-Hash)。
- Public Key 經過 SHA256 + RIPEMD160 得到Public Key Hash, 再經過Base58Check Encode得到Bitcoin address。
- it is the hash of a script------>P2SH(Pay-to-Script=Hash)。
Merkle Tree
- 作用:To prove some transaction included in hash.
- 提供:交易的hash+交易的merkle path+Merkle root的hash,即可證明。
比特幣基礎知識
- 單位:1 satoshi = Bitcoin,satoshi is smallest possible unit;
1 MilliBit = 0.001Bitcoin = 100,000 satoshis - 比特幣上限是固定的,有Almost 21 million BTC,2,099,999,997,690,000 satisgus
- 在2140年全部挖掘,共13.4million blocks
- 每十分鐘出現一個新區快。每210,000個區塊比特幣的產出速率就會下降50%,目前是6.25bitcoin per block
比特幣編程語言——script
- 介紹:reverse-Polish notation stack-based execution language
- 堆棧操作:
- Push:adds an item to the top of the stack;
- pop:removes the item at the top of the stack.
- 優點:
- Not hardware dependent
- enables execution on devices with limited memory, like embedded devices
- it is stateless. No state prior to execution and no state saved after execution.
- 不能循環的影響:Does not permit loops or complex program control features:
- This means predictable execution times
- precludes attacks
- no infinite loops
- not Turing-complete.
Wallets
- 什麼是錢包?
- Wallets is the primary user interface. Controls access to a user’s bitcoin; Manages keys and address; Tracks current balance; Enables creation and signing or transactions.
- 錢包哪裏?
- May be held on client machine or on an exchange.
- 錢包的功能?
- Wallets is the primary user interface. Controls access to a user’s bitcoin; Manages keys and address; Tracks current balance; Enables creation and signing or transactions.
- Wallets can keep a copy of the transaction; Can query the chain when needed.
- Wallet also refers to the data structure used to store and manage a user’s keys and address.
- 錢包在personal machine vs exchange
Wallet on personal machine is a software program in which you store Bitcoin; Wallet on exchange let you convert ‘real money’ like US dollars to Bitcoin. You don’t have full control of this exchange wallet.
區塊鏈的交易 transaction
- 交易過程
- 交易的組成部分:
- an amount of Bitcoin, denominated in satoshis;
- A locking script which needs intended recipient to provide something to redeem it.
- 如何贖回locking的script?
- They provide their signature and a hash of their public key or a hash of a script
- 根據贖回方式有五種交易標準:
- Pay-to-Public-Key-Hash(P2PKH):a hash of a specific public key is needed to redeem.
- Pay-to-Script-Hash(P2SH)
- Pay-to-Public-Key(P2PK):Mostly used in coinbase transactions
- Multiple-signature:limited to 15 keys
- Data Output: 40 bytes of non-payment data to a Transaction output.
- 區塊的第一筆交易basecoin trsansaction:
定義:the bitcoin earnt by mining are awarded via the first transaction of each new block.
性質:There are no UTXO inpus for these transaction.
UTXO
- 什麼是UTXO?
Unspent Transaction Output (UTXO) is the output of a transaction which may be spent as an input in a subsequent transaction. - UTXO與交易什麼關係?
‘Sending’ a recipient some bitcoin is done by creating some UTXO registered to their address. - UTXO的性質:
- All the UTXO of the system is known by every node, held in a database called UTXO set or UTXO pool.
- UTXO is locked to a specific address and may be scattered;
- UTXO與wallet的關係:
- a wallet will aggregate the UTXO belonging to a single address.
分散共識Decentralized consensus
- (節點如何驗證一個交易)Independen verification of each trasaction, by every full node.
- Independent aggregation of those transactions into new blocks by mining nodes together with demonstrated computation through a Proof-of-Work algorithm
- (節點如何驗證一個新塊)Independent verification of the new blocks by every node and assembly into a chain
- independent selection, by every node, of the chain with the most cumulative computation demonstrated through Proof-of-Word.
PoW
- 目的:Proof-of-Work is designed to create a hurdle to mining
- 避免了什麼問題:
- nodes might spin-up multiple sock-puppet nodes to win the reward
- a form of Sybil attack
- PoW的數學問題:Find the hash a specified object with a nonce parameter which is less than sum pre-specified total.
對block header進行兩次SHA256運算,得到的值小於目標值即可。
block header:version+previous_block_hash+merkle_root+time+target_bits+nonce - 這個數學問題的特點:
- Problem designed to be hard to do and easy to check
- Can only be solved by trial and error.
- 哪些未記錄的transaction可以進入candidate block?
- Prioritized by age(how many blocks since the UTXO was recorded)
- Size of transaction(1 bitcoin, aged 1 day)