# VAL-008: Default Cost Constants

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

---

## Summary

The DIG L2 chain must define default cost limits that balance security (preventing resource exhaustion) with throughput (allowing enough computation per block for practical use). Two constants are defined: a per-spend limit that matches Chia L1 exactly, and a per-block limit that is 50 times higher than L1's per-spend limit to accommodate the higher throughput expectations of an L2 chain.

On Chia L1, the single cost constant `MAX_BLOCK_COST_CLVM = 11_000_000_000` (11 billion) is defined at [`default_constants.py:68`](https://github.com/Chia-Network/chia-blockchain/blob/main/chia/consensus/default_constants.py#L68). This serves as both the per-spend and per-block limit since L1 blocks contain a single generator program. On DIG L2, individual spends are bounded at the same 11B limit to ensure compatibility with all existing Chia puzzles, but the block limit is set to 550B (50 * 11B) to allow many spends per block.

These constants are the default values for `ValidationConfig`. Callers can override them for testing or for alternative validation modes, but the defaults represent the canonical L2 consensus parameters. The per-spend limit is also meaningful because `run_spendbundle()` uses it internally to bound each individual puzzle execution.

---

## Specification

### Constants

```rust
/// Maximum CLVM cost per individual spend.
/// Matches Chia L1's MAX_BLOCK_COST_CLVM at default_constants.py:68.
pub const L1_MAX_COST_PER_SPEND: Cost = 11_000_000_000;

/// Maximum total CLVM cost per L2 block.
/// 50x the L1 per-spend limit, allowing high-throughput L2 blocks.
pub const L2_MAX_COST_PER_BLOCK: Cost = 550_000_000_000;
```

### Default ValidationConfig

```rust
impl Default for ValidationConfig {
    fn default() -> Self {
        Self {
            max_cost_per_spend: L1_MAX_COST_PER_SPEND,   // 11_000_000_000
            max_cost_per_block: L2_MAX_COST_PER_BLOCK,   // 550_000_000_000
            flags: 0,
        }
    }
}
```

### Rationale for Values

| Constant | Value | Rationale |
|----------|-------|-----------|
| `L1_MAX_COST_PER_SPEND` | 11,000,000,000 | Exact match with Chia L1 `MAX_BLOCK_COST_CLVM`. Ensures all valid L1 puzzles can execute on L2. Any puzzle that works on L1 will work on L2 within the same cost budget. |
| `L2_MAX_COST_PER_BLOCK` | 550,000,000,000 | 50x L1 per-spend. Allows approximately 50 maximum-cost spends per L2 block, or thousands of typical spends (which consume far less than the 11B maximum). The exact multiplier is a design choice balancing throughput against validation time. |

### Condition Cost Reference (from chia-consensus)

These costs are baked into `chia-consensus` and are not configurable, but are relevant for understanding what contributes to the total cost:

| Condition | Cost | L1 Reference |
|-----------|------|--------------|
| `AGG_SIG_*` | 1,200,000 | [`condition_costs.py:8`](https://github.com/Chia-Network/chia-blockchain/blob/main/chia/consensus/condition_costs.py#L8) |
| `CREATE_COIN` | 1,800,000 | [`condition_costs.py:9`](https://github.com/Chia-Network/chia-blockchain/blob/main/chia/consensus/condition_costs.py#L9) |
| Generic condition | 500 | [`condition_costs.py:13`](https://github.com/Chia-Network/chia-blockchain/blob/main/chia/consensus/condition_costs.py#L13) |

---

## Acceptance Criteria

- [ ] `L1_MAX_COST_PER_SPEND` is defined as a public constant with value `11_000_000_000`.
- [ ] `L2_MAX_COST_PER_BLOCK` is defined as a public constant with value `550_000_000_000`.
- [ ] `ValidationConfig::default().max_cost_per_spend` equals `11_000_000_000`.
- [ ] `ValidationConfig::default().max_cost_per_block` equals `550_000_000_000`.
- [ ] `ValidationConfig::default().flags` equals `0`.
- [ ] Both constants are of type `Cost` (which is `u64`).
- [ ] Both constants are publicly accessible from external crates.

---

## Implementation Notes

- **Primary file:** `src/consensus/config.rs`
- **Public export:** Constants and `ValidationConfig` must be re-exported from `src/lib.rs`.
- **Type:** `Cost` is `u64`, imported from `clvmr`.
- **L1 parity:** The per-spend limit MUST exactly match L1. If Chia L1 changes `MAX_BLOCK_COST_CLVM` in a future hard fork, `L1_MAX_COST_PER_SPEND` should be updated accordingly.
- **The 50x multiplier** is a DIG-specific design choice. It is not derived from any L1 constant. The multiplier could be adjusted in future versions based on L2 performance and security analysis.
- **Flags default to 0:** This means block-mode validation (most permissive). Callers must explicitly set `MEMPOOL_MODE` for mempool admission. This matches L1 where block validation uses flags=0 and mempool uses `MEMPOOL_MODE`.
- **Edge case:** Callers can set `max_cost_per_block` lower than `max_cost_per_spend`. This is valid (it means no single spend can use the full per-spend budget if it would exceed the block budget).

---

## Verification

### Test Plan

| Test | Type | Description | Expected Result |
|------|------|-------------|-----------------|
| L1_MAX_COST_PER_SPEND value | Unit test | `assert_eq!(L1_MAX_COST_PER_SPEND, 11_000_000_000)` | Passes |
| L2_MAX_COST_PER_BLOCK value | Unit test | `assert_eq!(L2_MAX_COST_PER_BLOCK, 550_000_000_000)` | Passes |
| Default config per_spend | Unit test | `assert_eq!(ValidationConfig::default().max_cost_per_spend, 11_000_000_000)` | Passes |
| Default config per_block | Unit test | `assert_eq!(ValidationConfig::default().max_cost_per_block, 550_000_000_000)` | Passes |
| Default config flags | Unit test | `assert_eq!(ValidationConfig::default().flags, 0)` | Passes |
| 50x relationship | Unit test | `assert_eq!(L2_MAX_COST_PER_BLOCK, 50 * L1_MAX_COST_PER_SPEND)` | Passes |
| Constants publicly accessible | Integration test | Import `L1_MAX_COST_PER_SPEND` and `L2_MAX_COST_PER_BLOCK` from `dig_clvm` | Import resolves |

---

## Source Citations

- **SPEC.md Section 5.1** (lines 559-562): Constant definitions with L1 reference.
  - `pub const L1_MAX_COST_PER_SPEND: Cost = 11_000_000_000;`
  - `pub const L2_MAX_COST_PER_BLOCK: Cost = 550_000_000_000; // 50 * L1 per-spend`
- **SPEC.md Section 5.1** (lines 501-508): `Default` impl for `ValidationConfig`.
- **SPEC.md Section 3.1** (line 229): "L2 cost constants — MAX_COST_PER_BLOCK for L2 (50x L1 per-spend limit)."
- **SPEC.md Section 9.5** (lines 960-964): Design decision "Why ValidationConfig with Configurable Cost Limits."
- **L1 reference — MAX_BLOCK_COST_CLVM:** [`default_constants.py:68`](https://github.com/Chia-Network/chia-blockchain/blob/main/chia/consensus/default_constants.py#L68)
- **L1 reference — condition costs:** [`condition_costs.py:8-13`](https://github.com/Chia-Network/chia-blockchain/blob/main/chia/consensus/condition_costs.py#L8)

---

## References

- [VAL-007](VAL-007.md) — Cost limit enforcement (uses these constants via config)
- [VAL-001](VAL-001.md) — Entry point signature (accepts `ValidationConfig`)
- [VAL-013](VAL-013.md) — MEMPOOL_MODE (relates to default `flags = 0`)
