dig-block 0.1.0

DIG L2 block format, production, and validation
Documentation
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
[package]
name = "dig-block"
version = "0.1.0"
edition = "2021"
rust-version = "1.75.0"
description = "DIG L2 block format, production, and validation"
license = "MIT"
authors = ["DIG Network"]
repository = "https://github.com/DIG-Network/dig-block"
readme = "README.md"
keywords = ["blockchain", "l2", "chia", "clvm", "dig"]
categories = ["cryptography::cryptocurrencies"]
# Only explicit `[[test]]` targets run as integration tests; `tests/common.rs` is a submodule (not its own crate).
autotests = false

[lib]
path = "src/lib.rs"

[dependencies]
# Chia protocol & consensus
chia-protocol = "0.26"
chia-bls = "0.26"
chia-consensus = "0.26"
chia-sha2 = "0.26"
chia-traits = "0.26"
# SER-003 / gossip: `Streamable` derive for [`L2Block`] / [`L2BlockHeader`] wire encoding (dig-blockstore).
chia_streamable_macro = "0.26"
clvm-utils = "0.26"
clvmr = "0.14"

# Chia SDK
chia-sdk-types = "0.30"
chia-sdk-signer = "0.30"

# DIG ecosystem
dig-clvm = "0.1"

# Serialization
bincode = "1"
serde = { version = "1", features = ["derive"] }

# Merkle / BIP158 (BLK-004): Bitcoin-compatible GCS filter writer, ordered puzzle_hash groups
bitcoin = { version = "0.32", default-features = false, features = ["std"] }
indexmap = "2"

# Error handling
thiserror = "2"

[dev-dependencies]
bincode = "1"
bitcoin = { version = "0.32", default-features = false, features = ["std"] }
chia-sha2 = "0.26"
clvmr = "0.14"
hex = "0.4.3"
hex-literal = "0.4"
# SER-001: JSON size probe only (wire remains bincode per NORMATIVE).
serde_json = "1"
# SER-005: property-based round-trip testing.
proptest = "1"

# BLK-005: dedicated integration test crate (flat `tests/` path; see spec test plan).
[[test]]
name = "blk_005_protocol_constants"
path = "tests/test_protocol_constants.rs"

# BLK-006: primitive types & re-exports.
[[test]]
name = "blk_006_primitive_types"
path = "tests/test_primitive_types.rs"

# BLK-001: L2BlockHeader struct & derives.
[[test]]
name = "blk_001_l2_block_header_struct"
path = "tests/test_l2_block_header_struct.rs"

# BLK-002: L2BlockHeader constructors.
[[test]]
name = "blk_002_l2_block_header_constructors"
path = "tests/test_l2_block_header_constructors.rs"

# BLK-007: version auto-detection.
[[test]]
name = "blk_007_version_auto_detection"
path = "tests/test_version_auto_detection.rs"

# BLK-003: L2Block struct (header + body + signature).
[[test]]
name = "blk_003_l2_block_struct"
path = "tests/test_l2_block_struct.rs"

# BLK-004: L2Block helper methods (Merkle roots, filter, integrity).
[[test]]
name = "blk_004_l2_block_helpers"
path = "tests/test_l2_block_helpers.rs"

# ATT-003: BlockStatus enum and predicates.
[[test]]
name = "att_003_block_status"
path = "tests/test_block_status.rs"

# ATT-004: SignerBitmap core methods.
[[test]]
name = "att_004_signer_bitmap_core"
path = "tests/test_signer_bitmap_core.rs"

# ATT-005: SignerBitmap merge and signer_indices.
[[test]]
name = "att_005_signer_bitmap_merge"
path = "tests/test_signer_bitmap_merge.rs"

# ATT-001: AttestedBlock struct and constructor.
[[test]]
name = "att_001_attested_block_constructor"
path = "tests/test_attested_block_constructor.rs"

# ATT-002: AttestedBlock methods (signing_percentage, has_soft_finality, hash).
[[test]]
name = "att_002_attested_block_methods"
path = "tests/test_attested_block_methods.rs"

# RCP-001: ReceiptStatus enum (repr u8, discriminants).
[[test]]
name = "rcp_001_receipt_status"
path = "tests/test_receipt_status.rs"

# RCP-002: Receipt struct (seven fields).
[[test]]
name = "rcp_002_receipt_struct"
path = "tests/test_receipt_struct.rs"

