# CON-001: Separate dig-constants Crate

> **Authoritative requirement:** [CON-001](../NORMATIVE.md#CON-001)
> **Verification:** [VERIFICATION.md](../VERIFICATION.md)
> **Tracking:** [TRACKING.yaml](../TRACKING.yaml)
> **Spec reference:** [SPEC.md](../../../../resources/SPEC.md) — Section 4.3

---

## Summary

DIG network parameters are defined in a separate `dig-constants` crate, independent of the `dig-clvm` CLVM execution engine. This separation ensures that any DIG crate — not just validation-related ones — can import network constants without pulling in the entire CLVM engine and its heavy dependencies (`clvmr`, `chia-consensus`, etc.). The `dig-constants` crate has already been created and compiles successfully at `../dig-constants` relative to the `dig-clvm` crate root.

The architectural rationale is dependency hygiene. Many DIG ecosystem crates need access to the genesis challenge, cost limits, or AGG_SIG additional data, but have no reason to depend on CLVM execution. For example, a networking crate that needs the genesis challenge for peer identification, a wallet crate that needs AGG_SIG data for signing, or a CLI tool that displays network parameters — none of these should transitively depend on `clvmr` or `chia-consensus`. By isolating constants into their own crate, these consumers get a lightweight import.

The `dig-constants` crate wraps Chia's `ConsensusConstants` type from `chia-consensus` with a DIG-specific `NetworkConstants` type that provides ergonomic accessors and enforces DIG-specific invariants (like all fork heights at zero). It exports two const instances — `DIG_MAINNET` and `DIG_TESTNET` — that are the canonical network configurations for the DIG L2.

---

## Specification

### Crate Location and Structure

```
dig-network/
├── dig-clvm/          # CLVM execution engine
├── dig-constants/     # Network constants (this crate)
│   ├── Cargo.toml
│   └── src/
│       └── lib.rs
└── ...
```

### Cargo.toml

```toml
[package]
name = "dig-constants"
version = "0.1.0"
edition = "2021"
description = "DIG L2 network constants and consensus parameters"

[dependencies]
chia-consensus = { version = "..." }
chia-protocol = { version = "..." }
chia-bls = { version = "..." }
hex-literal = { version = "..." }
# NO dig-clvm dependency (avoid circular)
# NO tokio or async runtime
```

### Public API

```rust
// dig-constants/src/lib.rs

mod constants;
mod network;

pub use constants::{DIG_MAINNET, DIG_TESTNET};
pub use network::NetworkConstants;
```

### How dig-clvm Depends on dig-constants

```toml
# dig-clvm/Cargo.toml
[dependencies]
dig-constants = { path = "../dig-constants" }
```

```rust
// dig-clvm/src/consensus/validate.rs
use dig_constants::{DIG_MAINNET, NetworkConstants};

pub fn validate_spend_bundle(
    bundle: &SpendBundle,
    context: &ValidationContext,  // context.constants: NetworkConstants
    config: &ValidationConfig,
    cache: Option<&mut BlsCache>,
) -> Result<SpendResult, ValidationError> {
    let max_cost = context.constants.max_block_cost_clvm();
    // ...
}
```

### How Other Crates Depend on dig-constants

```toml
# dig-wallet/Cargo.toml
[dependencies]
dig-constants = { path = "../dig-constants" }
# Does NOT need dig-clvm!
```

```rust
// dig-wallet/src/signing.rs
use dig_constants::DIG_MAINNET;

fn get_agg_sig_data() -> Bytes32 {
    DIG_MAINNET.agg_sig_me_additional_data()
    // No CLVM engine needed
}
```

### Dependency Graph

```
dig-constants
├── chia-consensus
├── chia-protocol
├── chia-bls
└── hex-literal

dig-clvm
├── dig-constants      ← lightweight constants
├── chia-consensus     ← heavy CLVM engine
├── chia-protocol
├── chia-bls
└── clvmr

dig-wallet (example consumer)
├── dig-constants      ← only constants, no CLVM
├── chia-bls
└── ...
```

---

## Acceptance Criteria

- [ ] `dig-constants` is a separate crate at `../dig-constants` relative to `dig-clvm`.
- [ ] `dig-constants` compiles independently without `dig-clvm`.
- [ ] `dig-clvm` depends on `dig-constants` (not the reverse).
- [ ] `dig-constants` does not depend on `clvmr` or `dig-clvm`.
- [ ] Other crates can import `dig-constants` without transitively depending on `dig-clvm`.

---

## Implementation Notes

- **Already created:** The `dig-constants` crate has already been created and compiles. This spec documents the design decision and constraints.
- **No circular dependency:** `dig-constants` MUST NOT depend on `dig-clvm`. If constants need to be computed using CLVM (they don't), the computation would happen at build time, not runtime.
- **Version alignment:** The `chia-consensus` version in `dig-constants` must match the version used by `dig-clvm` to avoid type conflicts (same `ConsensusConstants` type from different versions).
- **Workspace member:** Both crates should be members of the same Cargo workspace for unified dependency resolution.
- **Re-export consideration:** `dig-clvm` may re-export `dig_constants::NetworkConstants` and the const instances for convenience, but consumers who only need constants should depend on `dig-constants` directly.
- **No build scripts:** `dig-constants` does not require a build script. All constants are defined at compile time using `const` declarations and the `hex-literal` macro.

---

## Verification

### Test Plan

| Test | Type | Description | Expected Result |
|------|------|-------------|-----------------|
| Independent compilation | Build test | `cd dig-constants && cargo build` | Compiles without dig-clvm |
| No clvmr dependency | Build test | `cargo tree` for dig-constants | clvmr not in dependency tree |
| dig-clvm imports constants | Build test | `cd dig-clvm && cargo build` | Compiles with dig-constants dep |
| No circular dependency | Build test | `cargo tree` for both crates | No circular references |
| External crate usage | Build test | Create test crate depending only on dig-constants | Compiles without dig-clvm |
| Type compatibility | Integration test | Use NetworkConstants from dig-constants in dig-clvm | Same type, no conversion needed |

---

## Source Citations

- **SPEC.md Section 4.3**: "DIG params in separate crate. Any DIG crate imports without CLVM engine."
- **SPEC.md Section 4.3**: "Already created and compiling at ../dig-constants."
- **Cargo workspace documentation:** Best practices for multi-crate Rust projects.

---

## References

- [CON-002](CON-002.md) — NetworkConstants type (primary export of dig-constants)
- [CON-003](CON-003.md) — DIG_MAINNET and DIG_TESTNET instances
- [CON-007](CON-007.md) — Minimal dependencies (dig-constants dependency constraints)
- [VAL-015](../../validation/specs/VAL-015.md) — No full UTXO set (same pure-computation philosophy)
