Author

Topic: Bitcoin double spend UTXO on same block (Read 617 times)

newbie
Activity: 7
Merit: 1
September 01, 2017, 11:22:59 AM
#6
Goood, thannnks , that sounds clear !
legendary
Activity: 3472
Merit: 4801
September 01, 2017, 10:38:16 AM
#5
All right, this means that UTXO database only hold unspent CONFIRMED txn output (doesnt hold the unconfirmed ones) , i.e: to build utxo db you need ony to parse already mined blockchain (not the last block that you are trying to mine)?

No.  The UTXO will contain all the unspent transaction outputs that the node believes is true.

It is not clear from what you've written whether or not you understand the following:

There is not an "official" UTXO list.  Every node builds its own UTXO which may be different from the UTXO on other nodes.  Each node makes its own decisions about what is valid based on what it has heard from its peers.

for the unconfirmed utxo they are held in another "db" whitch is the mempool.

The mempool stores valid unconfirmed TRANSACTIONS.  The UTXO stores valid UNSPENT OUTPUTS.

2) UTXO db : built from parsing the Blockchain db

UTXO built from processing transactions (both from the blockchain AND unconfirmed from peers)

3) mempool : holds realtime received txns

mempool holds real time UNCONFIRMED received transactions.

And to assemble a block to be mined , UTXOs are searched from memepool AND UTXO db

No.

UTXO is used to check the validity of transactions.

Mempool is used to share unconfirmed transactions.

Transactions which are added to the block are typically chosen from the mempool, but that is not a requirement.  A miner (or pool) can add ANY valid transaction to their block regardless of whether or not that transaction was ever in a mempool.
newbie
Activity: 7
Merit: 1
September 01, 2017, 09:15:55 AM
#4
All right, this means that UTXO database only hold unspent CONFIRMED txn output (doesnt hold the unconfirmed ones) , i.e: to build utxo db you need ony to parse already mined blockchain (not the last block that you are trying to mine)?

for the unconfirmed utxo they are held in another "db" whitch is the mempool.

