# Blockchain Basics [TOC] ## Data Structure * Difficulty Target:找到比target小的值,以每10分鐘產生一區塊估算,困難值每2016個區塊會調整一次。 * 調整挖礦難度的目的:保證比特幣的稀缺性,同時也能保證網路的安全性。 * `new_target = old_target * (actual time / expected time)` ![image](https://hackmd.io/_uploads/Sk0HcIFRR.png) https://www.researchgate.net/figure/The-simplified-Bitcoin-blockchain-data-structure_fig2_349738447 ### Bitcoin Halving (減半機制) * 每 210,000 個區塊就會減半一次 (區塊獎勵) * 大約每四年進行一次 * 持續直到網路產生最大總供應量為 2100 萬 BTC * 預計將在 2140 年結束 ![image](https://hackmd.io/_uploads/HJRTLVWJkx.png) https://www.ig.com/cn/bitcoin-btc/bitcoin-halving ### Blockchain Demo https://andersbrownworth.com/blockchain/ ## Merkle Tree * 大幅減少資料傳輸量與運算資源消耗 * 驗證時,只需驗證Merkle Tree的Root值即可 ![image](https://hackmd.io/_uploads/Bk6g2IFR0.png) https://en.wikipedia.org/wiki/Merkle_tree ### Proof of Reserves, PoR (儲備證明) https://syshen.medium.com/%E5%8D%80%E5%A1%8A%E9%8F%88%E5%84%B2%E5%82%99%E8%AD%89%E6%98%8E-proof-of-reserve-235375de3278 ### Verkle Tree https://limaois.me/archives/349 ## Digital Signature * 保證收到資料的正確性 * 有效防止被中途攔截並竄改資料的情形 ![image](https://hackmd.io/_uploads/Byo33NWyyl.png) https://medium.com/@enterprise.eric320/%E4%B8%8D%E6%87%82%E7%A8%8B%E5%BC%8F-%E4%B9%9F%E8%83%BD%E7%90%86%E8%A7%A3%E7%9A%84%E5%8D%80%E5%A1%8A%E9%8F%88%E9%8C%A2%E5%8C%85%E6%8A%80%E8%A1%93%E5%8E%9F%E7%90%86-%E4%BA%8C-%E9%9D%9E%E5%B0%8D%E7%A8%B1%E5%8A%A0%E5%AF%86-%E6%95%B8%E4%BD%8D%E7%B0%BD%E7%AB%A0-a401f4cce623 ### One-time signature (一次性簽章) * 生成一對金鑰:私鑰用於簽章,公鑰用於驗證。 * 每個私鑰只能使用一次。 * 同一個私鑰被多次使用,系統的安全性將大幅降低,容易受到各種密碼分析攻擊。 * 一次性簽章方案被認為是抗量子的,因為它們不依賴於質因數分解或離散對數等問題 #### Lamport One-Time Signatures 非常簡單且速度快,但金鑰和簽章尺寸非常大,實際應用受限。 #### Winternitz One-Time Signatures 在簽章大小和計算效率之間提供了權衡,可調整參數以適應需求,但金鑰大小仍然較大,生成和驗證速度中等。 ![](https://i.imgur.com/lJF51Lq.png) https://codingman.cc/one-time-signature/ ### Digital Signature Demo https://andersbrownworth.com/blockchain/public-private-keys/ ## Byzantine Generals Problem (拜占庭將軍問題) * 每個將軍必須作出決定:攻擊或撤退(是或否) * 一旦做出決定後無法改變 * 所有將軍都必須就同一決定達成一致,並以同步方式執行 ### PoW (Proof-of-Work) * 優點:安全性、去中心化 * 缺點:能源消耗、計算資源浪費 * 例子:Bitcoin、Litecoin ... ### PoS (Proof-of-Stake) * 優點:消耗的能源較少 * 缺點:去中心化程度較 PoW 差 (集中權力在少數持有大量加密貨幣的參與者手中) * 例子:Ethereum、Polkadot ... https://www.samsonhoi.com/386/blockchain-proof-of-stake https://vocus.cc/article/626b40bafd8978000185a504 ## 51% Attack (51%攻擊) * 攻擊者控制全網 51% 以上的算力 * 最長鏈共識 * Double Spending (雙花問題) ![image](https://hackmd.io/_uploads/B1SABH-kkx.png) ![image](https://hackmd.io/_uploads/BkAABrbJ1l.png) * Coin Metrics「攻擊總成本 (TCA)」的新指標:比特幣 51% 攻擊成本逾 200 億美元,已經消除了惡意攻擊者的經濟動機。 https://abmedia.io/coin-metrics-bitcoin-ethereum-51-percent-attacks https://zombit.info/51-attack/