So you're in it for the tech? Let's talk tech. A simple POW blockchain explanation w
#1
So you're in it for the tech? Let's talk tech. A simple POW blockchain explanation w

<!-- SC_OFF --><div class="md"><p>It always amazes me how many people say they are in it for the tech (yes I know it's a meme), but they can't begin to explain the first thing about how a blockchain works. If that's you, let's change that! I am going to try to really ELI5 the concepts but reinforce them with some simple python code. Disclaimer: I'm not an expert and happy to have anyone correct me.</p> <p>For this example, we'll be talking about proof of work (POW). This is just part 1. I don't want to overwhelm you, but if there is interest, I will make new posts until we've built out a full blockchain in python.</p> <p><strong>What is a blockchain?</strong></p> <p>It's nothing more than an immutable (not changeable) store of information (in blockchain, we call these blocks). What makes it special is that as there is new information to store, it gets saved on top of the existing data. Each new piece of information (block) stores a reference to the data below it. These references are in the form of hashes.</p> <p><strong>What is a hash?</strong></p> <p>The topic are hashes are really complex, but all you need to know about them is that they are a computer algorithm's that take data of an arbitrary size and converts it to a fixed size. If the input data is the same, the hash will be the same every time you generate it. If you only have the hash, you cannot reverse it to get back to the original data. You should also know that a tiny change to the input data, results in a completely different hash. It won't look similar at all.</p> <p><strong>Let's try it out:</strong></p> <p>This assumes you are using Python 3 and have a basic understanding of Python and the command line. If not, there are tons of resources online, but happy to try to answer any questions.</p> <p>in this example, we are going to use the standard programming string &quot;hello world&quot; as our input data for simplicity. But in a real blockchain the input data is most likely a group of many transactions.</p> <p>Open a terminal and enter the following. This opens a python interpreter in which you can run code.</p> <pre><code> python3 </code></pre> <p>Now enter each line 1 by 1, pressing enter between each line.</p> <pre><code>import hashlib # imports the hashing library input_data = &quot;hello world&quot;.encode('utf-8'Wink # set some input data first_hash = hashlib.sha256(input_data).hexdigest() # saves the hash of our input data to a variable print(first_hash) # prints out the hash </code></pre> <p>Notice that after the entering the last line you get this out:</p> <pre><code>b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9 </code></pre> <p>Repeat the steps above and you'll see the hash doesn't change.</p> <p>Now let's make one tiny change to our input data (making the word world plural) and prove that the hash stays the same length but completely changes. In the same terminal enter the following lines:</p> <pre><code>input_data_updated = &quot;hello worlds&quot;.encode('utf-8'Wink # create some new input data second_hash = hashlib.sha256(input_data_updated).hexdigest() print(second_hash) </code></pre> <p>Notice this time you the following output:</p> <pre><code>8067f1ae16f20dea0b65bfcbd50d59014d143c8ecebab179d923f6ef244b40f8 </code></pre> <p>You should know that we can just treat the hash like any other text and hash it again. We can even combine it with other text before we hash it. Let's try it out:</p> <pre><code>combined_hash = hashlib.sha256(str(first_hash).encode('utf-8'Wink + str(second_hash).encode('utf-8'Wink).hexdigest() print(combined_hash) </code></pre> <p>Now you will get the following:</p> <pre><code>3ef229cf1df86a5a0a0fed22d95484585995bc9d851e4b46ac57b7287fa0f9ea </code></pre> <p><strong>How do hashes make a blockchain immutable?</strong></p> <p>Because we now know the properties of hashes, we know that changing the input data changes our hash. We also know the each block refers to the block below it by referencing it's hash. The way it does this is by combining its own input data with the hash of the previous block, just as we did in the above example. In POW, nodes run special software the keep track of the existing blocks and validate new ones. Just like we did in the above example, they can calculate the hash for themselves. If things don't check out they will reject the block.</p> <p>So imagine an attacker wants to change data in an older block so instead of saying you sent crypto to your friend, they try to rewrite history to say you sent crypto to them. But we know if they try to propose a block with this change, it will change the hash of the block they modified and thus will change the hash of every block after it.</p> <p>The only way they could work around this is by performing a 51% attack. in POW, nodes follow the longest chain of valid blocks. But because the attacker has gone and changed an older block all the blocks after that one are invalid because the hashes are wrong. They would need to regenerate all the blocks after the one they modified to make them valid. But doing so is expensive because meanwhile, all other miners are generating real blocks. This is where 51% attack comes in. If the attacker controlled &gt; 50% of the hashing power (computer's generating blocks), their modified chain will eventually become longer than the real one and nodes will begin treating that as the real chain.</p> <p>This scenario is difficult to do because gaining hashing power requires a lot of computer resources that are expensive. In the next part, we'll look at what these computers are doing that makes it a long and costly attack.</p> </div><!-- SC_ON --> submitted by <a href="https://www.reddit.com/user/Routine_Elk_7421"> /u/Routine_Elk_7421 </a> <br/> <span><a href="https://www.reddit.com/r/CryptoCurrency/comments/outcav/so_youre_in_it_for_the_tech_lets_talk_tech_a/">[link]</a></span> <span><a href="https://www.reddit.com/r/CryptoCurrency/comments/outcav/so_youre_in_it_for_the_tech_lets_talk_tech_a/">[comments]</a></span>Kind Regards R
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  FC Barcelona secures $132M investment for blockchain and NFT venture Dato 0 190 08-11-2023, 08:10 PM
Last Post: Dato
  Crypto Winter’s Chilling Aftermath: Galaxy Digital and Riot Blockchain Report Q2 L Andy 0 118 08-11-2023, 06:35 AM
Last Post: Andy
  US and China AI-tech standoff shows signs of spreading to other countries Dato 0 121 08-11-2023, 06:35 AM
Last Post: Dato
  Crypto Winter’s Chilling Aftermath: Galaxy Digital and Riot Blockchain Report Q2 L Andy 0 157 08-10-2023, 08:18 AM
Last Post: Andy
  Coinbase Launches Blockchain and Edges Closer to Goal of Reaching 1 Billion People Andy 0 103 08-10-2023, 08:18 AM
Last Post: Andy



Users browsing this thread: 1 Guest(s)