Skip to content

Commit 6c5884c

Browse files
committed
[BUG] Remove double counted nValueIn for zerocoin txes
Zerocoin spends values are already returned by GetValueIn below
1 parent 78a5da8 commit 6c5884c

File tree

4 files changed

+13
-25
lines changed

4 files changed

+13
-25
lines changed

src/coins.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,14 @@ CAmount CCoinsViewCache::GetValueIn(const CTransaction& tx) const
338338
if (tx.IsCoinBase())
339339
return 0;
340340

341-
//todo are there any security precautions to take here?
342-
if (tx.HasZerocoinSpendInputs())
343-
return tx.GetZerocoinSpent();
344-
345341
CAmount nResult = 0;
346-
for (unsigned int i = 0; i < tx.vin.size(); i++)
347-
nResult += AccessCoin(tx.vin[i].prevout).out.nValue;
342+
for (const CTxIn& in : tx.vin) {
343+
if (in.IsZerocoinSpend() || in.IsZerocoinPublicSpend()) {
344+
nResult += in.nSequence * COIN;
345+
} else {
346+
nResult += AccessCoin(in.prevout).out.nValue;
347+
}
348+
}
348349

349350
// Sapling
350351
nResult += tx.GetShieldedValueIn();

src/primitives/transaction.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,6 @@ CAmount CTransaction::GetShieldedValueIn() const
223223
return nValue;
224224
}
225225

226-
CAmount CTransaction::GetZerocoinSpent() const
227-
{
228-
CAmount nValueOut = 0;
229-
for (const CTxIn& txin : vin) {
230-
if(!txin.IsZerocoinSpend())
231-
continue;
232-
233-
nValueOut += txin.nSequence * COIN;
234-
}
235-
236-
return nValueOut;
237-
}
238-
239226
unsigned int CTransaction::GetTotalSize() const
240227
{
241228
return ::GetSerializeSize(*this, PROTOCOL_VERSION);

src/primitives/transaction.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,6 @@ class CTransaction
368368
return HasZerocoinSpendInputs() || HasZerocoinMintOutputs();
369369
}
370370

371-
CAmount GetZerocoinSpent() const;
372-
373371
bool IsCoinBase() const
374372
{
375373
return (vin.size() == 1 && vin[0].prevout.IsNull() && !vin[0].scriptSig.IsZerocoinSpend());

src/validation.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,6 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
15681568
return false; // Invalidity/DoS is handled by ParseAndValidateZerocoinSpends.
15691569
}
15701570
for (const CoinSpendValue& s : *opCoinSpendValues) {
1571-
nValueIn += s.value;
15721571
vSpends.emplace_back(s.serial, tx.GetHash());
15731572
}
15741573
} else if (!tx.IsCoinBase()) {
@@ -1592,10 +1591,12 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
15921591
// Cache the sig ser hashes
15931592
precomTxData.emplace_back(tx);
15941593

1594+
CAmount txValueOut = tx.GetValueOut();
15951595
if (!tx.IsCoinBase()) {
1596+
CAmount txValueIn = view.GetValueIn(tx);
15961597
if (!tx.IsCoinStake())
1597-
nFees += view.GetValueIn(tx) - tx.GetValueOut();
1598-
nValueIn += view.GetValueIn(tx);
1598+
nFees += txValueIn - txValueOut;
1599+
nValueIn += txValueIn;
15991600

16001601
std::vector<CScriptCheck> vChecks;
16011602
unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_DERSIG;
@@ -1607,7 +1608,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
16071608
return error("%s: Check inputs on %s failed with %s", __func__, tx.GetHash().ToString(), FormatStateMessage(state));
16081609
control.Add(vChecks);
16091610
}
1610-
nValueOut += tx.GetValueOut();
1611+
nValueOut += txValueOut;
16111612

16121613
CTxUndo undoDummy;
16131614
if (i > 0) {
@@ -1642,6 +1643,7 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
16421643
}
16431644

16441645
// track mint amount info
1646+
assert(nFees >= 0);
16451647
const int64_t nMint = (nValueOut - nValueIn) + nFees;
16461648

16471649
int64_t nTime1 = GetTimeMicros();

0 commit comments

Comments
 (0)