mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
coinstats: Fix hash_serialized2 calculation
The legacy serialization was vulnerable to maleation and is fixed by adopting the same serialization procedure as was already in use for MuHash. This also includes necessary test fixes where the hash_serialized2 was hardcoded as well as correction of the regtest chainparams. Co-authored-by: Sebastian Falbesoner <sebastian.falbesoner@gmail.com>
This commit is contained in:
@@ -15,9 +15,10 @@
|
||||
#include <undo.h>
|
||||
#include <validation.h>
|
||||
|
||||
using kernel::ApplyCoinHash;
|
||||
using kernel::CCoinsStats;
|
||||
using kernel::GetBogoSize;
|
||||
using kernel::TxOutSer;
|
||||
using kernel::RemoveCoinHash;
|
||||
|
||||
static constexpr uint8_t DB_BLOCK_HASH{'s'};
|
||||
static constexpr uint8_t DB_BLOCK_HEIGHT{'t'};
|
||||
@@ -166,7 +167,7 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block)
|
||||
continue;
|
||||
}
|
||||
|
||||
m_muhash.Insert(MakeUCharSpan(TxOutSer(outpoint, coin)));
|
||||
ApplyCoinHash(m_muhash, outpoint, coin);
|
||||
|
||||
if (tx->IsCoinBase()) {
|
||||
m_total_coinbase_amount += coin.out.nValue;
|
||||
@@ -187,7 +188,7 @@ bool CoinStatsIndex::CustomAppend(const interfaces::BlockInfo& block)
|
||||
Coin coin{tx_undo.vprevout[j]};
|
||||
COutPoint outpoint{tx->vin[j].prevout.hash, tx->vin[j].prevout.n};
|
||||
|
||||
m_muhash.Remove(MakeUCharSpan(TxOutSer(outpoint, coin)));
|
||||
RemoveCoinHash(m_muhash, outpoint, coin);
|
||||
|
||||
m_total_prevout_spent_amount += coin.out.nValue;
|
||||
|
||||
@@ -443,7 +444,7 @@ bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex
|
||||
continue;
|
||||
}
|
||||
|
||||
m_muhash.Remove(MakeUCharSpan(TxOutSer(outpoint, coin)));
|
||||
RemoveCoinHash(m_muhash, outpoint, coin);
|
||||
|
||||
if (tx->IsCoinBase()) {
|
||||
m_total_coinbase_amount -= coin.out.nValue;
|
||||
@@ -464,7 +465,7 @@ bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex
|
||||
Coin coin{tx_undo.vprevout[j]};
|
||||
COutPoint outpoint{tx->vin[j].prevout.hash, tx->vin[j].prevout.n};
|
||||
|
||||
m_muhash.Insert(MakeUCharSpan(TxOutSer(outpoint, coin)));
|
||||
ApplyCoinHash(m_muhash, outpoint, coin);
|
||||
|
||||
m_total_prevout_spent_amount -= coin.out.nValue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user