[Tut] Can a Miner Change a Bitcoin Transaction? - Printable Version +- Sick Gaming (https://www.sickgaming.net) +-- Forum: Programming (https://www.sickgaming.net/forum-76.html) +--- Forum: Python (https://www.sickgaming.net/forum-83.html) +--- Thread: [Tut] Can a Miner Change a Bitcoin Transaction? (/thread-99350.html) |
[Tut] Can a Miner Change a Bitcoin Transaction? - xSicKxBot - 05-07-2022 Can a Miner Change a Bitcoin Transaction? <div><div class="kk-star-ratings kksr-valign-top kksr-align-left " data-payload="{"align":"left","id":"340464","slug":"default","valign":"top","reference":"auto","count":"0","readonly":"","score":"0","best":"5","gap":"5","greet":"Rate this post","legend":"0\/5 - (0 votes)","size":"24","width":"0","_legend":"{score}\/{best} - ({count} {votes})"}"> <div class="kksr-stars"> <div class="kksr-stars-inactive"> <div class="kksr-star" data-star="1" style="padding-right: 5px"> <div class="kksr-icon" style="width: 24px; height: 24px;"></div> </p></div> <div class="kksr-star" data-star="2" style="padding-right: 5px"> <div class="kksr-icon" style="width: 24px; height: 24px;"></div> </p></div> <div class="kksr-star" data-star="3" style="padding-right: 5px"> <div class="kksr-icon" style="width: 24px; height: 24px;"></div> </p></div> <div class="kksr-star" data-star="4" style="padding-right: 5px"> <div class="kksr-icon" style="width: 24px; height: 24px;"></div> </p></div> <div class="kksr-star" data-star="5" style="padding-right: 5px"> <div class="kksr-icon" style="width: 24px; height: 24px;"></div> </p></div> </p></div> <div class="kksr-stars-active" style="width: 0px;"> <div class="kksr-star" style="padding-right: 5px"> <div class="kksr-icon" style="width: 24px; height: 24px;"></div> </p></div> <div class="kksr-star" style="padding-right: 5px"> <div class="kksr-icon" style="width: 24px; height: 24px;"></div> </p></div> <div class="kksr-star" style="padding-right: 5px"> <div class="kksr-icon" style="width: 24px; height: 24px;"></div> </p></div> <div class="kksr-star" style="padding-right: 5px"> <div class="kksr-icon" style="width: 24px; height: 24px;"></div> </p></div> <div class="kksr-star" style="padding-right: 5px"> <div class="kksr-icon" style="width: 24px; height: 24px;"></div> </p></div> </p></div> </div> <div class="kksr-legend"> <span class="kksr-muted">Rate this post</span> </div> </div> <p>You should always apply your own critical thinking when it comes to the crypto space. One question asked by many critical thinkers who know the overall idea of the <a href="https://blog.finxter.com/a-regex-to-match-bitcoin-addresses/" data-type="post" data-id="31419" target="_blank" rel="noreferrer noopener">Bitcoin</a> protocol but not yet its technicalities is:</p> <p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/13.1.0/72x72/1f4ac.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Question</strong>: What if a miner is not trustworthy and tries to change my transaction?</p> <ul> <li>Can the miner replace the receiver address with its own?</li> <li>Can the miner change the transaction amount?</li> <li>Can the miner change the sender address?</li> </ul> <p>The answer to all those questions is: No. Because if you want to issue a transaction, you need to broadcast the information </p> <p><code>(sender_public_key, receiver_public_key, amount)</code></p> <p>But here’s the trick: you sign the transaction using the private key of the sender:</p> <p><code>sender_private_key --> sign(sender_public_key, receiver_public_key, amount)</code></p> <p>Everybody knows the public key of the sender because it’s included in the transaction and therefore in the block. </p> <p><strong>Knowing the public key of the sender, anybody can verify that the whole transaction was signed by the owner of the private key.</strong></p> <p>If you changed one thing in the transaction (even by 1 SAT), the signature would not fit the transaction anymore and everybody would be able to know it!</p> <p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/13.1.0/72x72/1f4a1.png" alt="?" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>Info</strong>: With public-key cryptography, robust authentication is possible. A sender can combine a message with a private key to create a short <em>digital signature</em> on the message. Anyone with the sender’s corresponding public key can combine that message with a claimed digital signature. If the signature matches the message, the origin of the message is verified because it must have been made by the owner of the corresponding private key.<em> (Modified from <a rel="noreferrer noopener" href="https://en.wikipedia.org/wiki/Public-key_cryptography" data-type="URL" data-id="https://en.wikipedia.org/wiki/Public-key_cryptography" target="_blank">Wikipedia</a>)</em></p> <p>Now, what would happen if the miner would change any of the following information?</p> <ul> <li><code>sender_public_key, </code></li> <li><code>receiver_public_key, </code></li> <li><code>amount</code>,</li> </ul> <p>Well, the signature would not match the changed transaction, so there are two possibilities for a malicious miner: </p> <ul> <li>The miner would now have to include the original signature in the block which would not match the changed data. Any other miner would quickly see that the transaction is invalid and reject the block from the malicious miner. Remember: the assumption is that a majority of the mining power behaves properly in the Bitcoin protocol!</li> <li>The miner would have to calculate a new signature that fits to the changed transaction data. However, this is not possible as they don’t know the private key of the sender!</li> </ul> <p>The following video does a great job explaining these details in Bitcoin:</p> <figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"> <div class="wp-block-embed__wrapper"> <iframe loading="lazy" title="How Bitcoin Works Under the Hood" width="780" height="439" src="https://www.youtube.com/embed/Lx9zgZCMqXE?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> </div> </figure> <p>There are some details to it that I abstracted away. For example, miners do not actually check if a transaction is valid—that’s what full nodes are here for:</p> <hr class="wp-block-separator"/> <p><em>ALL full nodes verify all transactions in all blocks that they receive (as well as transactions received outside of blocks). Just because a block has a valid proof of work does not mean that the block is valid. It must still build upon a valid block and must only contain valid transactions. Full nodes still verify that transactions contained within a block are valid.</em></p> <p><em>Contrary to popular belief, miners do not say what transactions are valid. Their job is to determine the order of transactions, within certain constraints. It is the job of full nodes to verify transactions, and all miners (or the mining pools) should be running full nodes.</em></p> <p>(<a href="https://bitcoin.stackexchange.com/questions/72296/miner-modifies-unconfirmed-transactions-and-put-it-into-the-block" data-type="URL" data-id="https://bitcoin.stackexchange.com/questions/72296/miner-modifies-unconfirmed-transactions-and-put-it-into-the-block" target="_blank" rel="noreferrer noopener">StackOverflow</a>)</p> <hr class="wp-block-separator"/> </div> https://www.sickgaming.net/blog/2022/05/03/can-a-miner-change-a-bitcoin-transaction/ |