dig_block/validation/mod.rs
1//! Three-tier block validation pipeline ([SPEC §5, §7](docs/resources/SPEC.md)).
2//!
3//! ## Tiers
4//!
5//! | Tier | Module | SPEC | Requirements | External state | Chia crates used |
6//! |------|--------|------|-------------|----------------|-----------------|
7//! | 1 — Structural | [`structural`] | [§5](docs/resources/SPEC.md) | SVL-001 — SVL-006 | None | `chia-consensus::compute_merkle_set_root`, `chia-sdk-types::MerkleTree` |
8//! | 2 — Execution | [`execution`] | [§7.4](docs/resources/SPEC.md) | EXE-001 — EXE-009 | `clvmr::Allocator` | `dig-clvm::validate_spend_bundle` (wraps chia-consensus, chia-bls, clvmr) |
9//! | 3 — State | [`state`] | [§7.5](docs/resources/SPEC.md) | STV-001 — STV-007 | [`crate::CoinLookup`] | `chia-bls::verify` |
10//!
11//! ## Validation flow
12//!
13//! ```text
14//! L2Block
15//! │
16//! ├─► Tier 1: validate_structure() ← no external state; cheapest checks first
17//! │ ├── header version vs height (SVL-001)
18//! │ ├── DFSP roots pre-activation (SVL-002)
19//! │ ├── cost/size limits (SVL-003)
20//! │ ├── timestamp future bound (SVL-004)
21//! │ ├── count agreement (SVL-005)
22//! │ └── Merkle roots + integrity (SVL-006)
23//! │
24//! ├─► Tier 2: validate_execution() ← needs CLVM allocator
25//! │ ├── puzzle hash verification (EXE-002)
26//! │ ├── CLVM execution via dig-clvm (EXE-003)
27//! │ ├── condition parsing + assertion checking (EXE-004)
28//! │ ├── BLS signature verification (EXE-005)
29//! │ ├── conservation + fee consistency (EXE-006)
30//! │ ├── cost consistency (EXE-007)
31//! │ └── → ExecutionResult (EXE-008) with PendingAssertion (EXE-009)
32//! │
33//! └─► Tier 3: validate_state() ← needs CoinLookup
34//! ├── coin existence (STV-002)
35//! ├── puzzle hash cross-check (STV-003)
36//! ├── addition non-existence (STV-004)
37//! ├── height/time lock evaluation (STV-005)
38//! ├── proposer signature (STV-006)
39//! └── state root verification (STV-007)
40//! ```
41//!
42//! ## Composite method ([SPEC §10.3](docs/resources/SPEC.md))
43//!
44//! [`crate::L2Block::validate_full`] ([SPEC §7.1](docs/resources/SPEC.md), STV-001) chains all three
45//! tiers. If Tier 1 fails, Tiers 2 and 3 are never reached. If Tier 2 fails, Tier 3 is never reached.
46//! Returns the first error encountered or `Ok(computed_state_root)` on success.
47//!
48//! ## Chia parity ([SPEC §1.4](docs/resources/SPEC.md))
49//!
50//! The three-tier split mirrors Chia's validation in
51//! [`block_body_validation.py`](https://github.com/Chia-Network/chia-blockchain/blob/main/chia/consensus/block_body_validation.py):
52//! - Checks 1-14 ≈ Tier 1 (structural: counts, roots, duplicates, size — [SPEC §5.1–§5.2](docs/resources/SPEC.md))
53//! - Checks 15-22 ≈ Tier 2+3 (CLVM execution, coin existence, signatures, conservation — [SPEC §7.4–§7.5](docs/resources/SPEC.md))
54//!
55//! DIG separates execution (CLVM) from state (coin lookups) for cleaner testing and partial
56//! validation ([SPEC §1.1 Design Principle: Layered validation](docs/resources/SPEC.md)).
57
58pub mod execution;
59pub mod state;
60pub mod structural;