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
//! Block header validation (Orange Paper Section 5.3).
//!
//! Single place for header rules; easier to add BIP54 timewarp and version checks.
//!
//! ## Scope
//!
//! This module checks **structural / field** rules and **time** rules when a [`TimeContext`] is
//! supplied. **Proof-of-work** (hash vs compact target) is **not** validated here — use
//! [`crate::pow::check_proof_of_work`] / chain connection paths that combine PoW with context.
//!
//! ## Refactor / audit notes (coordinate with `blvm-spec-lock` before changing shape)
//!
//! - **Early returns** encode consensus rejects (`Ok(false)`). Do not duplicate the same condition
//! with `assert!` below — that only adds panic risk if someone reorders code.
//! - The tautological `assert!(result || !result)` (below) is **on purpose**: formal verification /
//! spec-lock tooling hooks here. Do not delete without verifier sign-off.
//! - **Version `0`** is rejected by `version < 1`.
//! - **Merkle root** is `[u8; 32]`; an extra length check would be redundant.
use crateResult;
use crate;
use spec_locked;
/// Validate block header fields and optional BIP113-style time rules.
///
/// Returns `Ok(true)` if all checks pass, `Ok(false)` if the header is invalid for these rules.
/// Does **not** run proof-of-work; see [`crate::pow::check_proof_of_work`].
///
/// # Arguments
///
/// * `header` - Block header to validate
/// * `time_context` - Optional time context for timestamp validation (BIP113)
/// If None, only basic timestamp checks are performed (non-zero).
/// If Some, full timestamp validation is performed:
/// - Rejects blocks with timestamps > network_time + MAX_FUTURE_BLOCK_TIME
/// - Rejects blocks with timestamps < median_time_past
// Intentional tautological assertions for formal verification
pub