You clearly have not read the bitcoin whitepaper. You are making a lot of guesses about how bitcoin works from things you have heard unknowledgeable people say, and many of your guesses are just wrong. This is leading you to a very invalid understanding of the system. Please throw out everything that you think you know about bitcoin and read the bitcoin whitepaper at least once before you try to understand how bitcoin works:
https://bitcoin.org/bitcoin.pdf1. How bitcoin wallet knows how much money I have?
There are many wallets. Exactly how it is accomplished depends on what wallet you are using. Generally though, your private keys and the associated address hash is stored by the wallet. The wallet maintains a list of unspent outputs from the blockchain that are associated with those addresses and adds them up.
: it count it on the basis of the bit coin chains or i just uses some variable to keep the info?
Like I said, it depends on the wallet you are choosing to use. Generally though, a wallet will add up the values of the unspent outputs and store this total in a variable so that it doesn't have to repeat the sum every time it wants to display the total.
2. If I understand it correctly, every time when I make a transaction, I also send my public key so that the others could verify that it's done by me?
There are several different types of transactions, but in the most common transaction type, yes the public key is sent. The key isn't sent so that others can verify that it's done by you. That verification is done with the signature which is computed from the private key. The public key is just sent to save some computing time so that the software doing the verifying doesn't need to compute the public key from the signature.
If yes, lets imagine the following situation:
Bob creates bit coin wallet and gets some bit coins.
Alice steals Bob's public key(which is not a secret) and simulates the bit coin message which says that Bob transfers Alice 1 bit coin. She uses Bob's public key to validate it.
Actually here we have 2 situation: a) when Bob's public key was already used in some of the transactions. b) he never used it before.
This is not possible. The public key is not used to validate the transaction, the signature is. It is only possible to create a valid signature with the private key. The private key is never included in any transactions, it is just used to calculate the signature.
3.
Verifycation whether a sender has the money:
Bob does not just confirms Alice's transaction. Instead he transfers her message to the whole network. The others check whether Alice has the money or not for this transaction. If positive, they send a message "Yes, Alice has the money". The transaction is complete when the necessary number of the members confirm this. And after that, everyones chain list will show that now Bob has 1 coin Alice transferred him.
No. This is not how bitcoin works at all. You should probably take some time to read the bitcoin whitepaper:
https://bitcoin.org/bitcoin.pdfAlice creates a transaction that specifies exactly which unspent outputs she is spending. Bob's software can check his own list of unspent outputs to verify that those outputs are actually unspent. In the transaction Alice includes a digital signature for every unspent output that she includes as an input. Each unspent output is encumbered with a requirement to supply a digital signature from a private key that is associated with a specific public key hash. Bob's software can confirm these signatures and know that Alice has met the requirement and therefore has the right to reassign the value associated with those unspent outputs to him by creating a new unspent output which is encumbered with a requirement to supply a signature from a private key that is associated with Bob's public key hash (also known as a Bitcoin Address). This allows Bob to verify the transaction without any assistance from anybody else.
Since it is possible that Alice might have sent another transaction that spends those exact same unspent outputs to somebody else, and Bob might not know about it, the system needs a distributed timestamp system that can determine which transaction happened "first". This is the purpose of mining. Miners perform a time consuming task, and when they complete that task successfully they get to broadcast a block of transactions that is linked to the previous block. If Bob sees Alice's transaction in that block, then he knows that miner saw that transaction "first" (before any other transaction that might try to spend the same unspent outputs). All miners that see that block will then ignore any other transaction that Alice tries to send spending the same unspent outputs.
a) What if we have 100K members or even 1 million, all of them have to verify each other's transaction?
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.
b) what it means "the necessary number of the members"? How many?
I don't know what you are asking. That's probably because you don't understand what you are asking about.
d)
You skipped "c"
When the others change the chain list on their PCs? : let's say Bob received a request to verify some transaction. Ok. Done. So should Bob immediately change the chain after that? What if Bob confirms and changes but John does not confirm?
No, if Bob is running a full node, then his software keeps a list of "unconfirmed" transactions. These are transactions that Bob's software has seen, but which a miner has not yet included in a block. His software also stores the blockchain (the list of every valid block that he has received so far). Bob's software immediately adds valid new transactions to his list of "unconfirmed" transactions as he receives them, and then removes the transactions from the list of "unconfirmed" transactions when he sees the transaction in a block.
e) What will happen if 50% of the fake members(the bots) would have their own chain list?
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.
f) Imagine that there is a million or even 100 millions of the bots and they send each other some extremely small amount of the bit coin. They do it without any purpose. So it means we get a kinda Dos attack?
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.
4
I understand that "enough number of the members" simply uses the following idea:
Anybody can confirm the transition only in the case if he resolves a "task". And for this job he gets 25bitcoins.
Again I'm not sure what you are talking about when you say "enough of the members".
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 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 David checks the list of his block chains and sees that transaction is correct. He wants to share the news over the network: the trans action is correct.
But before he does it, as a part of verification task, David must resolve some "task". Without it the others will not consider his confirmation.
Schematically we have a kinda box with unconfirmed transactions. And this box is locked with a key. So the task for David is to find this key to unlock the box and confirm the transactions.
That really isn't a very good way to look at it. You really, Really, REALLY should read the bitcoin whitepaper:
https://bitcoin.org/bitcoin.pdfDavid's software looks at the list of transactions that are not yet in any block that David's software knows about. David's softwware 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. Then David's software attempts to complete some provable work on that header. If David is able to complete the provable work before any other miner completes provable work on the block they are working on, then David gets to broadcast his completed block. If someone else completes a block first and David hears about it, then he starts all over again.
Thus, having the following questions:
a) how the others know whether David resolved the task or not?
The task is to calculate a hash that has a low enough value. The calculated hash is included in the header fo the block. Everybody that receives the block that David broadcasts can verify that it is the correct hash for the block and that the value is low enough. If it is not a correct hash for the block or if it is not low enough value, then David's block is rejected by everyone on the network.
b) as far as I understand, confirmation is nothing but mining! If so, then in the case if we have let's say only 10 members in the network and none of them mines, we will get the huge list of unconfirmed transactions and this confirmation job will never be done unless one of them will be convinced to start mining?
Correct. Confirmations will not occur unless there is at least one node that is "mining".
c) If so and only a miner can confirm the transactions, then in the case if Alice will confirm the fake transaction everyone will accept it?
Which fake transaction? If Alice sends 2 transactions that both spend the same previously unspent outputs, and neither of the transactions is confirmed yet, then the "real" transaction is whichever transaction is included in a block first, and the other transaction becomes invalid and disappears.
d) Imagine we have only 2 miners in the network. The first miner found the key first.Does it mean the second one will not get coins for his job?
Correct. Once one miner broadcasts a valid block, all miners will generally start all over working on a new block.
If so we have a situation that only a miner with the most powerful PC will always earn and consequently the other miners will eventually stop mining.
Having the most powerful PC does not guarantee that you will solve the block first. It simply increases your chances. It is impossible to know how many hashes it will take to solve a block that a miner is working on, and every miner is working on a different block with a different set of hashes. A very slow PC might successfully find a hash after computing the 5th hash on their block, while an extremely powerful PC might need to compute 100,000,000 hashes on their block before they successfully find one with a low enough value.
e) How the miner gets his reward for finding a key? I mean what is the source of this money? :
Is it sth like his mining app simply checks the condition: if result==key then balance+=25 coins?
If so then anybody can hack such the app.
No. As I've stated, the protocol allows every block to include exactly 1 transaction that has outputs, but which doesn't have an equivalent or greater value in inputs. The protocol requires that the outputs of this transaction be less than or equal to the sum of the current block subsidy and the transaction fees of all the transactions in the block. If the outputs are larger than that, then every other node on the system will reject the block as invalid and will refuse to accept it into their copy of the blockchain.
f) Who creates and locks the "box" of transactions and composes a key for the boxes?
There is not box, and there is no key. Every node on the system verifies that the block is valid before they accept it or relay it to anyone else.
g) Where does this box is located?
There is not "box"
As far as we are talking about a p2p network, there is no special place where we could keep the queue, etc.
Every peer on the network keeps their own list of unconfirmed transactions and their own copy of the blockchain.
Or maybe each wallet, on each PC, automatically creates a queue and automatically increments its number after the box is full?
There is no box. There is nothing to "fill".
Then how they synchronise the work
Each node accepts the first block that they receive. If they receive a block that does not belong to their chain, then they compare the total work for their chain to the total work of the chain with the new block and accept whichever chain has more total work.
and what if Alice hacked her app and it uses a weak key?
There is not 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.
5) In the case if our bin coin chain has a split, the others consider the one which is longer and this "road" is considered as a real one. We know that each chain has the id of the previous one and so on.
So what if Alice would generate a longer chain? In this case her chain will be considered as the correct one, no?
As long as her chain completed the appropriate proof of work? Then her chain would be accepted as the correct one. In Bitcoin when talking about "longest chain" what is really meant is the chain with the largest amount of valid proof of work.
6) Bitcoin can be decided into lots of the pieces.
Correct. The smallest integer unit of value within the protocol right now is equivalent to 0.00000001 BTC. It is not currently possible to transfer amounts smaller than this within the bitcoin protocol.
For example, let's say Alice has 1 bit coin and it's serial number is 123456
There are no serial numbers in the bitcoin protocol.
Now Alice sends 0.5 bit coin to Bob
Before this transaction, Bob already had 0.5 bit coin
Ok.
(presuming that even a part of bit coin has a serial number, the serial number of Bob's 0.5 bit coin was 98765)
There are no serial numbers in the bitcoin protocol.
So now Alice has 0.5 bit coin with a serial number 123456
And Bob has :
0.5 bit coin with serial number 98765 and 0.5 bit coin with a number 98765 ?
No. This is not how bitcoin works. There are no serial numbers in bitcoin.
So each member has to keep the huge number of the small pieces instead of merging them?
Pieces can be merged. Transactions have inputs (which supply value to the transaction from previously unspent outputs), and new unspent outputs. A transaction can have multiple inputs and a single output. This would combine multiple previously unspent outputs and would create a single new unspent output with the combined value of all the previously unspent outputs.