<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Raj Shetgar on Medium]]></title>
        <description><![CDATA[Stories by Raj Shetgar on Medium]]></description>
        <link>https://medium.com/@rajshetgar?source=rss-e8357e8f6540------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Lq8G3GS9m4PPfafu-1XJdA.jpeg</url>
            <title>Stories by Raj Shetgar on Medium</title>
            <link>https://medium.com/@rajshetgar?source=rss-e8357e8f6540------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 05:00:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rajshetgar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Blockchain: Proof of Work (PoW) in bitcoin]]></title>
            <link>https://medium.com/@rajshetgar/blockchain-proof-of-work-pow-in-bitcoin-34de270ac4c5?source=rss-e8357e8f6540------2</link>
            <guid isPermaLink="false">https://medium.com/p/34de270ac4c5</guid>
            <category><![CDATA[byzantine]]></category>
            <category><![CDATA[satoshi-nakamoto]]></category>
            <category><![CDATA[consensus]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[proof-of-work]]></category>
            <dc:creator><![CDATA[Raj Shetgar]]></dc:creator>
            <pubDate>Sat, 07 Apr 2018 13:48:28 GMT</pubDate>
            <atom:updated>2018-04-07T22:22:35.045Z</atom:updated>
            <content:encoded><![CDATA[<p>What is proof of work (pow)? why is it needed ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*fpMpJco5H9foo6c1Ug71AA.png" /><figcaption>Figure 1: Proof of Work used in blockchain (bitcoin)</figcaption></figure><p>From my <a href="https://medium.com/@rajshetgar/fake-blocks-on-a-blockchain-10ca050f12">previous post</a> we have understood the following:</p><ul><li>On an average every 10 mins there is a new block created on the bitcoin network. A new block is linked to the previous block using a reference, forming a chain… a chain of blocks hence called “blockchain”.</li><li>The blocks are created by special computers called “miners” on the bitcoin network. Miners main role is to create blocks and to verify blocks, for creating blocks the miners are rewarded with bitcoins (bitcoin will be rewarded to a miner only if remaining miners verify and approve the block as valid.)</li></ul><p>Now to understand what is “proof of work” and why it is needed, let us change the rules of bitcoin blockchain and say that no “proof of work” is needed for block creation. Below is the new block structure without “proof of work” requirement:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*E-hD2teN74MlP8w6iyq4xA.png" /><figcaption>Figure 2: Block without “Proof of Work”</figcaption></figure><p>Now to create a block without “proof of work” as shown in Figure 2, the miners need to take all the approved transactions (UTXO set) and hash it to form the merkel root, put a time stamp and reference it to the previous block number. To do this it would take less than a millisecond even with the slowest computer out there in the market today. And since creating a block is rewarded with bitcoins and each bitcoin is valued more than $8,000 AUD (as of 6th April 2018), this would attract many miners to create a block and also motivate them the collude to form a cartel to disallow miners outside the cartel from creating a block by spamming the network with loads of data and at the same time use powerful computers within the cartel to create new blocks — this would fail the very idea of distributed &amp; decentralised network.</p><p>Another problem, and in fact “<strong><em>the main problem</em></strong>” is how would everyone on the network come to an agreement (consensus) as to which block to use from which miner ? Since there is no trusted third party who can finalise and reward a particular miner for creating the block, every miner on the network have to work together with other miners to come to an agreement to reward the miner who created the block. Since bitcoin network is open source and decentralised, any one can join the network. Miners cannot trust each other as to if the other miner is “honest” or “dishonest” (safest would be to assume other miners are dishonest). And since the miners are geographically located in different locations, it can also be assumed that there is a chance that the network between the miners is also compromised. <strong><em>Under these conditions its impossible to come to an agreement (consensus), thus resulting in no block creation and no blockchain</em></strong> ! These two reasons, 1: trusting other miners if they are honest/dishonest and 2: network between miners being compromised, gives rise to what is called as “Byzantine Generals’ Problem”. Below is a quick 2 min videos that explains “Byzantine Generals’ Problem”.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F_MwqAaVweJ8%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D_MwqAaVweJ8&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F_MwqAaVweJ8%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d9828d6a59725ecd042d38164d2d4cf/href">https://medium.com/media/5d9828d6a59725ecd042d38164d2d4cf/href</a></iframe><p>The “<a href="https://en.wikipedia.org/wiki/Byzantine_fault_tolerance">Byzantine Generals’ Problem</a>” has not been solved till today. Satoshi Nakamoto in his/her paper proposed a smart way to solve this problem in a probabilistic way (not a 100% solution). Satoshi Nakamoto proposed to use “Proof of Work” in bitcoin which was based on “Proof of Work used in HashCash” (HashCash — A solution to prevent email spam).</p><p><em>HashCash: In order to prevent spammers sending same email to multiple recipients, </em><a href="https://en.wikipedia.org/wiki/Hashcash"><em>Adam Back</em></a><em> proposed a system where a person sending an email had to perform some proof of work (that required computation work) on the “email’s contents” and the “to address” on every email. People sending genuine emails were willing to do this easily as it didn’t require a lot of additional resource but for spammers this would result in a lot of computational resources — which cost them a lot of money and hence forced them not to “not spam / reduce spamming”.</em></p><p>“Proof of Work” in bitcoin network forces the miners to trust each other and to come to an agreement (consensus) in block creation/verification and move on with the next block to keep the blockchain alive and growing. “Proof of work” is implemented in bitcoin as follows:</p><ul><li>For every new block, bitcoin network expects a solution for a cryptographic puzzle that it creates as “work — in the form of “<em>difficulty target</em>”.</li><li>The miners who are creating a block have to also solve the cryptographic puzzle in the form of “nonce — which is proof of work done by miner — hence called “proof of work”.</li><li>Simply put, “difficulty target” is an output of a cryptographic function, where the cryptographic function is fixed and the only variable is the input “nonce”. Based on different value of the input, the output will differ. The only way to generate a “nonce” value that will result in the expected “difficulty target” (less or equal) by any miner in the network is to do it manually step by step in a for-loop/while-loop starting from value “0, 1, 2, 3, 4…..” till the nonce value that will result in the expected “difficulty target” (less or equal).</li><li>The “difficulty target” is selected by the network dynamically based on how fast the miners (computer resources) are. No matter how slow or fast the miners’ computers, the “difficulty target” is set such that it will approximately take 10mins to find a nonce. Miners spend a lot of computer resource and electricity to find the “nonce”, which costs a lot of money in the real world.</li><li>As soon as a miner finds a nonce, the miner assembles the block along with the nonce value, difficulty target and announces the new block on the network. Other miners can verify the nonce in a fraction of a millisecond, if verified successfully all the miners will now start working on creating the next block.</li><li>Due to this intensive process needed to find the nonce for the difficulty target, all the miners come to an agreement (consensus) for the new block with the correct proof of work in the form of “nonce” irrespective if they believe the other miner is honest/dishonest because it would take a lot of energy/money to find the nonce and no miner would spend resources upfront later to be rejected by the other miners on the network. The miners have the motivation to do good so that they can get rewarded for block creation.</li><li>The “Proof of Work” consensus will fail if more than 51% of the miners are dishonest, if this is the case then the whole blockchain will come down destroying the value of each bitcoin to less than $0. So its in the best interest of existing miners who already have bitcoins with them to always be honest and do the right thing to keep the value of bitcoins not to fall.</li></ul><p>Below is an explanation by Satoshi Nakamoto on how “Proof-of-Work” solves the Byzantine Generals’ Problem.</p><p><a href="https://www.mail-archive.com/cryptography@metzdowd.com/msg09997.html">Re: Bitcoin P2P e-cash paper</a></p><p><strong>So to summarise:</strong></p><ul><li>In a distributed and decentralised system, in the absence of a “trusted third party” all participants should come to an agreement to accept/reject what is valid/invalid in the system else the system will fail.</li><li>The process of coming to an agreement to accept/reject what is valid/invalid in the system is called “consensus”.</li><li>Its impossible to come to a 100% consensus in distributed and decentralised system. This is called the “Byzantine Generals’ Problem” and until today it has not been solved.</li><li>Satoshi Nakamoto in his/her paper proposed a smart way to solve “Byzantine Generals’ Problem” problem in a probabilistic way in the form of “Proof of Work”. (not a 100% solution but the best available solution so far).</li><li>“Proof of Work” consensus concept was initially proposed by Adam Back in “HashCash” to prevent email spams.</li><li>“Proof of Work” consensus concept is used in bitcoin blockchain to solve “Byzantine Generals’ Problem”. (Works only until 51% of the participants are honest participants)</li><li>Consensus in bitcoin blockchain is achieved by participants (miners) by solving a process intensive solution in the form of “nonce — proof of work” for a cryptographic problem given by the network in the form of “work — difficulty target”. Every block has a corresponding nonce for its difficulty target and it takes approximately 10mins to find the nonce. As soon as the nonce is found, the block is declared by the miner on the network, other miners can verify the nonce in a fraction of a millisecond, if verified successfully all the miners will now start working on creating the next block as the reward gets awarded to the miner who created the block which has the nonce.</li><li>Thus using “Proof of Work” concept, the miners in the bitcoin blockchain network come to a consensus on agreeing for a new block to be created on the blockchain and a block gets created on an average every 10mins.</li><li>There is a lot of agreements/disagreements on how much energy is spent (or rather wasted) in creating each block on bitcoin blockchain using the “Proof of Work” consensus concept. Hence alternative consensus concepts have evolved over time like “Proof of Stake”, which uses lot less energy. A follow-up blog will explain “Proof of Stake” consensus concept.</li></ul><p>Other articles on bitcoin/blockchain that will help in better understanding blockchain tech/distributed ledger tech:</p><ul><li><a href="https://medium.com/@rajshetgar/fake-blocks-on-a-blockchain-10ca050f12">Why can’t there be any fake blocks on a bitcoin blockchain ?</a></li><li><a href="https://medium.com/@rajshetgar/rogue-miner-creating-fake-transactions-cf38076d346b">What prevents the miner from creating fake bitcoins ?</a></li><li><a href="https://medium.com/@rajshetgar/blockchain-decoding-bitcoin-transaction-5da619ca9721">Part 1: What actually happens when you transfer bitcoin to someone else ?</a></li><li><a href="https://medium.com/@rajshetgar/part-2-decoding-bitcoin-transaction-2de138704d2d">Part 2: What actually happens when you transfer bitcoin to someone else ?</a></li></ul><p>Note: If you have any questions related to blockchain / distributed ledger technologies that you need answers, please ask the questions below. I will try to answer all your questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34de270ac4c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blockchain: Decoding bitcoin transaction (2)]]></title>
            <link>https://medium.com/@rajshetgar/part-2-decoding-bitcoin-transaction-2de138704d2d?source=rss-e8357e8f6540------2</link>
            <guid isPermaLink="false">https://medium.com/p/2de138704d2d</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[transaction-outputs]]></category>
            <category><![CDATA[transaction-inputs]]></category>
            <category><![CDATA[utxo]]></category>
            <dc:creator><![CDATA[Raj Shetgar]]></dc:creator>
            <pubDate>Sat, 17 Mar 2018 05:09:31 GMT</pubDate>
            <atom:updated>2018-03-23T02:25:13.193Z</atom:updated>
            <content:encoded><![CDATA[<p>Part 2: What actually happens when you transfer bitcoin to someone else ?</p><p>In <a href="https://medium.com/@rajshetgar/blockchain-decoding-bitcoin-transaction-5da619ca9721"><strong><em>part 1</em></strong></a>, we focused on understanding what happens when a bitcoin is transferred to someone on the bitcoin network. This article will focus on in depth analysis of what happens in each transaction.</p><p>As we know, when one person transfers a bitcoin to someone else they actually only transfer the ownership rights. When a transfer happens, the transfer has to be first validated by “full nodes” who will check if the sender actually owns the bitcoins and then approves the transaction if the sender owns the bitcoins. The approved transactions are listed in “Unspent Transaction Outputs set” or “UTXO set”. The miners take the transactions in the “UTXO set” and assemble them into blocks, if the block is legitimate and successfully verified by remaining miners then the block becomes part of the immutable blockchain.</p><p>Taking the same example from <a href="https://medium.com/@rajshetgar/blockchain-decoding-bitcoin-transaction-5da619ca9721">part 1</a>, we will use the transaction worth “0.0199” bitcoin (I paid for my coffee at “Waves Coffee” in Vancouver on Dec 12, 2013). In this case my bitcoin wallet (sender) transmits a “chunk” of data as shown in “Figure 1”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/883/1*0mmQM_vInMNTov_0dQZUtg.png" /><figcaption>Figure 1: Chunk of data transmitted by sender’s wallet</figcaption></figure><p>In order to understand this better we will convert the matrix like “chunk” of data to something we humans can understand. There are two steps to creating a block, in step 1 the sender’s wallet will transmit a chunk of data on the network which will be picked up by the full-nodes to see if the sender owns the bitcoin and is legitimate to spend the bitcoins and once it’s found legitimate it becomes part of “”UTXO set”, in step 2 (called mining) some verified transactions from the “UTXO set” is taken and mined into blocks on the blockchain.</p><p>To understand better, we will start with “step 2” and work backwards. So let’s go back in time and pick up the mined block that was created on Dec 12th 2013. As we know that each block on the blockchain contains two parts, “block header” and “transactions” as shown in “Figure 2”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*6qx9S-SLFoxMmdSTWIQHJg.png" /><figcaption>Figure 2: Each block is made up of “block header” + “transaction data”</figcaption></figure><p>Now when we identify our transaction in the “list of transactions” in the block, we can get the details of the transactions in “human” readable format on websites like “<a href="http://www.blockchain.info/">www.blockchain.info</a>&quot; or “<a href="http://www.chainquerycom/">www.chainquerycom</a>&quot;. When we query our <a href="https://blockchain.info/tx/ccc1534f7d8c56403652f13f565484b60a69e8abc710e8cfe3e56769690f8d23">transaction</a> on “blockchain.info” we get the details as shown in “Figure 3”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XYKGfvG4NunbEm-TZpEFGQ.png" /><figcaption>Figure 3: Details of the transaction “<a href="https://blockchain.info/tx/ccc1534f7d8c56403652f13f565484b60a69e8abc710e8cfe3e56769690f8d23">ccc1534f7d8c56403652f13f565484b60a69e8abc710e8cfe3e56769690f8d23</a>”</figcaption></figure><p>Each verified transaction selected from “UTXO set” and then mined into a block consists of:</p><p>(1) Sender Address (In our case its myself, the owner of the bitcoins)</p><p>(2) Recipient Address (In our case it’s the receiver, “Waves Coffee”)</p><p>(3) Bitcoin transferred to the recipient (In our case its 0.0199 bitcoins)</p><p>(4) Bitcoin returned as “change” to the sender (In bitcoin network, every time there is a transaction the whole amount of bitcoins owned by the sender is transferred but the transfer is split into three parts of which one part goes to the receiver (0.0199), the second part goes back to the sender as change (0.0004644) and the third part goes to the miners as fees (0.0005). The simple logic here is that whatever bitcoins the sender owns, has to be spent but change will be returned back to the sender after deducting fees)</p><p>(5) The Sender Address (same address of the sender where change bitcoins (0.00004644) will be sent back)</p><p>(6) Transaction number: this is an unique transaction number that is set in stone and never changes after the block is mined.</p><p>(7) Block number: this is an unique block number. Each block on the blockchain has an unique number and once a block is mined and becomes part of the longest chain, it becomes immutable and never changes.</p><p>Others: there are also other fields, such as “total inputs = the total balance of bitcoins that the sender owns before the transaction = 0.0208644”, “total outputs = is made up of two parts, one being the bitcoins that are transferred to the receiver and the other being the change bitcoins sent back to the original sender” and finally “the fees = fees that are paid to the miner”</p><p>Before the miner mines the transaction from the UTXO set into a block, the full-nodes collect the transaction and validate the transaction before it can get into UTXO set. Now lets decode the “chunk” of data and what it means to be validated to get into “UTXO set”.</p><p>In figure 1, we see the serialised data that’s transmitted on the network when I made the “0.0199” bitcoin transfer to “Waves Coffee”. Now using “<a href="http://chainquery.com/bitcoin-api/getrawtransaction/ccc1534f7d8c56403652f13f565484b60a69e8abc710e8cfe3e56769690f8d23/1">www.chainquery.com</a>&quot; if we decode the <a href="http://chainquery.com/bitcoin-api/getrawtransaction/ccc1534f7d8c56403652f13f565484b60a69e8abc710e8cfe3e56769690f8d23/1">transaction</a> in figure 1, we get “figure 4”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*EedYWQX9V8-LvUYy7vCjWQ.png" /><figcaption>Figure 4: Transaction (Human readable based on Figure 1)</figcaption></figure><p>Each transaction that is new and still not part of the UTXO set, consists of (as shown in figure 4):</p><ul><li>Each transaction, amongst others has two main parts “transaction inputs” and “transaction outputs”.</li><li>In transaction inputs we have:</li></ul><p>(1) Transaction ID: Is a reference to a previous transaction using which it can be verified that the sender received bitcoins earlier and is the current owner of the bitcoins, so he will be allowed to spend.</p><p>(2) vout: is the index identifying which output to use from the above “Transaction ID”. In most cases it will be the 2nd item from the previous “transaction output”. The index starts from 0 and in our case its “1”, which means that we need to use the item 2 from “transaction outputs” from the transaction referenced in “ transaction id”</p><p>(3) scriptSeg: Is also called “unlocking script”. It is generated by the wallet of the sender using “private key”. It’s made up of “signature” and “public key” that shows the ownership of the bitcoins</p><ul><li>In the second part, we have transaction outputs:</li></ul><p>(4) value: Bitcoin value to be sent represented in satoshi (1 BTC = 100,000,000 satoshi)</p><p>(5) n: there are more than 1 items in the “transaction outputs”. The first transaction is set as “0”, in future this output index will be used in “vout of transaction inputs” to form a link.</p><p>(6) scriptPubKey: Is also called “Locking script” and it consists of the recipient’s details (address) and some op-codes that will be executed. All the “op-codes and data” in one transaction are executed together and if the execution results in an error then the transaction is rejected and if successful then the receipt gets the bitcoin that was sent and remaining change goes back to the sender.</p><p>(7) value: the 2nd item in “transaction outputs” is the change that needs to be returned back to the sender. It’s the bitcoin value represented in satoshi (1 BTC = 100,000,000 satoshi)</p><p>(8) n: since its the 2nd item in the transaction, this is set as “1”.</p><p>(9) scriptPubKey: the 2nd item in the “transaction output” scriptPubKey” consists of the sender’s details (address) and some op-codes. We need the sender’s details because we need to send back the change to the sender.</p><p><strong>So to summarise:</strong></p><p>When a transaction is initiated, the wallet of the sender assembles the data that will be sent on the network. This “chunk” of data will contain “transaction inputs” and “transaction outputs”.</p><ul><li>The “transaction inputs” will have a reference back to the previous transaction, which will prove the sender’s wallet is actually spending bitcoins that it received/owns and by using cryptography a signature is generated and a reference to public key is provided. Together with “signature” and “public key” we can prove that the wallet possesses the “private key” which will prove the wallet can spend the bitcoins.</li><li>The “transaction outputs” will have details of the recipient address and how much bitcoins need to be sent to the recipient along with some OP-codes. One thing to remember is that in bitcoin network, the sender has to spend all the bitcoins it owns in one transaction and if there is excess bitcoins left then they will be sent back to the sender as “change” in the same “transaction outputs”. There is also some bitcoins that will be used to pay the fees but we have ignored this in our explanation.</li></ul><p>So when other nodes start seeing the “chunk” of data on the network sent by the sender’s wallet, the full-nodes on the network pick up these transactions and start to verify if it is legitimate transaction or not. By using the details in “transaction inputs” and “transaction outputs” along with the OP-codes, the full-nodes execute the OP-Codes and if executed successfully it proves that the sender’s wallet is sending bitcoins that it owns and now the ownership for those bitcoins has changed to “recipient”. At the end of this successful verification, the full-nodes add this transaction into a local database called “UTXO set”. The “UTXO set” consists of all legitimate transactions that are waiting to be finalised and mined into a block to become part of the immutable blockchain.</p><p>The miners main job in the network is to create new blocks and verify new blocks created by other miners on the blockchain. To prevent collusion amongst miners who could create fake blocks, the network tries to prevent this collusion by giving a puzzle that needs to be solved by all miners on the network. This cryptographic puzzle is in the form of “difficulty target” for which the miner has to find a solution in the form of a “nonce”. As soon as a nonce is found, the miner assembles the block using transactions from the “UXTO set” and declares it on the network, if the block is successfully verified by other miners it will become part of the blockchain.</p><p>Note: If you have any questions related to blockchain / distributed ledger technologies that you need answers, please ask the questions below. I will try to answer all your questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2de138704d2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blockchain: Decoding bitcoin transaction (1)]]></title>
            <link>https://medium.com/@rajshetgar/blockchain-decoding-bitcoin-transaction-5da619ca9721?source=rss-e8357e8f6540------2</link>
            <guid isPermaLink="false">https://medium.com/p/5da619ca9721</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[miners]]></category>
            <category><![CDATA[satoshi]]></category>
            <category><![CDATA[utxo]]></category>
            <dc:creator><![CDATA[Raj Shetgar]]></dc:creator>
            <pubDate>Thu, 15 Mar 2018 13:37:39 GMT</pubDate>
            <atom:updated>2018-03-23T02:24:47.793Z</atom:updated>
            <content:encoded><![CDATA[<p>Part 1: What actually happens when you transfer bitcoin to someone else ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*-Y5_e-4Rhazr-ROlG6PQcA.png" /><figcaption>Figure 1: Actual payment of 0.0199 BTC done by Raj Shetgar to Waves Coffee in Vancouver on Dec 12, 2013</figcaption></figure><p>This article focuses on high level explanation, for more in depth analysis of what happens in each transaction please read <a href="https://medium.com/@rajshetgar/part-2-decoding-bitcoin-transaction-2de138704d2d"><strong><em>part 2</em></strong></a> of this article.</p><p>Technically speaking no one can transfer bitcoins from them to others because what an individual owns is “ownership” rights in the form of private key which allows them to transfer ownership to someone else. A transaction tells the network that the owner has authorised the transfer of ownership to another owner.</p><p>Every time a transaction happens, it gets broadcasted on the network and it gets assembled into “unspent transaction output — UTXO” set by full-nodes on the network. The “full nodes” focus on collecting the new transactions and putting together in the “UTXO set” (which keep growing and shrinking).</p><p>Each full node creates their own copy of UTXO set by actually scanning every block from the beginning (genesis block) to the latest block and store it in a local “UTXO Database” — this database allows the node to quickly verify transactions to see if the sender of bitcoins actually has received bitcoins before sending it to someone else (verifying ownership).</p><p>The miners are rewarded to put together these UTXO transactions together to form a block (a block is made up of transactions and block header). The miners focus on assembling the block and then declare the new block on the network to get rewarded, if the block is successfully verified it will become part of the blockchain.</p><p>Based on where the miners and nodes are located geographically they pick up different transactions from UTXO sets. Hence many transactions made at the same time can end up being in different blocks on the blockchain.</p><p>Miners and full nodes both collect all transactions to create their own “UTXO set” locally but only the miners create the block for the blockchain, publish/verify the blocks on the blockchain. Full nodes do not get rewarded whereas miners get rewarded for creating/publishing valid blocks.</p><p>Here is an example (Figure 1 above), back in 2013 when I was living in Vancouver, I was introduced to bitcoins/blockchains. I was working with a start-up that was building a bitcoin exchange and also installed world’s first bitcoin atm. I purchased some bitcoins using the ATM and used “0.0199 bitcoin” to pay for my coffee at “Waves Coffee” in Vancouver on Dec 12, 2013. When I made that transaction of 0.0199 BTC, “Figure 2” is what happened on the network.</p><p>When someone makes transfer on the bitcoin network, the sender transmits a “chunk” of data and in that chunk of data there is the value of bitcoin that will change ownership along with other data. In Figure 2, below you can see the value “0.0199 BTC = 1,990,000 satoshis = 0x1e5d70 = 705d1e encoded in “little-endian” transferred.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RaLMnDqk0pdtrfUngwjE-A.png" /><figcaption>Figure 2: Transfer of 0.0199 BTC = 1,990,000 satoshis = 0x1e5d70 = 705d1e encoded in little-endian</figcaption></figure><p>This blog has a follow-up blog which is a bit more technical and will explain each and every byte in the transaction. You can read <a href="https://medium.com/@rajshetgar/part-2-decoding-bitcoin-transaction-2de138704d2d?source=linkShare-e8357e8f6540-1521323924">part 2 of this blog here</a>, if not then then keep staring at the “Matrix” like code above trying to decode it…</p><p>Note: If you have any questions related to blockchain / distributed ledger technologies that you need answers, please ask the questions below. I will try to answer all your questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5da619ca9721" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blockchain: Rogue bitcoin miners creating fake transactions]]></title>
            <link>https://medium.com/@rajshetgar/rogue-miner-creating-fake-transactions-cf38076d346b?source=rss-e8357e8f6540------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf38076d346b</guid>
            <category><![CDATA[decentralised-ledger]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[bitcoin-mining]]></category>
            <category><![CDATA[bitcoin]]></category>
            <dc:creator><![CDATA[Raj Shetgar]]></dc:creator>
            <pubDate>Tue, 13 Mar 2018 13:41:59 GMT</pubDate>
            <atom:updated>2018-03-17T05:12:48.608Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>What prevents the miner from creating fake bitcoins ?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*4uXlNc76szEwhMOFO33JVg.png" /><figcaption>Figure 1: Bitcoin Blockchain</figcaption></figure><ul><li>As we all know, there is no free lunch and everyone needs to pay a price for everything that’s valuable. Miners provide computer resources to the bitcoin network to run and the networks rewards the miners in the form of “transaction fees” and “block making reward — for every new block that’s created”.</li><li>Even though it takes seconds to validate the contents of each block and it’s easy to do, it is made difficult on purpose by creating a puzzle that needs to be solved. This cryptographic puzzle is in the form of “difficulty target” for which the miner has to find a solution in the form of a “nonce”. Lot of computer resource and electricity is used to find the “nonce” which in the real world costs “money”. The miners are actually spending their own “money” to find the “nonce” to create a new block. There is an inherent interest they have to recover their money plus addition profits in the form of “transaction fees” and “block reward”. They have the motivation to do good so that they can get rewarded.</li><li>But now let’s assume that some miners (i.e. rouge miners) get greedy and they figures out a way to collude where they can earn more bitcoins by creating some new fake bitcoins and broadcasting these as unauthorised transactions and then they try to create a new block out of these illegitimate transactions. Let’s assume that they were able to find the “nonce” and they publish their block to the network.</li><li>Every time a new block is published by a miner, the remaining miners/nodes will try to validate the block by checking if the “nonce” is correct and the contents of the new block is legitimate.</li><li>Each block has two main parts, 1) block header and 2) transactions.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*6qx9S-SLFoxMmdSTWIQHJg.png" /><figcaption>Figure 2: Details of each block (bitcoin blockchain)</figcaption></figure><ul><li>The 2nd part in each block on the blockchain has all the “transactions” validated in the current block, in our case it also contains unauthorised transactions. Now miner/node who is trying to check if the miner who created the block is valid or not, starts with the block header which has the “difficulty target” and the solution “nonce”, using functions within the bitcoin software it will verify if it’s true or false, if it’s true it then moves to the next part “the transactions”. Each transaction has details of “bitcoin ownership” from the sender to the receiver and reference to the previous transaction which shows how the sender in the first place received the bitcoins. This link to previous transactions can traverse all the way back to “block 0 — genesis block”. Now since some transactions were fake, the whole block gets rejected by other miners/nodes in the network.</li><li>Now the “rouge miner” who tried to cheat the system lost an opportunity to earn bitcoins as rewards even after spending electricity and lost the opportunity to earn “transaction fees”. This economics of operation will never work and result in going bankrupt.</li><li>Blocks on the network are like a “puzzle” it needs to be solved to look like a completed puzzle (like the puzzle game) with all the pieces put together in the right place. But if some miners try to cheat the system, his/her puzzle solution looks incomplete and can easily be spotted by other miners. The bitcoin network is designed in a way to force everyone to play by the rules, those who play by the rules get rewarded and those who don’t will not get rewarded (i.e. from miners perspective)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*dBbB4CwSemA3wC0LryCGZg.png" /><figcaption>Figure 3: New transactions mined into blocks resulting in a blockchain</figcaption></figure><ul><li>You can only have unauthorised transactions and also approved by miners if and only if more than 51% of the miners are trying to cheat the system and all working together to cheat the system. (this is what is called as the 51% attack)</li></ul><p>Note: If you have any questions related to blockchain / distributed ledger technologies that you need answers, please ask the questions below. I will try to answer all your questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf38076d346b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blockchain: Fake bitcoin blocks on blockchain]]></title>
            <link>https://medium.com/@rajshetgar/fake-blocks-on-a-blockchain-10ca050f12?source=rss-e8357e8f6540------2</link>
            <guid isPermaLink="false">https://medium.com/p/10ca050f12</guid>
            <category><![CDATA[full-node]]></category>
            <category><![CDATA[nonce]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[utxo]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Raj Shetgar]]></dc:creator>
            <pubDate>Tue, 13 Mar 2018 11:10:24 GMT</pubDate>
            <atom:updated>2018-03-17T05:13:37.438Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Why can’t there be any fake blocks on a bitcoin blockchain ?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*dBbB4CwSemA3wC0LryCGZg.png" /><figcaption>Figure 1: From new transactions to blockchain</figcaption></figure><ul><li>On an average every 10 mins there is a new block created on the bitcoin blockchain.</li><li>A new block gets created by miners who collect all transactions (UTXO) that have not been confirmed in any previous blocks.</li><li>As soon as a new block is finalised and put on the blockchain, the race begins to finalise the next block. To make the race more interesting the network provides a cryptographic challenge to all the miners to solve in the form of “difficulty level”, for which the miners have to find an answer called “nonce” (proof-of-work). This cryptographic challenge is hard to solve but easy to verify.</li><li>So what all the miners do is, they first collect all the unconfirmed transactions (UTXO) that fit the block size and then start solving the challenge to find the “nonce”. A solution (nonce) to the challenge (difficulty level) can only be solved by miners by going through a “for loop or while loop” until they find a solution. If a miner (or miner pool) finds a solution, they assemble the block including declaring the solution (nonce) and reference to the previous confirmed block.</li><li>Once a new miner (or miner pool) declares a new block with solution (nonce), other miners check if the solution (nonce) solves the cryptographic challenge “difficulty level” and all the transactions within the block are legitimate. If other miners see that the block is legitimate, then they acknowledge it and start the race to solve the next block, if not they reject the block — hence there can never be a fake block.</li><li>Together with “reference to previous block”, “merkle root”, “time stamp”, “difficulty level”, “nonce” and “all transactions within the block” a new immutable block is formed which can be validated by anyone on the network.</li></ul><p>Note: If you have any questions related to blockchain / distributed ledger technologies that you need answers, please ask the questions below. I will try to answer all your questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10ca050f12" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>