<p>That isn't allowed, even within a block. Here is the code that checks for that:</p>

<p>main.cpp: <a href="https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/main.cpp#L1695">ConnectBlock</a></p>

<pre><code>    if (!CheckInputs(tx, state, view, fScriptChecks, flags, false, nScriptCheckThreads ? &amp;vChecks : NULL))
        return error("ConnectBlock(): CheckInputs on %s failed with %s",
            tx.GetHash().ToString(), FormatStateMessage(state));
</code></pre>

<p>main.cpp: <a href="https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/main.cpp#L1361">CheckInputs</a></p>

<pre><code>if (!Consensus::CheckTxInputs(tx, state, inputs, GetSpendHeight(inputs)))
    return false;
</code></pre>

<p>main.cpp: <a href="https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/main.cpp#L1316">CheckTxInputs</a></p>

<pre><code>for (unsigned int i = 0; i &lt; tx.vin.size(); i++)
{
    const COutPoint &amp;prevout = tx.vin[i].prevout;
    const CCoins *coins = inputs.AccessCoins(prevout.hash);
    // [11 lines snipped]
    nValueIn += coins-&gt;vout[prevout.n].nValue;
    // [3 lines snipped]
}

if (nValueIn &lt; tx.GetValueOut())
    return state.DoS(100, false, REJECT_INVALID, "bad-txns-in-belowout", false,
        strprintf("value in (%s) &lt; value out (%s)", FormatMoney(nValueIn), FormatMoney(tx.GetValueOut())));
</code></pre>

CC BY-SA 3.0
2015-10-26T00:57:53.220Z
main.cpp : line 1346  and line 1352   why checking 2 times?
bitaps.com
CC BY-SA 3.0
2015-10-26T01:01:38.827Z
@bitaps Dunno. Why not, though?
Nick ODell
CC BY-SA 3.0
2015-10-26T00:43:25.837Z
2015-10-26T00:43:25.837Z
Nick ODell
<p>Transactions have 2 ways to get into blockchain in bitcoind:</p>

<ul>
<li><p>mempool -> newblock </p></li>
<li><p>newblock no in mempool</p></li>
</ul>

<p>lets check <strong>AcceptToMemoryPool</strong> function</p>

<p><a href="https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/main.cpp#L876" rel="nofollow">https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/main.cpp#L876</a></p>

<pre><code>CAmount nFees = nValueIn-nValueOut;
</code></pre>

<p>in case outs > ins </p>

<p>nFees&lt;0</p>

<pre><code>if (mempoolRejectFee &gt; 0 &amp;&amp; nFees &lt; mempoolRejectFee) {
        return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "mempool min fee not met", false, strprintf("%d &lt; %d", nFees, mempoolRejectFee));
</code></pre>

<p>negative nFees will be rejected all is good in this point</p>

<p>ok
lets check <strong>Connectblock</strong>  function</p>

<p><a href="https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/main.cpp#L1805" rel="nofollow">https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/main.cpp#L1805</a></p>

<p>for each tx in block we do:</p>

<pre><code>nFees += view.GetValueIn(tx)-tx.GetValueOut();
</code></pre>

<p><a href="https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/main.cpp#L1826" rel="nofollow">https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/main.cpp#L1826</a></p>

<pre><code> CAmount blockReward = nFees + GetBlockSubsidy(pindex-&gt;nHeight, chainparams.GetConsensus());
if (block.vtx[0].GetValueOut() &gt; blockReward)
    return state.DoS(100,
                     error("ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)",
                           block.vtx[0].GetValueOut(), blockReward),
                           REJECT_INVALID, "bad-cb-amount");
</code></pre>

<p>At this point we calculate max possible reward for this block: all tx fees + mining reward</p>

<p>then we check that coinbase reward not more then this value</p>

<p>what if same miner create and include transaction that have inputs for 1 btc and have outputs for 2 btc, so fee for this tx will be -1 btc</p>

