文章目录
散列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)