how does bitcoin solve the same chain replay attack? Let's say I send 10BTC to Bob. I have 30 BTC. So after transferring, I should have 20.
Now, after I transfered 10, transaction can be copied and broadcasted to the network again by Bob(he might have somehow get it from pool or something). Which means that replay attack has just taken place on the same chain(I know that replay attacks happen mostly when there's a hard fork, but in this case, I am talking about the same chain replay attacks).
Ethereum solves it by having nonce field in each account.
Question 1) How does bitcoin solve this case without SegWit ?
Question 2) how does bitcoin solve this case with SegWit ?
Question 3) If the replay attack happens for hard fork case, did bitcoin implement the solution or not ? I know that it was BTC cash that created a solution and btc said they wouldn't do it, but i am curious what's the state on this now ?
In all cases what you are describing is a double-spend. Bitcoin uses a UTXO model (not an account based model) which means that there is a set of coins also known as the UTXO set or Unspent Transaction Output set.
Transactions destroy coins and create new coins.
A new transaction attempting to spend a coin that has been destroyed is simply invalid.
Your concept of you and Bob &quot;having x BTC&quot; as a balance is incorrect for Bitcoin. What you have is a set of coins (a subset of the network-wide UTXO set) that you can destroy with a transaction by solving an output script. When you send 10 BTC to Bob what's really happening is you are taking one of your coins (lets say a coin with a 20 BTC value) and destroying it. Your transaction replaces it with two new coins, both for 10 BTC -- one secured by Bob's public key and the other secured by your own public key (this is your &quot;change&quot;).
Once that transaction is confirmed the original 20 BTC coin no longer exists. Sending the same transaction a second time would be invalid because it attempts to destroy coins that don't exist.