<p>Any node (not just a miner) can check whether a transaction's inputs have been previously spent by looking through the entire blockchain to see if any transaction has spent that input. There is no correct or incorrect way to do this; not all nodes have to do this in the same way.</p>

<p>The common way to do this is to trust yourself (as a node) to have verified the blockchain correctly in the past. What Bitcoin Core (and other software that follow Bitcoin Core's methods) does is it maintains a separate database that contains all of the unspent transaction outputs. So if the previous outputs that a transaction's inputs references are not in this database, then the node declares the transaction invalid. It assumes that its database is correct because it built that database.</p>

<p>There is nothing that forces miners to do anything. A miner could create an invalid block that contains an invalid transaction (e.g. one that spends from a non-existent output). However all nodes (not just miners) verify that blocks and transactions are valid. So the Bitcoin network will reject any invalid blocks and thus the miner will not actually get his reward for his work. This incentivizes miners to verify block and transactions, but they aren't forced to.</p>

CC BY-SA 3.0
2018-04-06T22:28:38.947Z
2018-04-06T22:28:38.947Z
Ava Chow
<p>Maybe I have overlooked it, but I think the "Bitcoin Developer Reference" does not specify how a miner has to check whether or not transaction inputs have been previously spent.</p>

<p>How is it done? 
And espacially how is this enforced in the process?</p>

<p>All I found is 5.2 "process" 2.) in the 2016 paper.</p>

<p>I think, the miner has to look at every block after the "oldest" referenced transaction input and make sure no transaction in no block has the appropriate transaction as input. Is that true?</p>

<p>In that case, what enforces the miner to do so? </p>

<mining-theory><consensus>
How to: Check whether or not transaction inputs have been previously spent
Mark Neuhaus
# How to: Check whether or not transaction inputs have been previously spent

(Asked by: username_0 on 2018-04-06)

Maybe I have overlooked it, but I think the "Bitcoin Developer Reference" does not specify how a miner has to check whether or not transaction inputs have been previously spent.

How is it done?
And espacially how is this enforced in the process?

All I found is 5.2 "process" 2.) in the 2016 paper.

I think, the miner has to look at every block after the "oldest" referenced transaction input and make sure no transaction in no block has the appropriate transaction as input. Is that true?

In that case, what enforces the miner to do so?

**Tags:** mining-theory, consensus


---

## 1 answers

### Answer by username_1 on 2018-04-06. Score: 2 | Accepted answer

Any node (not just a miner) can check whether a transaction's inputs have been previously spent by looking through the entire blockchain to see if any transaction has spent that input. There is no correct or incorrect way to do this; not all nodes have to do this in the same way.

The common way to do this is to trust yourself (as a node) to have verified the blockchain correctly in the past. What Bitcoin Core (and other software that follow Bitcoin Core's methods) does is it maintains a separate database that contains all of the unspent transaction outputs. So if the previous outputs that a transaction's inputs references are not in this database, then the node declares the transaction invalid. It assumes that its database is correct because it built that database.

There is nothing that forces miners to do anything. A miner could create an invalid block that contains an invalid transaction (e.g. one that spends from a non-existent output). However all nodes (not just miners) verify that blocks and transactions are valid. So the Bitcoin network will reject any invalid blocks and thus the miner will not actually get his reward for his work. This incentivizes miners to verify block and transactions, but they aren't forced to.


---