# RCP-003: ReceiptList methods and Merkle root.
[[test]]
name = "rcp_003_receipt_list_methods"
path = "tests/test_receipt_list_methods.rs"

# RCP-004: ReceiptList aggregate methods.
[[test]]
name = "rcp_004_receipt_list_aggregates"
path = "tests/test_receipt_list_aggregates.rs"

# CKP-003: CheckpointStatus enum (epoch lifecycle).
[[test]]
name = "ckp_003_checkpoint_status"
path = "tests/test_checkpoint_status.rs"

# CKP-001: Checkpoint struct and new().
[[test]]
name = "ckp_001_checkpoint_struct"
path = "tests/test_checkpoint_struct.rs"

# CKP-002: CheckpointSubmission struct and new().
[[test]]
name = "ckp_002_checkpoint_submission_struct"
path = "tests/test_checkpoint_submission_struct.rs"

# CKP-004: Checkpoint::compute_score.
[[test]]
name = "ckp_004_checkpoint_score"
path = "tests/test_checkpoint_score.rs"

# CKP-005: CheckpointSubmission methods (hash, epoch, threshold, L1 record).
[[test]]
name = "ckp_005_checkpoint_submission_methods"
path = "tests/test_checkpoint_submission_methods.rs"

# CKP-006: CheckpointBuilder (epoch summary accumulation + Merkle roots).
[[test]]
name = "ckp_006_checkpoint_builder"
path = "tests/test_checkpoint_builder.rs"

# ERR-001: BlockError structural (Tier 1) variants.
[[test]]
name = "err_001_block_error_structural"
path = "tests/test_block_error_structural.rs"

# ERR-002: BlockError execution (Tier 2) and state (Tier 3) variants.
[[test]]
name = "err_002_block_error_execution_state"
path = "tests/test_block_error_execution_state.rs"

# ERR-003: CheckpointError enum.
[[test]]
name = "err_003_checkpoint_error"
path = "tests/test_checkpoint_error.rs"

# ERR-004: BuilderError enum.
[[test]]
name = "err_004_builder_error"
path = "tests/test_builder_error.rs"

# ERR-005: SignerBitmapError enum.
[[test]]
name = "err_005_signer_bitmap_error"
path = "tests/test_signer_bitmap_error.rs"

# ERR-005: ReceiptError enum.
[[test]]
name = "err_005_receipt_error"
path = "tests/test_receipt_error.rs"

# HSH-007: tagged Merkle hashing (0x01 leaf, 0x02 node) vs chia-sdk-types MerkleTree.
[[test]]
name = "hsh_007_tagged_merkle"
path = "tests/test_hsh_007_tagged_merkle.rs"

# HSH-001: L2BlockHeader hash (SHA-256 over SPEC §3.1 preimage).
[[test]]
name = "hsh_001_block_header_hash"
path = "tests/test_hsh_001_block_header_hash.rs"

# HSH-002: Checkpoint hash (SHA-256 over SPEC §3.2 preimage).
[[test]]
name = "hsh_002_checkpoint_hash"
path = "tests/test_hsh_002_checkpoint_hash.rs"

# HSH-003: spends_root — MerkleTree over SHA-256(serialized SpendBundle) leaves in order.
[[test]]
name = "hsh_003_spends_root"
path = "tests/test_hsh_003_spends_root.rs"

# HSH-004: additions_root — Merkle set over puzzle_hash groups + hash_coin_ids (chia-consensus).
[[test]]
name = "hsh_004_additions_root"
path = "tests/test_hsh_004_additions_root.rs"

# HSH-005: removals_root — Merkle set over removal coin IDs (chia-consensus).
[[test]]
name = "hsh_005_removals_root"
path = "tests/test_hsh_005_removals_root.rs"

# HSH-006: filter_hash — SHA-256(BIP-158 GCS over addition puzzle_hashes + removal coin_ids).
[[test]]
name = "hsh_006_filter_hash"
path = "tests/test_hsh_006_filter_hash.rs"

# HSH-008: receipts_root — MerkleTree over SHA-256(bincode(Receipt)) leaves (ReceiptList uses same fn).
[[test]]
name = "hsh_008_receipts_root"
path = "tests/test_hsh_008_receipts_root.rs"

