File size: 10,751 Bytes
1d3f990 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | # Isomorphic Shift β Formal Translation & State Correspondence Layer
**Repository**: SnapKitty Collective
**Status**: IMPLEMENTATION IN PROGRESS
**Authority**: Datalog/Prolog source-of-truth
**Governance Motto**: EVIDENCE OR SILENCE
---
## Mission
The Isomorphic Shift layer provides formally defined, bidirectional transformations connecting:
1. **Notebook Instructions** β Surface-level operation requests (EmojiCode, HolyC, Ada, Python, JavaScript)
2. **Runtime Representations** β Executable states (Rust, Erlang, Lean 4 proof obligations)
3. **Proof Representations** β Formal verification goals (Lean 4, Agda theorems)
4. **Execution Events** β Runtime state transitions logged to WORM
5. **Receipt Records** β Immutable evidence of execution and authorization
Each mapping is:
- **Bidirectional** with verified round-trip laws
- **Semantically preserving** (meaning survives transformation)
- **Authority-preserving** (no unauthorized permission escalation)
- **Invertible** (unless explicitly rejected as unsupported)
- **Classified** by category (isomorphism, embedding, projection, normalization, serialization, etc.)
---
## Core Principle: Round-Trip Laws
For every isomorphic shift M:
- **Forward then Inverse**: `inverse(forward(X)) = canonicalize(X)`
- **Inverse then Forward**: `forward(inverse(Y)) = canonicalize(Y)`
- **Semantic Preservation**: `meaning(X) = meaning(forward(X))`
- **Authority Preservation**: Shifts must NOT increase permissions, proof status, or release status
Lossy transformations are explicitly rejected as non-isomorphic.
---
## Eight Required Mappings (M1βM8)
| ID | Source Domain | Target Domain | Direction | Classification | Status |
|----|---|---|---|---|---|
| **M1** | SurfaceInstruction | CanonicalInstruction | β | Normalization | Design |
| **M2** | CanonicalInstruction | LogicTerm | β | Serialization | Design |
| **M3** | AuthorizedLogicDecision | RuntimeCommand | β | Projection | Design |
| **M4** | ProofObligation | VerifierInvocation | β | Embedding | Design |
| **M5** | ExecutionEvent | LogicEventFact | β | Serialization | Design |
| **M6** | ExecutionEvent | ReceiptRecord | β | Projection | Design |
| **M7** | NotebookCellRecord | LogicCellFact | β | Serialization | Design |
| **M8** | RuntimeSpecificValue | CanonicalValue | β | Normalization | Design |
---
## Canonical Intermediate Representation (ISIR)
All shifts pass through a deterministic canonical form with fields:
- `schema_version: u32` β Versioning
- `shift_id: String` β Unique shift identifier
- `shift_version: u32` β Shift-specific version
- `source_domain: String` β Domain of origin
- `target_domain: String` β Target domain
- `direction: String` β "forward", "inverse", or "bidirectional"
- `value_type: String` β "instruction", "decision", "event", "proof", "receipt", etc.
- `payload: Vec<u8>` β CBOR-encoded canonical representation
- `invariant_set: Vec<String>` β List of preserved invariants
- `required_permission: String` β Authorization level required
- `source_hash: String` β Blake3 hash of source
- `canonical_hash: String` β Blake3 hash of canonical form (deterministic)
- `parent_receipt_hash: Option<String>` β Ancestry chain
**Canonical encoding**: Deterministic CBOR (RFC 7049) with canonical item ordering.
---
## Authority Protocol (12-Step Sequence)
1. **Parse** source β Validate syntax
2. **Validate** source schema β Check structural requirements
3. **Canonicalize** β Produce deterministic ISIR
4. **Identify shift** β Look up M1βM8 mapping
5. **Query Prolog** β Check authorization facts and rules
6. **Validate schema compatibility** β Verify domain/codomain match
7. **Execute bounded transformation** β Apply adapter with timeout
8. **Validate target** β Check output schema
9. **Verify invariants** β Confirm all invariants preserved
10. **Generate evidence** β Produce manifest and receipt
11. **Commit transaction** (if applicable) β Atomic append to ledger
12. **Append receipt** β WORM-seal the result
---
## Datalog/Prolog Integration
**Source-of-truth authority**: All shifts, domains, schemas, authorizations, and permissions are registered as Prolog facts.
**Required files**:
- `logic/shifts.pl` β All isomorphic shifts registered
- `logic/domains.pl` β Domain definitions with types and constraints
- `logic/schemas.pl` β Schema versions and compatibility rules
- `logic/invariants.pl` β Preserved invariants per shift
- `logic/shift_authorization.pl` β Authorization rules
- `logic/shift_validity.pl` β Validity checking rules
- `logic/semantic_equivalence.pl` β Semantic preservation rules
- `logic/shift_release.pl` β Release-readiness rules
**Prohibition**: Isomorphic Shift MUST NOT maintain independent copies of:
- Capabilities or revocations
- Proof verification status
- Release status
- Authorization decisions
All queries flow through Prolog.
---
## Implementation Stack
### Rust Adapters (`adapters/`)
- `m1_surface_to_canonical.rs` β Surface instruction normalization
- `m2_canonical_to_logic.rs` β Canonical to logic term serialization
- `m3_logic_to_runtime.rs` β Authorized logic decision to runtime command
- `m4_proof_to_verifier.rs` β Proof obligation to verifier invocation
- `m5_event_to_logic.rs` β Execution event to logic event fact
- `m6_event_to_receipt.rs` β Execution event to receipt record
- `m7_notebook_to_logic.rs` β Notebook cell to logic cell fact
- `m8_value_normalization.rs` β Runtime value to canonical value
Each adapter implements:
```rust
pub fn forward(source: &Source) -> Result<Target, ShiftError>
pub fn inverse(target: &Target) -> Result<Source, ShiftError>
pub fn verify_round_trip(source: &Source) -> Result<bool, ShiftError>
```
### Logic Engine (`logic/`)
- **Facts**: Shift definitions, domain definitions, schema versions
- **Rules**: Authorization, validity checking, semantic equivalence
- **Queries**: shift_available/1, shift_permitted/3, round_trip_verified/2
- **Tests**: Logic-level tests for rule correctness
### Tests (`tests/`)
- **RoundTrip**: ForwardβInverseβcanonicalize, InverseβForwardβcanonicalize
- **SemanticPreservation**: Meaning, types, authority survive
- **Authority**: No permission escalation, no proof status change
- **Failure**: Malformed rejected, unsupported versions rejected, lossy mappings rejected
- **Logic**: Unregistered shifts denied, unauthorized agents denied, contradictions detected
---
## Transaction Model
### States
- `prepared` β Source parsed, schema validated
- `validated` β Canonical form generated, shift identified
- `authorized` β Prolog authorization successful
- `transformed` β Adapter executed successfully
- `invariants_checked` β All invariants verified
- `committed` β Transaction written to ledger (if applicable)
- `receipted` β Receipt WORM-sealed
- `rejected` β Operation denied (authorization, validation, or semantic failure)
- `failed` β Adapter timeout, malformed target, or other runtime error
### Atomicity
- Commit all or nothing
- Failed stages β automatic rollback
### Idempotency
- Same transaction ID + canonical input β returns existing result from ledger
---
## Evidence Bundle
All completed shifts produce:
1. **Manifest** β Metadata about the shift (source, target, timestamp, adapters used)
2. **Receipt** β WORM-sealed proof of execution
3. **Invariant Proof** β Evidence that all invariants were preserved
4. **Authorization Log** β Prolog query results proving authorization
5. **Test Results** β Round-trip verification evidence
---
## Restrictions
β NO additional sub-agents
β NO destructive repository operations
β NO deletion of existing Isomorphic Shift artifacts
β NO Git history rewriting
β NO replacing functioning implementations without evidence
β NO self-authorized runtime mutations
β NO isomorphism claims without verified inverse behavior
β NO completion reports based on scaffolding
---
## Directories
```
isomorphic-shift/
βββ README.md (this file)
βββ schemas/
β βββ domains.schema.json
β βββ canonical.schema.json
β βββ shift.schema.json
β βββ receipt.schema.json
βββ logic/
β βββ shifts.pl
β βββ domains.pl
β βββ schemas.pl
β βββ invariants.pl
β βββ shift_authorization.pl
β βββ shift_validity.pl
β βββ semantic_equivalence.pl
β βββ shift_release.pl
β βββ tests/
βββ adapters/
β βββ lib.rs
β βββ m1_surface_to_canonical.rs
β βββ m2_canonical_to_logic.rs
β βββ m3_logic_to_runtime.rs
β βββ m4_proof_to_verifier.rs
β βββ m5_event_to_logic.rs
β βββ m6_event_to_receipt.rs
β βββ m7_notebook_to_logic.rs
β βββ m8_value_normalization.rs
β βββ tests/
βββ proofs/
β βββ round_trip_laws.lean
β βββ semantic_preservation.lean
β βββ authority_preservation.lean
βββ tests/
β βββ round_trip_tests.rs
β βββ semantic_preservation_tests.rs
β βββ authority_tests.rs
β βββ failure_tests.rs
β βββ logic_integration_tests.rs
βββ evidence/
β βββ manifests/
β βββ receipts/
β βββ invariant_proofs/
βββ docs/
βββ architecture.md
βββ mapping-catalog.md
βββ invariants.md
βββ source-of-truth-integration.md
βββ threat-model.md
βββ limitations.md
```
---
## Next Steps
1. Define domain types and constraints (domains.pl, domains.schema.json)
2. Implement M1βM8 adapters with round-trip verification
3. Register shifts in Prolog (shifts.pl)
4. Implement authorization rules (shift_authorization.pl)
5. Build and test adapters
6. Integrate with existing notebook/ledger systems
7. Generate evidence bundle
---
## References
- **LOC Agent**: DEVFLOW-FINANCE/snapkitty-core/src/agents/loc_agent.rs (Triad execution)
- **Sovereign Kernel**: bob-orchestrator/prolog/sovereign_kernel.pl (Authorization logic)
- **Bifrost Transform**: DEVFLOW-FINANCE/collectivekitty/lib/bifrost/transform.ts (Event transformation pattern)
- **EmojiCode Mapping**: EmojiCode β HolyC/Ada/Rust/Haskell (loc_agent.rs emoji_map)
- **Notebook**: DEVFLOW-FINANCE/sovereign_notebook.ipynb (Triad pipeline trace)
|