Skip to content

Commit fa5668b

Browse files
author
MarcoFalke
committed
refactor: Use type-safe assumeutxo hash
This avoids accidentally mixing it up with other hashes (like block hashes).
1 parent 0000007 commit fa5668b

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

src/chainparams.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,11 @@ class CRegTestParams : public CChainParams {
451451
m_assumeutxo_data = MapAssumeutxo{
452452
{
453453
110,
454-
{uint256S("0x1ebbf5850204c0bdb15bf030f47c7fe91d45c44c712697e4509ba67adb01c618"), 110},
454+
{AssumeutxoHash{uint256S("0x1ebbf5850204c0bdb15bf030f47c7fe91d45c44c712697e4509ba67adb01c618")}, 110},
455455
},
456456
{
457457
210,
458-
{uint256S("0x9c5ed99ef98544b34f8920b6d1802f72ac28ae6e2bd2bd4c316ff10c230df3f2"), 210},
458+
{AssumeutxoHash{uint256S("0x9c5ed99ef98544b34f8920b6d1802f72ac28ae6e2bd2bd4c316ff10c230df3f2")}, 210},
459459
},
460460
};
461461

src/chainparams.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <consensus/params.h>
1111
#include <primitives/block.h>
1212
#include <protocol.h>
13+
#include <util/hash_type.h>
1314

1415
#include <memory>
1516
#include <vector>
@@ -25,14 +26,18 @@ struct CCheckpointData {
2526
}
2627
};
2728

29+
struct AssumeutxoHash : public BaseHash<uint256> {
30+
explicit AssumeutxoHash(const uint256& hash) : BaseHash(hash) {}
31+
};
32+
2833
/**
2934
* Holds configuration for use during UTXO snapshot load and validation. The contents
3035
* here are security critical, since they dictate which UTXO snapshots are recognized
3136
* as valid.
3237
*/
3338
struct AssumeutxoData {
3439
//! The expected hash of the deserialized UTXO set.
35-
const uint256 hash_serialized;
40+
const AssumeutxoHash hash_serialized;
3641

3742
//! Used to populate the nChainTx value, which is used during BlockManager::LoadBlockIndex().
3843
//!

src/test/validation_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ BOOST_AUTO_TEST_CASE(test_assumeutxo)
135135
}
136136

137137
const auto out110 = *ExpectedAssumeutxo(110, *params);
138-
BOOST_CHECK_EQUAL(out110.hash_serialized, uint256S("1ebbf5850204c0bdb15bf030f47c7fe91d45c44c712697e4509ba67adb01c618"));
138+
BOOST_CHECK_EQUAL(out110.hash_serialized.ToString(), "1ebbf5850204c0bdb15bf030f47c7fe91d45c44c712697e4509ba67adb01c618");
139139
BOOST_CHECK_EQUAL(out110.nChainTx, (unsigned int)110);
140140

141141
const auto out210 = *ExpectedAssumeutxo(210, *params);
142-
BOOST_CHECK_EQUAL(out210.hash_serialized, uint256S("9c5ed99ef98544b34f8920b6d1802f72ac28ae6e2bd2bd4c316ff10c230df3f2"));
142+
BOOST_CHECK_EQUAL(out210.hash_serialized.ToString(), "9c5ed99ef98544b34f8920b6d1802f72ac28ae6e2bd2bd4c316ff10c230df3f2");
143143
BOOST_CHECK_EQUAL(out210.nChainTx, (unsigned int)210);
144144
}
145145

src/validation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4939,7 +4939,7 @@ bool ChainstateManager::PopulateAndValidateSnapshot(
49394939

49404940
const AssumeutxoData& au_data = *maybe_au_data;
49414941

4942-
if (stats.hashSerialized != au_data.hash_serialized) {
4942+
if (AssumeutxoHash{stats.hashSerialized} != au_data.hash_serialized) {
49434943
LogPrintf("[snapshot] bad snapshot content hash: expected %s, got %s\n",
49444944
au_data.hash_serialized.ToString(), stats.hashSerialized.ToString());
49454945
return false;

0 commit comments

Comments
 (0)