So to resume , if i m right , there is 3 databases :
 1) Blockchain (contains blocks mined with all confirmed txns)

 2) UTXO db : built from parsing the Blockchain db

 3) mempool : holds realtime received txns

 And to assemble a block to be mined , UTXOs are searched from memepool AND UTXO db (or chainstate as it's called in bitcoin core)
legendary
Activity: 3472
Merit: 4801
September 01, 2017, 07:29:28 AM
#3
Can you guys tell me how double spending UTXO in the same block (currently being mined) is handeled in bitcoin core ?

It is rejected by all nodes on the network as an invalid block.  Nodes will not add the block to their blockchain. Nodes will not relay the block to peers.

The block will be abandoned, the valid transactions in the block will remain in the mempool of other nodes, and Alice will not be able to spend the block reward.
sr. member
Activity: 257
Merit: 343
September 01, 2017, 04:26:53 AM
#2
In short, rules are defined here:
https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages
say: "reject if we already have matching tx in the pool, or in a block in the main branch"

I didn't follow/verify all your example, but I think such a double spend would be detected in the mempool.
newbie
Activity: 7
Merit: 1
September 01, 2017, 01:53:16 AM
#1
Hi ,

Assuming this blockchain output result (starting from genesis block 0) "i m building bitcoin from scratch" :
Quote
Alice={
  "private_key": "4e5238c752e7274f7ddfc830ea08a51abd3eac65041d2bcbdc4aa605ef3558df",
  "public_key": "04692a6b64ee578d71560d60035fcf603411a6355371438f6af2a18a3acb4c9cfa9495657aad4bf 296935d4a5b09c13d3c0a9452b26c7c6d6b4f260f7c14cc7dfd",
  "public_key_hash": "f654d9b8a60961d5fde58049e1956d0e1b8b0fcf9c1ff9b3d72cb66b47b7d1f8"
}
Bob={
  "private_key": "7eea7f277e7a934b52fa69699ea17f79eb2d2383d9bc685013dcaba5187e357d",
  "public_key": "045c927042030e1a2d44590d81b6faf60fd39e4c9fee1b7d81cff3df314e2c1599aa7724c224ebd 24ad42252b22a13ad92b2d71ca5bbef8796e726ea86adab833e",
  "public_key_hash": "7f156e1b6b2be69577c2ddbcd5bd91b119d2a8da8bf5cade344f34995c7a536b"
}
Charlie={
  "private_key": "9331e7ad92abc7141de6b08721defd7ddcfb56fe62c0d990afde712392b869b0",
  "public_key": "04bee6e9b1445d99fbfa789c4f7015d911d3ac262ca4575ce9711fb482f5c4dc310e08d4833a620 7cd074ec87f899f495ba6d0a64e51a9ff36e70c41d302e70cde",
  "public_key_hash": "329612d65984fa0293210640d24867cfc2388eca6c0b91970e053ac4d4eae536"
}
-------------------------------------------------------
Block# 0 mined in: 171 ms
----UTXO DB --------
{
  "a58364ef3f15886f3601809b1b1821714b0cd6d75d3a5e123ff5a1c20b195b34---0": {
    "value": 50,
    "pubKeyHash": "f654d9b8a60961d5fde58049e1956d0e1b8b0fcf9c1ff9b3d72cb66b47b7d1f8"
  }
}
--------------------
Block# 1 mined in: 72 ms
----UTXO DB --------
{
  "a58364ef3f15886f3601809b1b1821714b0cd6d75d3a5e123ff5a1c20b195b34---0": null,
  "ed1b5fc60eadd9fc02d35f58631446b19ceff41965d7e83fa885060e20d29cbf---0": {
    "value": 96,
    "pubKeyHash": "f654d9b8a60961d5fde58049e1956d0e1b8b0fcf9c1ff9b3d72cb66b47b7d1f8"
  },
  "7fa2fe6c1cfedcba9c94889ff79f18459d90c6100c81c33f335c91026f1b856e---0": {
    "value": 30,
    "pubKeyHash": "7f156e1b6b2be69577c2ddbcd5bd91b119d2a8da8bf5cade344f34995c7a536b"
  },
  "7fa2fe6c1cfedcba9c94889ff79f18459d90c6100c81c33f335c91026f1b856e---1": {
    "value": 20,
    "pubKeyHash": "f654d9b8a60961d5fde58049e1956d0e1b8b0fcf9c1ff9b3d72cb66b47b7d1f8"
  },
  "f859c4c1cbf10bb3643e5fcbaedfea0a24b72927122fd7b5fcce1cd015a519db---0": {
    "value": 4,
    "pubKeyHash": "329612d65984fa0293210640d24867cfc2388eca6c0b91970e053ac4d4eae536"
  }
}
--------------------
{
  "chain": [
    {
      "index": 0,
      "timestamp": "01/01/2017",
      "data": [
        {
          "inps": [
            {
              "prevtxn_hash": "COINBASE_0",
              "index": 0,
              "scriptSig": {
                "sig": "dummy1",
                "pubKey": "dummy2"
              }
            }
          ],
          "outs": [
            {
              "value": 50,
              "pubKeyHash": "f654d9b8a60961d5fde58049e1956d0e1b8b0fcf9c1ff9b3d72cb66b47b7d1f8"
            }
          ],
          "hash": "a58364ef3f15886f3601809b1b1821714b0cd6d75d3a5e123ff5a1c20b195b34"
        }
      ],
      "previousHash": "0000000000000000000000000000000000000000000000000000000000000000",
      "nonce": 1060430016,
      "hash": "00055703d7aef669d2e4aa125a7cbcc03352842091cf716bd983777d7d44a9a7"
    },
    {
      "index": 1,
      "timestamp": "01/01/2017",
      "data": [
        {
          "inps": [
            {
              "prevtxn_hash": "COINBASE_1",
              "index": 0,
              "scriptSig": {
                "sig": "dummy1",
                "pubKey": "dummy2"
              }
            }
          ],
          "outs": [
            {
              "value": 96,
              "pubKeyHash": "f654d9b8a60961d5fde58049e1956d0e1b8b0fcf9c1ff9b3d72cb66b47b7d1f8"
            }
          ],
          "hash": "ed1b5fc60eadd9fc02d35f58631446b19ceff41965d7e83fa885060e20d29cbf"
        },
        {
          "inps": [
            {
              "prevtxn_hash": "a58364ef3f15886f3601809b1b1821714b0cd6d75d3a5e123ff5a1c20b195b34",
              "index": 0,
              "scriptSig": {
                "sig": "3044022021bd08b21e59331af21a7ef809106f0955b9cb3ae8e17547075d18f24f168eca02200c5 9fead771c0c996d9fa9785d867b5e6f60c255ef5096042fc5ce3df9e34108",
                "pubKey": "04692a6b64ee578d71560d60035fcf603411a6355371438f6af2a18a3acb4c9cfa9495657aad4bf 296935d4a5b09c13d3c0a9452b26c7c6d6b4f260f7c14cc7dfd"
              }
            }
          ],
          "outs": [
            {
              "value": 30,
              "pubKeyHash": "7f156e1b6b2be69577c2ddbcd5bd91b119d2a8da8bf5cade344f34995c7a536b"
            },
            {
              "value": 20,
              "pubKeyHash": "f654d9b8a60961d5fde58049e1956d0e1b8b0fcf9c1ff9b3d72cb66b47b7d1f8"
            }
          ],
          "hash": "7fa2fe6c1cfedcba9c94889ff79f18459d90c6100c81c33f335c91026f1b856e"
        },
        {
          "inps": [
            {
              "prevtxn_hash": "a58364ef3f15886f3601809b1b1821714b0cd6d75d3a5e123ff5a1c20b195b34",
              "index": 0,
              "scriptSig": {
                "sig": "304402207ded8626fa1a183db8fae4fc745ee5fefb5095932ee1f9e1606d402cb5b4a9d30220059 f0a538a9bfe36a34be21ef5b80b7fe9115b4b41d0ac257ec519461bdfb19e",
                "pubKey": "04692a6b64ee578d71560d60035fcf603411a6355371438f6af2a18a3acb4c9cfa9495657aad4bf 296935d4a5b09c13d3c0a9452b26c7c6d6b4f260f7c14cc7dfd"
              }
            }
          ],
          "outs": [
            {
              "value": 4,
              "pubKeyHash": "329612d65984fa0293210640d24867cfc2388eca6c0b91970e053ac4d4eae536"
            }
          ],
          "hash": "f859c4c1cbf10bb3643e5fcbaedfea0a24b72927122fd7b5fcce1cd015a519db"
        }
      ],
      "previousHash": "00055703d7aef669d2e4aa125a7cbcc03352842091cf716bd983777d7d44a9a7",
      "nonce": 3033275015,
      "hash": "0003352f6e897bb4544d489df8d2f9b8cb09170ca267e456180db291829cd8df"
    }
  ],
  "utxo_db": {
    "db": {
      "a58364ef3f15886f3601809b1b1821714b0cd6d75d3a5e123ff5a1c20b195b34---0": null,
      "ed1b5fc60eadd9fc02d35f58631446b19ceff41965d7e83fa885060e20d29cbf---0": {
        "value": 96,
        "pubKeyHash": "f654d9b8a60961d5fde58049e1956d0e1b8b0fcf9c1ff9b3d72cb66b47b7d1f8"
      },
      "7fa2fe6c1cfedcba9c94889ff79f18459d90c6100c81c33f335c91026f1b856e---0": {
        "value": 30,
        "pubKeyHash": "7f156e1b6b2be69577c2ddbcd5bd91b119d2a8da8bf5cade344f34995c7a536b"
      },
      "7fa2fe6c1cfedcba9c94889ff79f18459d90c6100c81c33f335c91026f1b856e---1": {
        "value": 20,
        "pubKeyHash": "f654d9b8a60961d5fde58049e1956d0e1b8b0fcf9c1ff9b3d72cb66b47b7d1f8"
      },
      "f859c4c1cbf10bb3643e5fcbaedfea0a24b72927122fd7b5fcce1cd015a519db---0": {
        "value": 4,
        "pubKeyHash": "329612d65984fa0293210640d24867cfc2388eca6c0b91970e053ac4d4eae536"
      }
    }
  }
}
------------------------------------
Balances:
alice:116
bob:30
charlie:4
====================================================================================

In the Block#0  pays alice 50 from coinbase (witch is the single txn in the block)
resulting a txn hash a58364ef3f15886f3601809b1b1821714b0cd6d75d3a5e123ff5a1c20b195b34 , redeemed to alice pubkeyhash f654d9b8a60961d5fde58049e1956d0e1b8b0fcf9c1ff9b3d72cb66b47b7d1f8
--> Mined correctly (by alice)

In the Block#1 :
  txn1 : alice sends 30 to bob and 20 back to her self using UTXO#0 (a58364ef3f15886f3601809b1b1821714b0cd6d75d3a5e123ff5a1c20b195b34 index:0) found in block#0
 
  txn2: : alice sends 4 to charlie  from SAME UTXO#0 (a58364ef3f15886f3601809b1b1821714b0cd6d75d3a5e123ff5a1c20b195b34 index:0) found in block#0  AND alice mine the block, resulting that the txn fees in txn2 = 50(in a58364ef3f...) - 4( to charlie) = 46 --> alice coinbase redemtion = 50+46=96

Can you guys tell me how double spending UTXO in the same block (currently being mined) is handeled in bitcoin core ?

Thanx


 





Jump to: