1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// ---------------- [ File: bitcoin-hash/src/assume.rs ]
crate::ix!();
pub struct AssumeUtxoHash {
base: BaseHash<u256>,
}
impl AssumeUtxoHash {
/// Construct a new [`AssumeUtxoHash`] from the supplied 256‑bit hash.
#[instrument(level = "debug", skip(hash))]
pub fn new(hash: &u256) -> Self {
Self {
base: BaseHash::new(hash),
}
}
}
/**
| Holds configuration for use during
| UTXO snapshot load and validation.
| The contents here are security critical,
| since they dictate which UTXO snapshots
| are recognized as valid.
|
*/
pub struct AssumeUtxoData {
/**
| The expected hash of the deserialized
| UTXO set.
|
*/
hash_serialized: AssumeUtxoHash,
/**
| Used to populate the nChainTx value, which
| is used during
| BlockManager::LoadBlockIndex().
|
| We need to hardcode the value here because
| this is computed cumulatively using block
| data, which we do not necessarily have at
| the time of snapshot load.
*/
n_chain_tx: u32,
}
pub type MapAssumeUtxo = HashMap<i32,AssumeUtxoData>;
// ---------------- [ File: bitcoin-hash/src/assume.rs ] (new test module)
#[cfg(test)]
mod assume_utxo_hash_spec {
use super::*;
/// Verify that constructing an [`AssumeUtxoHash`] succeeds
/// for a non‑zero and the zero hash alike.
#[traced_test]
fn construction_is_lossless() {
// GIVEN a zero 256‑bit hash
let zero_hash = u256::default();
// WHEN we construct an `AssumeUtxoHash`
let snapshot = AssumeUtxoHash::new(&zero_hash);
// THEN converting the inner `BaseHash` back to bytes must
// yield exactly 32 zeroed bytes.
let bytes: Vec<u8> = snapshot.base.clone().into();
assert_eq!(bytes, vec![0u8; 32]);
// …and the same must hold for a non‑zero hash.
let non_zero = u256::from(42);
let snapshot = AssumeUtxoHash::new(&non_zero);
let bytes: Vec<u8> = snapshot.base.into();
assert_ne!(bytes, vec![0u8; 32]);
}
}