dig-clvm
DIG L2 CLVM consensus engine. Validates spend bundles and computes coin additions/removals for DIG validators.
Built as a thin orchestration layer on top of the Chia crate ecosystem. Never reimplements what chia-consensus, chia-sdk-types, chia-sdk-driver, clvmr, clvm-utils, or chia-bls already provide.
Core Contract
Input: SpendBundle (coin spends + aggregated BLS signature)
Output: SpendResult { additions: Vec<Coin>, removals: Vec<Coin>, fee: u64 }
or ValidationError
Blockchain state management (UTXO persistence, Merkle roots, block storage) is out of scope. This crate validates and computes; the caller commits to state.
Public API
Entry Points
validate_spend_bundle — Validate a single spend bundle
;
Validates a spend bundle for mempool admission or block inclusion. Internally delegates CLVM execution, condition parsing, and BLS signature verification to chia-consensus.
Validation pipeline:
- Structural checks (duplicate spends, coin existence, already-spent)
- CLVM execution + condition extraction via
chia-consensus::run_spendbundle() - Cost enforcement against
config.max_cost_per_block - BLS signature verification (skipped if
DONT_VALIDATE_SIGNATUREflag set) - Conservation check (
sum(removals) >= sum(additions) + fee)
build_block_generator — Assemble bundles into a block
;
Iterates bundles in order, adds each until max_cost is reached. Caller pre-sorts by fee/cost ratio. Produces a compressed CLVM block program via solution_generator_backrefs().
validate_block — Validate a block generator
;
Executes a block-level CLVM program via chia-consensus::run_block_generator2(), validates conditions, and returns additions/removals.
Input Types
ValidationContext — Chain state for validation
coin_records contains only the coins relevant to this validation. The caller loads them from their database. This crate never touches storage.
ephemeral_coins tracks coins created by earlier bundles in the same block, enabling same-block create+spend (Chia L1's ASSERT_EPHEMERAL behavior).
ValidationConfig — Validation parameters
Flags can be combined: MEMPOOL_MODE | DONT_VALIDATE_SIGNATURE.
Output Types
SpendResult — Validation output
additions and removals are what the caller commits to blockchain state. conditions is the raw output from chia-consensus for callers that need to inspect announcements, signatures, or time locks.
BlockGeneratorResult — Block construction output
ValidationError — Error types
Constants
pub const L1_MAX_COST_PER_SPEND: Cost = 11_000_000_000; // Matches Chia L1
pub const L2_MAX_COST_PER_BLOCK: Cost = 550_000_000_000; // 50x L1 per-spend
Re-exports
All Chia ecosystem types are re-exported so callers need only depend on dig-clvm:
| Source Crate | Re-exported Types |
|---|---|
clvmr |
Allocator, NodePtr, Cost |
clvm-traits |
ToClvm, FromClvm |
clvm-utils |
tree_hash, CurriedProgram, TreeHash, ToTreeHash |
chia-protocol |
Coin, CoinSpend, SpendBundle, Program, Bytes32, CoinState |
chia-bls |
PublicKey, SecretKey, Signature, BlsCache, aggregate_verify |
chia-consensus |
ConsensusConstants, opcodes |
chia-sdk-types |
Condition, Conditions, Mod |
chia-sdk-driver |
SpendContext, Layer, Spend, SpendWithConditions, Puzzle, DriverError |
chia-sdk-coinset |
CoinRecord |
chia-puzzles |
All puzzle bytecodes |
dig-constants |
NetworkConstants, DIG_MAINNET, DIG_TESTNET |
Usage
Validate a Spend Bundle
use ;
use ;
let ctx = ValidationContext ;
let mut cache = default;
let config = default;
let result = validate_spend_bundle?;
// Commit to state
for coin in &result.additions
for coin in &result.removals
Build and Validate a Block
use ;
// Sort bundles by fee/cost ratio, then build
let block = build_block_generator?;
// Validate the block
let result = validate_block?;
Skip Signature Verification (Mempool Pre-validation)
use DONT_VALIDATE_SIGNATURE;
let config = ValidationConfig ;
let result = validate_spend_bundle?;
Architecture
src/
lib.rs -- Re-exports only
consensus/
mod.rs -- Module root
validate.rs -- validate_spend_bundle()
block.rs -- build_block_generator(), validate_block()
context.rs -- ValidationContext
config.rs -- ValidationConfig, cost constants
result.rs -- SpendResult, BlockGeneratorResult
cache.rs -- BLS cache management
error.rs -- ValidationError
No async, no IO, no storage. Pure computation. All CLVM execution, condition parsing, tree hashing, BLS verification, and cost accounting delegated to the Chia crate ecosystem.
Dependencies
[]
= "0.14"
= "0.26"
= "0.26"
= "0.26"
= "0.26"
= "0.26"
= "0.26"
= "0.30"
= { = "0.30", = ["action-layer"] }
= "0.30"
= "0.20"
= { = "../dig-constants" }
= "2"
= "0.4"
[]
= "0.30"
Testing
55 dedicated test files, 154 tests. One file per requirement (tests/vv_req_{prefix}_{nnn}.rs).
Documentation
| Document | Path |
|---|---|
| Specification | docs/resources/SPEC.md |
| Requirements (55) | docs/requirements/ |
| Workflow | docs/prompt/start.md |