# SVL-001: header version vs height / DFSP activation (SPEC §5.1 Step 1).
[[test]]
name = "svl_001_header_version_check"
path = "tests/test_svl_001_header_version_check.rs"

# SVL-002: DFSP roots must be EMPTY_ROOT before activation height (SPEC §5.1 Step 2).
[[test]]
name = "svl_002_dfsp_root_pre_activation"
path = "tests/test_svl_002_dfsp_root_pre_activation.rs"

# SVL-003: header declared total_cost / block_size vs MAX_COST_PER_BLOCK / MAX_BLOCK_SIZE (SPEC §5.1 Steps 3–4).
[[test]]
name = "svl_003_cost_and_size_checks"
path = "tests/test_svl_003_cost_and_size_checks.rs"

# SVL-004: header timestamp vs now + MAX_FUTURE_TIMESTAMP_SECONDS (SPEC §5.1 Step 5).
[[test]]
name = "svl_004_timestamp_future_bound"
path = "tests/test_svl_004_timestamp_future_bound.rs"

# SVL-005: header spend/addition/removal/slash counts vs block body (SPEC §5.2 steps 2, 4, 5, 13).
[[test]]
name = "svl_005_block_count_agreement"
path = "tests/test_svl_005_block_count_agreement.rs"

# SVL-006: Merkle roots, duplicate/double-spend, slash limits, filter hash, bincode size (SPEC §5.2 steps 3, 6–15).
[[test]]
name = "svl_006_merkle_root_integrity"
path = "tests/test_svl_006_merkle_root_integrity.rs"

# BLD-001: BlockBuilder struct and new() (SPEC §6.1–6.2, block_production NORMATIVE).
[[test]]
name = "bld_001_builder_struct_constructor"
path = "tests/test_bld_001_builder_struct_constructor.rs"

# BLD-002: BlockBuilder add_spend_bundle cost/size budgets, remaining_cost, spend_bundle_count.
[[test]]
name = "bld_002_add_spend_bundle_budget"
path = "tests/test_bld_002_add_spend_bundle_budget.rs"

# BLD-003: BlockBuilder add_slash_proposal count and per-payload size limits.
[[test]]
name = "bld_003_add_slash_proposal_limits"
path = "tests/test_bld_003_add_slash_proposal_limits.rs"

# BLD-004: BlockBuilder set_l1_proofs, set_dfsp_roots, set_extension_data.
[[test]]
name = "bld_004_optional_setters"
path = "tests/test_bld_004_optional_setters.rs"

# BLD-005: BlockBuilder build() / build_with_dfsp_activation — roots, counts, version, timestamp, block_size, signing.
[[test]]
name = "bld_005_build_pipeline"
path = "tests/test_bld_005_build_pipeline.rs"

# BLD-006: BlockSigner in build() — hash passed to signer, BLS verify, failure mapping, object safety.
[[test]]
name = "bld_006_block_signer_integration"
path = "tests/test_bld_006_block_signer_integration.rs"

# BLD-007: every successful build() output passes L2Block::validate_structure (SVL-005/006 parity).
[[test]]
name = "bld_007_builder_validity_guarantee"
path = "tests/test_bld_007_builder_validity_guarantee.rs"

# SER-001: bincode round-trip for wire types + bincode vs JSON size probe (flat `tests/` path).
[[test]]
name = "ser_001_bincode_all_types"
path = "tests/test_ser_001_bincode_all_types.rs"

# SER-002: to_bytes (infallible) / from_bytes (BlockError / CheckpointError) conventions.
[[test]]
name = "ser_002_to_from_bytes"
path = "tests/test_ser_002_to_from_bytes.rs"

# SER-003: L2BlockHeader::genesis bootstrap (SPEC §8.3, NORMATIVE § SER-003).
[[test]]
name = "ser_003_genesis_header"
path = "tests/test_ser_003_genesis_header.rs"

# SER-004: serde defaults for post-v1 fields — backwards compat round-trip (SPEC §8.2, NORMATIVE § SER-004).
[[test]]
name = "ser_004_serde_defaults"
path = "tests/test_ser_004_serde_defaults.rs"

# SER-005: property-based round-trip integrity (proptest) for all wire types (SPEC §12.1, §12.5).
[[test]]
name = "ser_005_roundtrip_integrity"
path = "tests/test_ser_005_roundtrip_integrity.rs"

