# Phase 0, Milestone 1: Core Types

> Foundation types for the Synor blockchain

**Status**: ✅ Complete
**Priority**: Critical
**Crate**: `synor-types`

---

## Overview

Define all core data types used throughout the Synor blockchain, including addresses, amounts, transactions, blocks, and hashes.

---

## Tasks

### Task 1.1: Hash Types
- [x] Implement `Hash256` - 32-byte hash wrapper
- [x] Implement `Hash512` - 64-byte hash wrapper
- [x] Add serialization (serde, borsh)
- [x] Add hex encoding/decoding

**Files:**
- `crates/synor-types/src/hash.rs`

### Task 1.2: Address Types
- [x] Implement `Address` with network prefix
- [x] Support mainnet (`q0`) and testnet (`qz`) prefixes
- [x] Add Bech32-like encoding
- [x] Implement `AddressType` enum (P2PKH, P2SH, P2TR)

**Files:**
- `crates/synor-types/src/address.rs`

### Task 1.3: Amount Types
- [x] Implement `Amount` with overflow protection
- [x] Use 8 decimal places (somas)
- [x] Implement arithmetic operations
- [x] Add formatting and parsing

**Files:**
- `crates/synor-types/src/amount.rs`

### Task 1.4: Transaction Types
- [x] Implement `Transaction` struct
- [x] Implement `TransactionInput` with outpoint reference
- [x] Implement `TransactionOutput` with script
- [x] Add transaction ID calculation

**Files:**
- `crates/synor-types/src/transaction.rs`

### Task 1.5: Block Types
- [x] Implement `BlockHeader` with DAG references
- [x] Implement `Block` with header and transactions
- [x] Add blue score tracking
- [x] Implement block hash calculation

**Files:**
- `crates/synor-types/src/block.rs`

### Task 1.6: Script Types
- [x] Implement `Script` for locking/unlocking
- [x] Implement `ScriptPubKey` for outputs
- [x] Implement `ScriptSig` for inputs
- [x] Add opcode definitions

**Files:**
- `crates/synor-types/src/script.rs`

---

## Validation

### Validation Commands

```bash
# Run unit tests
cargo test -p synor-types

# Check documentation
cargo doc -p synor-types --no-deps

# Lint
cargo clippy -p synor-types -- -D warnings
```

### Validation Agents

| Agent | Command | Purpose |
|-------|---------|---------|
| `type-design-analyzer` | Review type design | Ensure proper encapsulation and invariants |
| `code-reviewer` | Review implementation | Check code quality and patterns |

### Validation Criteria

- [ ] All types implement `Clone`, `Debug`, `PartialEq`, `Eq`
- [ ] All types implement `Serialize`, `Deserialize` (serde)
- [ ] All types implement `BorshSerialize`, `BorshDeserialize`
- [ ] Hash types have constant-time comparison
- [ ] Amount arithmetic checks for overflow
- [ ] Address validation rejects invalid prefixes
- [ ] Transaction ID matches expected hash algorithm

### Security Checks

- [ ] No panics on malformed input (use Result types)
- [ ] Constant-time comparison for sensitive data
- [ ] No integer overflow in Amount operations
- [ ] Address checksum validation

### Test Coverage

```bash
# Run with coverage
cargo tarpaulin -p synor-types --out Html

# Expected coverage: >90%
```

---

## Dependencies

- `serde` - Serialization
- `borsh` - Binary serialization
- `hex` - Hex encoding
- `thiserror` - Error types

---

## Acceptance Criteria

1. All 53 unit tests pass
2. No clippy warnings
3. Documentation complete for all public types
4. Coverage >90%

---

*Completed: January 2025*