<p>then miner can set reward for coinbase transaction to  25 btc  + all fees - 1 btc.  </p>

<p>so this (block.vtx[0].GetValueOut() > blockReward)  return True</p>

<p>as result we have Transaction, that  create more coins then received, inside blockchain</p>

<p>Where is my error?</p>

<transactions>
Transactions that have outputs value more then inputs value possible?
bitaps.com
# Transactions that have outputs value more then inputs value possible?

(Asked by: username_0 on 2015-10-26)

Transactions have 2 ways to get into blockchain in bitcoind:

* mempool -> newblock
* newblock no in mempool

lets check **AcceptToMemoryPool** function

<https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/main.cpp#L876>

```
CAmount nFees = nValueIn-nValueOut;

```

in case outs > ins

nFees<0

```
if (mempoolRejectFee > 0 && nFees < mempoolRejectFee) {
        return state.DoS(0, false, REJECT_INSUFFICIENTFEE, "mempool min fee not met", false, strprintf("%d < %d", nFees, mempoolRejectFee));

```

negative nFees will be rejected all is good in this point

ok
lets check **Connectblock** function

<https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/main.cpp#L1805>

for each tx in block we do:

```
nFees += view.GetValueIn(tx)-tx.GetValueOut();

```

<https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/main.cpp#L1826>

```
 CAmount blockReward = nFees + GetBlockSubsidy(pindex->nHeight, chainparams.GetConsensus());
if (block.vtx[0].GetValueOut() > blockReward)
    return state.DoS(100,
                     error("ConnectBlock(): coinbase pays too much (actual=%d vs limit=%d)",
                           block.vtx[0].GetValueOut(), blockReward),
                           REJECT_INVALID, "bad-cb-amount");

```

At this point we calculate max possible reward for this block: all tx fees + mining reward

then we check that coinbase reward not more then this value

what if same miner create and include transaction that have inputs for 1 btc and have outputs for 2 btc, so fee for this tx will be -1 btc

then miner can set reward for coinbase transaction to 25 btc + all fees - 1 btc.

so this (block.vtx[0].GetValueOut() > blockReward) return True

as result we have Transaction, that create more coins then received, inside blockchain

Where is my error?

**Tags:** transactions


---

## 1 answers

### Answer by username_1 on 2015-10-26. Score: 5 | Accepted answer

That isn't allowed, even within a block. Here is the code that checks for that:

main.cpp: [ConnectBlock](https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/main.cpp#L1695)

```
    if (!CheckInputs(tx, state, view, fScriptChecks, flags, false, nScriptCheckThreads ? &vChecks : NULL))
        return error("ConnectBlock(): CheckInputs on %s failed with %s",
            tx.GetHash().ToString(), FormatStateMessage(state));

```

main.cpp: [CheckInputs](https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/main.cpp#L1361)

```
if (!Consensus::CheckTxInputs(tx, state, inputs, GetSpendHeight(inputs)))
    return false;

```

main.cpp: [CheckTxInputs](https://github.com/bitcoin/bitcoin/blob/c719cefc417cc578f48b33069b764339a61054ce/src/main.cpp#L1316)

```
for (unsigned int i = 0; i < tx.vin.size(); i++)
{
    const COutPoint &prevout = tx.vin[i].prevout;
    const CCoins *coins = inputs.AccessCoins(prevout.hash);
    // [11 lines snipped]
    nValueIn += coins->vout[prevout.n].nValue;
    // [3 lines snipped]
}

if (nValueIn < tx.GetValueOut())
    return state.DoS(100, false, REJECT_INVALID, "bad-txns-in-belowout", false,
        strprintf("value in (%s) < value out (%s)", FormatMoney(nValueIn), FormatMoney(tx.GetValueOut())));

```

> **Comments:**
> **username_0**: main.cpp : line 1346  and line 1352   why checking 2 times?  
> **username_1**: @bitaps Dunno. Why not, though?  

---

