No. Only those that are running "full nodes" (which store and share the entire blockchain) have to verify every transaction. There are lightweight wallets that don't store the entire blockchain, and services that can provide wallets with an interface.
Let's imagine that every1 uses only "full" wallets. Does it mean that if the network includes 1million members, each of them has to verify the transactions of 999,999 members?
Yes.
Then they will have created their own alternative coin. Since their chain won't have completed enough work on the time consuming task, the rest of the network won't recognize their chain as being valid.
How do you know if their chain completed enough work on the task or not?
Bitcoin uses the SHA256 hash function to provide a proof of the work completed.
Since it is impossible to predict what the result of a SHA256 hash will be for a given input, the only way to find out is to do the actual work and compute the hash. The results are expected to be evenly distributed between 0 and 1.1579209 X 10
77. The amount of work that must be "proven" can be adjusted by setting a target value.
Think of this as an analogy:
You are given 1000 coins. You toss them all up in the air and when they land you look to see how many have landed with the heads side up. I can assign a "work" that says you have to repeat the process until you get less than 999 heads. Obviously this is pretty easy "work" and you will almost always succeed on your first attempt. I can now adjust the "difficulty" of the work by adjusting the number of heads you need to get. If I assign "work" that requires that you repeat the process until you get less than 400 heads, you'll probably be tossing those coins for a while. Now I can assign that same "work" difficulty (less than 400 heads) to a group of people. Some people will be able to repeat the process very fast, and some will be slower. The faster people will have a better chance of succeeding first since they will have more attempts, but the slower people can still get lucky and succeed with fewer attempts.
With Bitcoin, the "work" is to repeatedly modify the header of the block and calculate the SHA256 hash of that modified header until the hash value is less than a target that all full nodes and miners on the entire network have agreed on. The "difficulty" of the "work" can be adjusted by changing the target value. If the target isn't difficult enough, then blocks arrive too fast, and the target is made lower to force the participants to try longer. If the target is too difficult, then the blocks don't arrive fast enough, and the target is made higher to allow the participants to find a solution faster. By providing a header that hash a SHA256 hash value that is lower than the target, the miner proves that they did the "work" (they repeatedly modified the header and calculated the resulting hash until they found a low enough value).
I guess there is a time field in the block right?
There is, but it is just used to make sure that the blocks are coming at the right pace. Every 2016 blocks the difficulty is adjusted based on the amount of time it took for those 2016 blocks to be created. The time field in the block is not reliable since miners can lie about the time when they create the block. It is even possible for later blocks to have a time field that is earlier than the previous few blocks. The protocol requires that the time field be within a certain range of the most recent blocks to keep it from drifting too far from reality. If it is outside of the acceptable range then all peers will reject the block.
But what if they do in the following way:
each block has some property "previous_block_id", so schematically it looks sth like this:
1<--2<--3<--4
Imagine that block id number 4 is the latest one in the list. Then, they could simply manually create block with a property previous_block_id =4 and suggest this block to the others.
How can you recognise that this last block is invalid? If has a reference to the previous block which can be verified.
It has to meet various requirements to be accepted. A few of those conditions are:
- If you calculate the SHA256 hash of the block then it has to be less than the target value.
- It is only allowed to include valid transactions.
- The timestamp must be within a set range of the most recent previous blocks.
- The block reward cannot exceed the sum of the current subsidy plus the transaction fees of all the transactions in the block.
Yes. However, most nodes on the network will refuse to accept or relay a transaction with an extremely small amount of bitcoin unless the transaction also pays a transaction fee of at least 0.0001 BTC. That means the DDOS attack will cost the attacker 1 BTC for every 10,000 transactions that they send.
a) who gets the fee? Let's say Bob sends coins to Alice.
The miner that includes the transaction in a block and successfully completes the proof-of-work.
David is verifying their transaction. Will David get the fee?
It is important to understand that in bitcoin the words "verify" and "confirm" do NOT mean the same thing. Every full node peer on the network "verifies" every transaction. The only one that "confirms" the transaction is the miner (or mining pool) that first includes the transaction in a block where they have successfully completed the proof-of-work.
b) So the wallets have some kind of verification section: if (transaction_amount < 0.0001) refuse_transaction() ?
Yes. All peers have a verification process. If transactions don't meet necessary requirements then the transaction may not be accepted, relayed, or confirmed.
c) What happens to the refused transaction? Will Bob get some notification or he will wait in vain?
That depends on the reason for refusal. Most well written wallet software will protect a user from sending transactions that don't meet the well known conditions on the network. The wallet software would in that case refuse to even try to send the transaction and would report to Bob that he is attempting to send a problematic transaction. If Bob writes his own wallet software and doesn't check for the conditions, then his software would wait in vain.
d) If some reach person is in charge of the DDOS attack, so he can pay 1 BTC for 10K transaction, or if he uses the minimum amount of the BTC where no fees are charged, then BTC network could be stopped?
Even when sending transactions that are above the minimum amount, there are other fee conditions to make DDOS attacks expensive. If the attacker is willing to pay those fees, then yes they could theoretically create a situation where everyone else's transactions would take longer to confirm and they could potentially create a situation where peers are flooded with more transactions than they can handle in a short period of time. Of course doing so would cost them a LOT of bitcoins in fees which would be paid to the miners that are solving the blocks, so their attack would result in increased profits for the miners.
Speaking about the fees:
I understand that each transaction has a priority field: a transaction with lots of the money will be implemented first and transaction with small amount of the money will wait for its turn a lot of time, is it correct?
It is not a "field" it is a calculation that miners are encouraged to make when they are deciding which transactions to include in the blocks that they are mining. Miners are allowed to use any criteria that they like, but there are some "best practices" recommendations that most miners adhere to. You are correct though. To prevent a DDOS from someone that is sending amounts that are larger than the "required fee" minimum, miners are encouraged to give priority to transactions that are moving larger amounts of bitcoins and to give priority to transactions that spend bitcoins that were received longer ago.
And if every new block is created every 10 mins, does it mean that in order to implement transaction , a sender has to wait at least 10 mins?
No. A transaction can be sent immediately. It is then relayed as an "unconfirmed transaction" throughout the network immediately. The recipient is generally likely to receive the "unconfirmed transaction" within a few seconds. If the recipient wants to be confident that there isn't a competing transaction spending the same outputs elsewhere on the network that they haven't seen, then they should wait for a confirmation before providing whatever product or service they were exchanging for the bitcoins. However, due to the difficulty in propagating a "double-spend" unconfirmed transaction, there are many scenarios where the risk involved in treating the unconfirmed transaction as complete is acceptable. In most cases it is best to wait the average 10 minutes for the transaction to be confirmed before re-sending those same bitcoins elsewhere.
With mining though you are correct that the protocol requires the miner to prove that they have completed a time consuming task. Once they can provide this proof, they can broadcast the associated block of transactions.
In general terms it's clear but I'm trying to understand how it really works in the world full of hackers.
Bob "takes" a block he wants to "unlock".
There is no "unlocking". Bob creates a block by choosing which unconfirmed transactions he wants to "confirm". Then he generates a block header specific to that list of transactions. Then he starts repeatedly modifying that block header and calculating the resulting SHA256 hash of the block header until he finds a header that has a SHA256 hash with a value that is lower than the current target.
a) Bob does not see the transactions in the block? e.g. the transactions are maybe encrypted?
Bitcoin transactions are not encrypted. Bob does see the transactions in the block, since Bob chose which transactions to include.
b) Who is this person who gets the proof of Bob that the task was done?
All full node peers on the network. Every peer verifies for itself that Bob's block is valid and is the first valid block that they received for its position in the chain. Full node peers NEVER trust any other peer. They verify EVERY transaction and EVERY block that they receive before accepting it or relaying it to any other peers.
In the case if it's only Bob's mining application that works in the following way:
while(true)
{
...
if (check_key(suggested_key))
return suggested_key;
}
And nobody else checks Bob's solution, then Bob can easily modify his software. So I guess somebody checks his answer, right?
I'm not sure what you mean by "suggested_key", but as I've explained, EVERY full node peer checks EVERY block that they receive.
In exchange for this service, the miner gets to include a special transaction that pays him 25 BTC that didn't exist before the block as well as paying him all the transaction fees from all the transactions that are included in the block.
so Bob's mining software has some kinda flow:
Stamp_block(){
include_transactions_into_block();
include_25BTC_into_block_forMiner();
}
If this is the case, why Bob can't hack his software and request only include_25BTC_into_block_forMiner() ?
He can, but then he will miss out on all the transaction fees from all the transactions that paid fees. Other miners will get those fees instead in the next block after Bob's. This will result in lower revenue for Bob. Since mining is competitive, it tends to increase in costs until the costs for the most efficient miners are only slightly less than their revenues. As such, Bob will find that his reduced revenue results in his business operating at a loss. He will either need to:
- Continue operating at a loss until he is bankrupt.
- Start including transactions so that he can collect the transaction fees to improve profitability
- Quit mining
Correct. Confirmations will not occur unless there is at least one node that is "mining".
So eventually we will come to the point when it will not be profitable to mine. And consequently the network will stop?
unless somebody fully artificially will mine in order to keep the network working
If the least efficient miners stop mining (since they are no longer profitable) and no new miners enter the network, then blocks will occur more slowly. The network will then adjust the target difficulty to be lower. This will result in increased profitability for the remaining miners. Eventually the network will reach an equilibrium where the remaining miners are earning enough to continue mining.
David's software looks at the list of transactions that are not yet in any block that David's software knows about. David's software chooses which of these unconfirmed transactions it would like to confirm. It collects all the chosen unconfirmed transactions together into a block and computes a block header that is specific only to that exact list of transactions. It includes a special transaction that will pay David 25 BTC plus the sum of the transaction fees from all the chosen transactions.
a) There is a public queue with unconfirmed transactions.
All transactions are broadcast to all connected peers on the network. Those peers then relay the transaction to the peers they are connected to, and so on until nearly all peers on the network know about the transaction. Each peer keeps track of its own list of unconfirmed transactions.
How David works with these transactions: he only marks them that now he works on them or he removes them from the public queue?
No. All miners are allowed to simultaneously work on whatever unconfirmed transactions they want to. Typically many different miners are all working with the same group of unconfirmed transactions. Each miner can re-order those transactions however they like in their list as long as all of the inputs of each transaction occur earlier in the blockchain (or earlier in that block).
What if David marks/remove the transactions and then turns off his PC, what will happen next with the marked/removed transactions? They will be lost?
Peers do not generally remove a transaction from their list of unconfirmed transactions until they see the transaction in a block. The pool of unconfirmed transactions is limited in size though. Therefore, if a transaction is not confirmed yet after an extended time (typically a few days), then a peer will eventually drop the older unconfirmed transaction from its own list. The original sender of the transaction can either re-broadcast the transaction (which is what Bitcoin Core does), or they can drop the transaction from their own list which will result in those bitcoins once again being spendable in their wallet (which is what blockchain.info/wallet currently does).
b) I understand that each block of transactions has a reference to the previous block.
Correct.
So David and Alice are mining and both of them started "building" their blocks. They both know that the id of the last block is 5. What happens next? - they both create a new block with a reference to the block #5 ?
Yes.
Correct. Once one miner broadcasts a valid block, all miners will generally start all over working on a new block.
So, eventually we will come to the point where only some organization with the most powerful computers is able to confirm the transactions and earn on transactions.
Far more likely is that multiple competing organizations with powerful computers are confirming transactions. Only time will tell exactly how it will play out though.
Is it Federal Reserve System?
Not at all. There are a variety of very important differences. For example a Federal Reserve System is allowed to print as much money as they like whenever they like, while the bitcoin miners cannot create invalid blocks. Any competitor is allowed to start mining anytime they like. You can't just start up your own Federal Reserve System to compete with the existing one if you want.
Every peer on the network keeps their own list of unconfirmed transactions and their own copy of the blockchain.
These lists which each node has, are they equal?
I don't understand the question.
There is not a key. There is a proof of work that must be accomplished. If Alice does not complete the appropriate proof of work, then the rest of the network will ignore her invalid block.
But you said that miner creates a block, populates it with the transactions he wants to confirm and "locks" it with some hash and then starts searching for the answer for this hash.
No. He doesn't "lock" it with a hash, he repeatedly modifies the header and computes a new hash until he finds one that is lower than the target. Then he broadcasts the resulting block to all his connected peers.
So is it possible that Alice(miner) will create a very easy hash or the hash depends on the included transitions and consequently can not be "adjusted" by Alice?
Alice also must repeatedly modify the header of her block and calculate the hash until she finds a hash that has a value lower than the current target. Her block will be different than his, but there is no way to know who is going to stumble across a header with a low enough hash first.