INF2003 Database Systems Blockchain AY24/25 PDF

Document Details

CelebratoryNewton4365

Uploaded by CelebratoryNewton4365

Singapore Institute of Technology

Zhang Wei

Tags

blockchain database systems cryptography computer science

Summary

This document contains lecture notes on database systems and blockchain for AY24/25 trimester 1, presented by Zhang Wei at the Singapore Institute of Technology (SIT). The notes cover topics such as transaction recording, blocks, traditional ledgers, blockchain ledgers, consensus, and the process of adding blocks to the chain.

Full Transcript

INF2003: Database Systems Blockchain AY24/25 Trimester 1 Zhang Wei SIT Nov. 19, 2024 Module and Teaching Feedback AY24/25, Tri 1 From University: Complete both module and teaching feedback. Please share constructive feedback in the free text sections Academic Staff will not be able to ide...

INF2003: Database Systems Blockchain AY24/25 Trimester 1 Zhang Wei SIT Nov. 19, 2024 Module and Teaching Feedback AY24/25, Tri 1 From University: Complete both module and teaching feedback. Please share constructive feedback in the free text sections Academic Staff will not be able to identify the student. All feedback received are anonymous. Their grades will not be affected as the feedback results will only be shared with the academic staff after the release of exam results. From Wei: We have been improving this module continuously based on students’ feedback. Thank you for your contribution to our module and for helping your junior peers. What is Blockchain Originally for recording transactions, where: 王 宁 Transactions organized as blocks. 侯 有 Blocks are encryption-based and chained together from old to new. 将 种 Blocks can be accessed everywhere. 相 乎 Traditional ledger: e.g., OCBC, centralized leger for clients. OCBC, the centralized entity, always has the truth. Any discrepancies, client shall reconcile with OCBC (has the say). Blockchain leger: All nodes can access. All nodes have the truth. All nodes have the say. What if people share different opinions? Consensus to be achieved. Consensus is kind of democracy, but not really one people one vote. SIT NTU SIT NTU SingTel Koufu SingTel Koufu Process A user initiate a transaction. As confidential information inside, need to encrypt with digital signature. Like sign to pay in real world. How to let the other nodes know? Broadcast. Are we sure all nodes know? Distributed system. Theoretically, possible to wait forever. Those nodes which get the message, can choose to process/record. Each transaction one block? If so, the chain will be too long. Normally, received a lot transactions, and include some of them in a block. How to motivate the nodes to include a transaction? Pay transaction fee. Pay more, higher chance to be processed; initially not the dominant one. Process Can I add my block to the chain? Where the big reward comes (details later). All nodes want to add one block to a chain. But a chain can only be extended by 1. Compete for the right to add block. Mining process. Initially, reward much larger than transaction fee. One node wins the competition and adds a new block. Need the other nodes to acknowledge the win. Agree Consensus protocols. Starting Point + History New block reflects the “truth” accepted by all. -> Current State Start another round in the new chain. Supporting Technology New concept, old technologies (building blocks). Each full node in Blockchain keeps one copy of the whole chain. Problem: would the chain be super large? Buy a data center to participate? Then it encourages centralization again. Main cryptography techniques: Keys and Hash, mainly for blocks. Hash: h(x). x is a long text, object, file, etc. h(s) is a short representation of x. Given x and h, only 1 h(x). Deterministic. Given x1 != x2, h(x1) = h(x2). Collision. Rare. Even there is, u cannot control. Various hash functions available. We mainly use SHA-256. No matter how is the input x. -> the hash value is always 256 0/1 digits. Hash Solution: each block mainly consists of hash values, not raw info. Same block -> 1 hash value (given the same hash function). Any changes in the block -> different hash -> validation. Fast operation. How? Start with the Genesis block, or block 0. Compute the hash of the whole block, with all info of index, payload, etc. Block 1 must include the hash of block 0, as shown in “prev”. Compute the hash of the whole block, with all info of index, payload, etc. Every block records where this block comes from -> hash chain. Question: is blockchain a singly or doubly linked list? Genesis 0 1 2 3 4 5 N.A. prev prev prev prev prev payload payload payload payload payload payload hash hash hash hash hash hash Why Blockchain Cannot Be Tempered? 0 1 2 3 4 5 N.A. prev prev prev prev prev payload payload payload payload payload payload hash hash hash hash hash hash In block 2, I transferred 100 SGD to Tony Stark. Now the latest block is block 5. I want to temper block 2, e.g., change the amount to -100. Can I? The payload of block 2 has been changed. -> the hash of block 2 changes. -> the hash of block 2 cannot match with the “prev’ of block 3 anymore. We know the chain has been tempered by some simple hash comparisons. 0 1 2 3 4 5 N.A. prev prev ≠ prev prev prev payload payload payload’ payload payload payload hash hash hash’ hash hash hash Motivation to Participate I only want to use the system. I do not want to contribute. Can? Some jobs to do, for the whole system. Keep a copy of the history and current state. It is fine, as mostly small hashes instead of the large raw data. Package transactions. Add new blocks. Motivation: 1) transaction fee; 2) new block reward. In the beginning stage, new block reward is dominant. Transaction fee will be more important as the system matures. Motivation to Participate Finding a nonce: called mining. Possible > 1 miners get a valid nonce at the (approximately) same time? Payload can be different. Nonce can be different. Mining is a process of looking for luck. Luck is not a superpower. With a valid nonce and a valid block -> broadcast to all. Once become the most accepted block -> officially add the block. The miner, who add the block, received the transaction fee and block reward. This is why, your transaction may never be included if you put 0 trans fee. e.g., bitcoins rewarded decreasing in time (but can be increasing in value). Bitcoin: half for every 210,000 blocks. Since Feb. 2019, each new block gets 12.5 BTC ~= SGD 55,000. Since May 2020, each new block gets 6.25 BTC ~= SGD 400,000. 2024: 3.125 BTC ~= SGD 381,000. BTC 2010: 10,000 BTC 2 pizzas -> 2023 ~SGD 500 MILLION SGD! BTW, the guy recently said he does not regret … https://www.coindesk.com/price/bitcoin Proof of Work Finding a valid nonce is more or less guessing again and again. Who shall get the mining reward? Luck is the only factor? If everyone can, raspberry Pi or MCU rules the world. System attack becomes cheap -> system not secure anymore. Shall be sincere enough. Sincere ~ computing power in our story. Say, hash threshold 2^200 for SHA-256. The beginning 56 digits are all 0. Each digit 50% chance to be 0 -> try how many times can win? Expectation: 2^56 times -> expected 1 success. Expectation: hard to prove, easy to verify. Hard: intensive computation to find a valid nonce. Slower chain expansion. Expensive to cheat, e.g., adding invalid blocks. “It is not by speeches and Disagreement? -> computing power as the justice … majority resolutions that the Easy: just one hash comparison. great questions of the time are Operational friendly. Traceability and so on. decided, but by iron and blood.” Disagreement? The world is not perfect -> ppl extend the chain with different views. Miner 1 got a valid nonce, propose to add his block, and mine the next. Miner 2 got a valid nonce, propose to add his block, and mine the next. What will happen? State fork. Longest-chain rule. No matter how many forks, only the longest one wins. Every miner, checks the latest chain. Any forks, choose the longest one. Suppose all miners are fair, best way: broadcast early w/ good network. 4 5 prev prev 0 1 2 3 payload payload N.A. prev prev prev hash hash payload payload payload payload hash hash hash hash 4’ prev payload hash Discussion Is blockchain a good database for storing data? Record-keeping system. Cannot even work efficiently or work for CRUD. BTC, 1MB per block, 250B per trans, 10 min per block -> 400 trans per min. Visa: ~1,700 per second -> 102,000 trans per min. Can blockchain offer physical world traceability? Hardly any online system has real control in the offline physical world. Buy organic food in blockchain. Package can be swapped in physical world. New and hot technologies are not omnipotent. What are the suitable areas for blockchain? International and universal currency beyond the current financial system. No long-waiting remittance. No swift code. Unfortunately, also the reason why BTC is widely used in black market. Anti-counterfeiting. Data in the chain cannot be changed. Change, no matter how small, can be detected w/ hash comparison. Patent, Covid-19 cross-border documents, etc. Summary History -> now. We lack trust to each other, especially in a world-wide scenario. We do not even trust 3rd party. History recorded in distributed system, managed by all participate. “Agree on history” eventually leads to “agree on present”. Chain and hash. Raw data is not stored, making each participant keeps a full copy possible. Chain is hash-based, where each block records the info of the last block. -> once the last block is tempered, there will be a hash mismatch. Proof-of-work. Mostly widely used. Higher computing power -> more likely to add new block -> more likely get reward and fee. Fair and secure. Bad guys must pay a lot with steeply diminishing return. Be realistic and do not be fooled.

Use Quizgecko on...
Browser
Browser