Skip to main content

map_clvm_validation_error

Function map_clvm_validation_error 

Source
pub fn map_clvm_validation_error(err: ValidationError) -> BlockError
Expand description

Map a dig_clvm::ValidationError to the appropriate crate::BlockError variant (EXE-003, SPEC §7.4.3).

§Why this lives in dig-block

dig-clvm is a vendored CLVM consensus engine; it raises domain-specific errors (per-coin id, per-spend issues). dig-block exposes a single taxonomy (crate::BlockError) so downstream callers never see dig_clvm variants — matching NORMATIVE EXE-003 / ERR-002.

§Mapping table

dig_clvm::ValidationErrordig_block::BlockError
PuzzleHashMismatch(coin_id)PuzzleHashMismatch { coin_id, expected, computed } (hashes echo coin id as a best-effort — caller may enrich)
SignatureFailedSignatureFailed { bundle_index: 0 } (caller with bundle loop context may rewrap with the correct index)
CostExceeded { limit, consumed }ClvmCostExceeded { cost: consumed, remaining: limit, coin_id: default }
ConservationViolation { input, output }CoinMinting { removed: input, added: output }
CoinNotFound(coin_id)CoinNotFound { coin_id }
AlreadySpent(coin_id)CoinAlreadySpent { coin_id, spent_height: 0 }
DoubleSpend(coin_id)DoubleSpendInBlock { coin_id }
Clvm(reason)ClvmExecutionFailed { coin_id: default, reason }
Driver(e)InvalidData(e.to_string())

§Rationale

dig-clvm’s error variants carry less context than dig-block’s (e.g. no expected / computed hash split for puzzle-hash mismatches — that split is a dig-block ergonomic on top of coin_id). The bundle_index field on crate::BlockError::SignatureFailed is set to 0 here because dig-clvm operates on one bundle at a time; callers iterating bundles can rewrap with the correct index (see L2Block::validate_execution_with_context).

§Chia parity

Aligns with block_body_validation.py Checks 15–22 error codes.