Bitcoin Forum
November 11, 2024, 12:04:15 AM *
News: Latest Bitcoin Core release: 28.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Beginner's question on consensus.  (Read 105 times)
YYBNN (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 21


View Profile
June 03, 2021, 03:34:43 AM
Merited by Welsh (6), o_e_l_e_o (2), ABCbits (1)
 #1

Hi, I have a question regarding consensus. Perhaps it is  It’s related to the double spending problem. So, I will speak in this context.

Let’s say bitcoin network only has 5 nodes. Jon has 10 bitcoin, and trying to give 10 bitcoin to Mike and Lisa, intending the double spending.

Q1)So firstly, I wonder whether this action is even practical in usual circumstances, like having a hot wallet. When Jon sends 10 bitcoin to Mike, it should deduct 10 bitcoin from his hot wallet immediately. So, how could Jon even try to double spend? No bitcoin…(Now, if Jon is trying to go to a public ledger, and redo the block by adding or deleting particular transactions, I get it this type of activity leads to the double spending. For the longest chain, I understand 51% hash power is necessary to do so.)

In short, I understand that Jon can send Mike and Lisa 10 bitcoin each at the very same time to do double spending, but is it even possible in a hot wallet situation (which I think is a usual circumstance for many people).

Q2)In any case, if Jon tries to send bitcoin, other four will check if this transaction is valid or not. Exactly, are they checking if Jon has enough founds by going back to the public ledger, and Jon is not doing the double spending also by going back to the public ledger? I suppose the answer is yes, but here I am starting to get confused because this is the point which PoW is coming in as two of four nodes could be Jon's, and they might lie. In my understanding, PoW plays a role to choose a representative who puts a block. I understand that it is a hashing race to get a certain value where inputs are all transactions to be included in a block, the past information from the previous block, and a nonce which you choose to get an ideal output. Hence, anyone who is participating to this hash race already knows which transactions they should include into the block. So, there should be a consensus before PoW that would check which transactions to be included?

Sorry it was a bit long and perhaps basic to some of you all, but if you could help me to clarify, that would be great.
ranochigo
Legendary
*
Offline Offline

Activity: 3038
Merit: 4420


Crypto Swap Exchange


View Profile
June 03, 2021, 03:52:58 AM
Merited by ABCbits (2), o_e_l_e_o (2), Pmalek (1), BlackHatCoiner (1)
 #2

Q1)So firstly, I wonder whether this action is even practical in usual circumstances, like having a hot wallet. When Jon sends 10 bitcoin to Mike, it should deduct 10 bitcoin from his hot wallet immediately. So, how could Jon even try to double spend? No bitcoin…(Now, if Jon is trying to go to a public ledger, and redo the block by adding or deleting particular transactions, I get it this type of activity leads to the double spending. For the longest chain, I understand 51% hash power is necessary to do so.)

In short, I understand that Jon can send Mike and Lisa 10 bitcoin each at the very same time to do double spending, but is it even possible in a hot wallet situation (which I think is a usual circumstance for many people).
Your wallet probably won't allow you to make another transaction that spends an input that has already been spent. However, there is nothing stopping you from constructing the transaction and pushing it yourself.

When a node receives a transaction, it'll get validated and the node will remove the UTXO involved from their UTXO set. This means that every other transaction that spends the same UTXO will be invalid to the node as the node has already removed it. However, if you were to broadcast the transaction to two half of the network, then assuming equal propagation, each half will see different transactions. This is known as a race attack, where in a scenario that a merchant sees TX A but infact TX B with the same inputs and sent back to a different address is also propagated on the network. In this case, then whichever transaction that gets included in a block first wins. The premise of 51% attack or any of that sort usually will have the attacker building a chain alongside the honest network.

For example, if the transaction gets included at block height of 2, then the attacker will start mining at a block height of 2 with a rogue transaction until they outpace the network. Afterwhich, they broadcast that chain and they're able to effectively overwrite the other chain as it has a higher PoW.
Q2)In any case, if Jon tries to send bitcoin, other four will check if this transaction is valid or not. Exactly, are they checking if Jon has enough founds by going back to the public ledger, and Jon is not doing the double spending also by going back to the public ledger? I suppose the answer is yes, but here I am starting to get confused because this is the point which PoW is coming in as two of four nodes could be Jon's, and they might lie. In my understanding, PoW plays a role to choose a representative who puts a block. I understand that it is a hashing race to get a certain value where inputs are all transactions to be included in a block, the past information from the previous block, and a nonce which you choose to get an ideal output. Hence, anyone who is participating to this hash race already knows which transactions they should include into the block. So, there should be a consensus before PoW that would check which transactions to be included?
When a transaction gets broadcasted, it stays in a memory pool of nodes before it gets mined into a block. This state is different from each and every node; if you were to push two conflicting transactions equally to two nodes, they would perceive the state differently with them regarding the first transaction received as valid while not accepting the other transaction into their mempool. As a result, there is no consensus here at this stage.