# EXE-008: ExecutionResult output struct — Tier-2 → Tier-3 bridge (SPEC §7.4.7).
[[test]]
name = "exe_008_execution_result"
path = "tests/test_exe_008_execution_result.rs"

# EXE-009: PendingAssertion + AssertionKind (8 height/time variants) + from_condition factory.
[[test]]
name = "exe_009_pending_assertion"
path = "tests/test_exe_009_pending_assertion.rs"

# EXE-001: L2Block::validate_execution API surface + block-level fee/cost consistency on empty block.
[[test]]
name = "exe_001_validate_execution_api"
path = "tests/test_exe_001_validate_execution_api.rs"

# EXE-002: per-CoinSpend puzzle hash verification via clvm-utils::tree_hash (SPEC §7.4.2).
[[test]]
name = "exe_002_puzzle_hash_verification"
path = "tests/test_exe_002_puzzle_hash_verification.rs"

# EXE-003: dig-clvm delegation + ValidationError -> BlockError mapping (SPEC §7.4.3).
[[test]]
name = "exe_003_clvm_delegation"
path = "tests/test_exe_003_clvm_delegation.rs"

# EXE-004: condition parsing — pending-assertion collection from OwnedSpendBundleConditions (SPEC §7.4.4).
[[test]]
name = "exe_004_condition_parsing"
path = "tests/test_exe_004_condition_parsing.rs"

# EXE-005: BLS aggregate signature verification delegated to dig-clvm (SPEC §7.4.5).
[[test]]
name = "exe_005_bls_delegation"
path = "tests/test_exe_005_bls_delegation.rs"

# EXE-006: coin conservation + block-level fee consistency (SPEC §7.4.6).
[[test]]
name = "exe_006_fee_consistency"
path = "tests/test_exe_006_fee_consistency.rs"

# EXE-007: block-level cost consistency (SPEC §7.4.6 / Chia Check 9).
[[test]]
name = "exe_007_cost_consistency"
path = "tests/test_exe_007_cost_consistency.rs"

# STV-001: L2Block::validate_state + validate_full API surface (SPEC §7.5).
[[test]]
name = "stv_001_validate_state_api"
path = "tests/test_stv_001_validate_state_api.rs"

# STV-002: coin existence checks for removals (SPEC §7.5.1 / Chia Check 15).
[[test]]
name = "stv_002_coin_existence"
path = "tests/test_stv_002_coin_existence.rs"

# STV-003: puzzle hash cross-check (state vs CoinSpend) (SPEC §7.5.2 / Chia Check 20).
[[test]]
name = "stv_003_puzzle_hash_cross_check"
path = "tests/test_stv_003_puzzle_hash_cross_check.rs"

# STV-004: addition non-existence (+ ephemeral exception) (SPEC §7.5.3).
[[test]]
name = "stv_004_addition_uniqueness"
path = "tests/test_stv_004_addition_uniqueness.rs"

# STV-005: height/time lock evaluation for PendingAssertion (SPEC §7.5.4 / Chia Check 21).
[[test]]
name = "stv_005_height_time_locks"
path = "tests/test_stv_005_height_time_locks.rs"

# STV-006: proposer signature verification via chia_bls::verify (SPEC §7.5.5).
[[test]]
name = "stv_006_proposer_signature"
path = "tests/test_stv_006_proposer_signature.rs"

# STV-007: state root verification (apply additions/removals, compare) (SPEC §7.5.6).
[[test]]
name = "stv_007_state_root"
path = "tests/test_stv_007_state_root.rs"

# STR-*: one integration test binary per requirement (`autotests = false`).
[[test]]
name = "str_001_cargo_dependencies"
path = "tests/test_str_001_cargo_dependencies.rs"

[[test]]
name = "str_002_module_hierarchy"
path = "tests/test_str_002_module_hierarchy.rs"

[[test]]
name = "str_003_public_reexports"
path = "tests/test_str_003_public_reexports.rs"

[[test]]
name = "str_004_coin_lookup_block_signer"
path = "tests/test_str_004_coin_lookup_block_signer.rs"

[[test]]
name = "str_005_test_infrastructure"
path = "tests/test_str_005_test_infrastructure.rs"

# Public-API smoke test — exercises the crate as a downstream consumer would (prelude,
# re-exports, builder -> validate_full round-trip, wire serde, trait object safety).
[[test]]
name = "public_api_smoke"
path = "tests/test_public_api_smoke.rs"