Don't think of Bitcoins as an account but rather each transaction spending a specific UTXO (unspent transaction output) which gets used and created in the transaction. The concept of PoW gives whoever having the larger hashrate the liberty to choose and include either transactions, the number of nodes the attacker hold is irrelevant. As long as Jon is able to create a block that includes the transaction that he desires, then that transaction will be included in the longest chain.

Since no consensus is involved before the transaction is included in a block, then accepting a transaction with zero confirmation is riskier. PoW defeats double spending by achieving a consensus whereby each unique UTXO can only be spent once and once only in the same chain and an agreement by the nodes agreeing on the chain with the longest valid PoW.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
NotATether
Legendary
*
Offline Offline

Activity: 1778
Merit: 7372


Top Crypto Casino


View Profile WWW
June 03, 2021, 05:34:06 AM
 #3

Calling it "double spending" is a misnomer because the bitcoins are not actually spent twice, they are taken from Mike and given to Lisa (for example), so if Jon were to pay Mike 10BTC and then use double spending to pay Lisa 10BTC then she will actually be receiving Mike's payment because it can be replaced on the blockchain - and all nodes will pick up the change - with another transaction to a different destination as long as it is still unconfirmed.

███████████████████████
████▐██▄█████████████████
████▐██████▄▄▄███████████
████▐████▄█████▄▄████████
████▐█████▀▀▀▀▀███▄██████
████▐███▀████████████████
████▐█████████▄█████▌████
████▐██▌█████▀██████▌████
████▐██████████▀████▌████
█████▀███▄█████▄███▀█████
███████▀█████████▀███████
██████████▀███▀██████████

███████████████████████
.
BC.GAME
▄▄▀▀▀▀▀▀▀▄▄
▄▀▀░▄██▀░▀██▄░▀▀▄
▄▀░▐▀▄░▀░░▀░░▀░▄▀▌░▀▄
▄▀▄█▐░▀▄▀▀▀▀▀▄▀░▌█▄▀▄
▄▀░▀░░█░▄███████▄░█░░▀░▀▄
█░█░▀░█████████████░▀░█░█
█░██░▀█▀▀█▄▄█▀▀█▀░██░█
█░█▀██░█▀▀██▀▀█░██▀█░█
▀▄▀██░░░▀▀▄▌▐▄▀▀░░░██▀▄▀
▀▄▀██░░▄░▀▄█▄▀░▄░░██▀▄▀
▀▄░▀█░▄▄▄░▀░▄▄▄░█▀░▄▀
▀▄▄▀▀███▄███▀▀▄▄▀
██████▄▄▄▄▄▄▄██████
.
..CASINO....SPORTS....RACING..


▄▄████▄▄
▄███▀▀███▄
██████████
▀███▄░▄██▀
▄▄████▄▄░▀█▀▄██▀▄▄████▄▄
▄███▀▀▀████▄▄██▀▄███▀▀███▄
███████▄▄▀▀████▄▄▀▀███████
▀███▄▄███▀░░░▀▀████▄▄▄███▀
▀▀████▀▀████████▀▀████▀▀
YYBNN (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 21


View Profile
June 03, 2021, 06:49:37 AM
 #4

@ranochigo

Thank you so much for your clear explanation and more knowledge, I lam learning a lot here.

<About Q1>
"When a node receives a transaction, it'll get validated and the node will remove the UTXO involved from their UTXO set. This means that every other transaction that spends the same UTXO will be invalid to the node as the node has already removed it. However, if you were to broadcast the transaction to two half of the network, then assuming equal propagation, each half will see different transactions. This is known as a race attack, where in a scenario that a merchant sees TX A but infact TX B with the same inputs and sent back to a different address is also propagated on the network. In this case, then whichever transaction that gets included in a block first wins."

I see, I understand this. I did not know the race attack, but this could certainly happen, but you can avoid by "whichever transaction that gets included in a block first wins."

Bit away from my original question. When you say "When a node receives a transaction, it'll get validated", this is to check if this transaction was not in anywhere of the block chain at that stage, I suppose. I am learning about SPV and learned that with merkle tree data structure and only block headers, it is easy to check if the transaction is contained in previous blocks.(https://learning.edx.org/course/course-v1:BerkeleyX+CS198.1x+3T2019/block-v1:BerkeleyX+CS198.1x+3T2019+type@sequential+block@f37bbffc45a84deabf346911b8d83178/block-v1:BerkeleyX+CS198.1x+3T2019+type@vertical+block@4fe65dfbf03e4cb48ef588b85af9e107) I believe each node validates in this way, am I right? Current block height is less than 700000, I guess this validation is computationally light.


"For example, if the transaction gets included at block height of 2, then the attacker will start mining at a block height of 2 with a rogue transaction until they outpace the network. Afterwhich, they broadcast that chain and they're able to effectively overwrite the other chain as it has a higher PoW."

I get this. Thank you. Just out of curiosity, if the longest chain gets hacked by 51% attack, what happened to the block rewards of miners who did the longest chain? I suppose it becomes zero, perhaps there is a code which executes at this event. And, I guess all transactions which were in the longest chain get put back to memory pool?

<About Q2>
Thank you, it is clear now. Again out of curiosity, little different topic, I know there is an upper bound in the size of blocks, hence, one can contain finitely many transactions. Is there any lower bound like you have to include at least k transactions from some k? I suppose, for hashing, it does not get better having less transactions. I heard also that miners get transaction fees besides of block rewards, so it is natural to put as much as transactions if the number of inputs transactions does not matter in the hashing race, which I think is the case.
ranochigo
Legendary
*
Offline Offline

Activity: 3038
Merit: 4420


Crypto Swap Exchange


View Profile
June 03, 2021, 08:15:03 AM
 #5

Bit away from my original question. When you say "When a node receives a transaction, it'll get validated", this is to check if this transaction was not in anywhere of the block chain at that stage, I suppose. I am learning about SPV and learned that with merkle tree data structure and only block headers, it is easy to check if the transaction is contained in previous blocks.(https://learning.edx.org/course/course-v1:BerkeleyX+CS198.1x+3T2019/block-v1:BerkeleyX+CS198.1x+3T2019+type@sequential+block@f37bbffc45a84deabf346911b8d83178/block-v1:BerkeleyX+CS198.1x+3T2019+type@vertical+block@4fe65dfbf03e4cb48ef588b85af9e107) I believe each node validates in this way, am I right? Current block height is less than 700000, I guess this validation is computationally light.
The reference client (Bitcoin Core) will validate the transaction to check whether it violates any of its policy, validity of signature, fees, UTXO existence etc. Reference client builds their own chainstate which contains the UTXO and they don't need to use merkle proof to verify if the UTXOs being spent are in the chain.

I get this. Thank you. Just out of curiosity, if the longest chain gets hacked by 51% attack, what happened to the block rewards of miners who did the longest chain? I suppose it becomes zero, perhaps there is a code which executes at this event. And, I guess all transactions which were in the longest chain get put back to memory pool?
If a chain gets reorganized by a rogue chain, then the block rewards of those in the replaced chain would disappear, it would be as if they've never existed. They have been replaced by the rogue chain.

Yes, transactions are returned to the mempool provided that they stay valid, none of the UTXOs were spent in another transaction in the rogue chain. Reorgs are not that uncommon, stale blocks occur once in a while.

Thank you, it is clear now. Again out of curiosity, little different topic, I know there is an upper bound in the size of blocks, hence, one can contain finitely many transactions. Is there any lower bound like you have to include at least k transactions from some k? I suppose, for hashing, it does not get better having less transactions. I heard also that miners get transaction fees besides of block rewards, so it is natural to put as much as transactions if the number of inputs transactions does not matter in the hashing race, which I think is the case.
You need to include at least one transaction, the coinbase transaction. That can contain your block rewards, witness commitment, etc.

But yes, the number of transactions doesn't affect your hashing speed.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
YYBNN (OP)
Newbie
*
Offline Offline

Activity: 7
Merit: 21


View Profile
June 03, 2021, 09:45:04 AM
 #6

Thank you, learned a great deal!
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!