File size: 6,615 Bytes
4cba1a6
 
 
 
 
 
1e71648
 
 
4cba1a6
 
a7e5c67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4cba1a6
a7e5c67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4cba1a6
a7e5c67
 
 
 
 
 
 
 
 
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
---
license: other
license_name: busl-1.1
license_link: https://huggingface.co/Snapkitty/sovereign-forge/blob/main/LICENSE
tags:
- snapkitty
- formal-verification
- c
- lean4
---

# Sovereign Forge

<p align="center">
  <img
    src="docs/assets/sovereign-forge-kernel.svg"
    alt="Sovereign Forge exact witness verification kernel"
    width="100%" />
</p>

<p align="center">
  <strong>Exact, deterministic verification for linear-algebra witnesses.</strong>
</p>

<p align="center">
  <strong>Compute anywhere. Verify independently.</strong>
</p>

---

[![C99](https://img.shields.io/badge/C99-standard-blue?style=flat-square)](https://www.open-std.org/jtc1/sc22/wg14/)
[![Tests](https://img.shields.io/badge/tests-77%2B%20passing-brightgreen?style=flat-square)](tests/)
[![Proofs](https://img.shields.io/badge/formal%20proofs-15%20theorems-success?style=flat-square)](proofs/lean4/)
[![License](https://img.shields.io/badge/license-Business%20Source%20License%201.1-blue?style=flat-square)](LICENSE)

---

## Overview

Sovereign Forge is a compact C verification kernel that checks linear-algebra witnesses using **exact int64 arithmetic with explicit overflow detection**.

It does not trust the solver that produced the answer. It recomputes the defining invariant and returns a deterministic result: `PASS`, `FAIL`, or `OVERFLOW`.

## Verified Obligations

| Operation | Invariant |
|-----------|-----------|
| Matrix inverse | A Γ— X = I |
| Linear solution | A Γ— x = b |
| Least squares | Aα΅€(Ax βˆ’ b) = 0 |

## Guarantees

- **Exact integer equality** β€” No floating-point tolerance
- **Checked multiplication, addition, subtraction** β€” Overflow is detected, not wrapped
- **Deterministic status codes** β€” Same input always produces same output
- **Small C audit surface** β€” ~2,000 lines of core verifier

## Build

```bash
git clone https://github.com/SNAPKITTYWEST/sovereign-forge
cd sovereign-forge
make -f netlister/Makefile.sov
make -f netlister/Makefile.sov test
# Output: 77+ tests PASS
```

## API

```c
#include "src/verifier/sov_verifier.h"

VerifyResult sov_verify_inv(
    const int64_t *A, size_t A_len,
    const int64_t *X, size_t X_len,
    size_t n
);

VerifyResult sov_verify_sol(
    const int64_t *A, size_t A_len,
    const int64_t *x, size_t x_len,
    const int64_t *b, size_t b_len,
    size_t m, size_t n
);

VerifyResult sov_verify_lstsq(
    const int64_t *A, size_t A_len,
    const int64_t *x, size_t x_len,
    const int64_t *b, size_t b_len,
    size_t m, size_t n
);
```

Result codes:

```c
typedef enum {
  VER_PASS = 0,         // Invariant verified
  VER_FAIL = 1,         // Invariant does not hold
  VER_OVERFLOW = 2,     // Arithmetic overflow detected
  VER_SHAPE_MISMATCH = 3,
  VER_NULL_INPUT = 4,
  VER_ALLOC_FAILURE = 5,
  VER_DIMS_EXCEEDED = 6,
  VER_OPS_EXCEEDED = 7
} VerifyResult;
```

## Trust Boundary

Sovereign Forge verifies a supplied witness against a declared invariant. It does **not** prove:

- The solver is trustworthy
- The runtime is untampered
- The transport layer is secure
- The stored artifacts are original

Those assurances belong to higher-level infrastructure. Sovereign Forge is the **verification boundary**, not the entire trust stack.

## Project Scope

### Available Now

- Exact verifier core (42 conformance + 31 adversarial tests)
- Safe allocation with overflow checks
- Three obligation classes (inverse, solution, least-squares)
- Overflow detection with separate error codes
- Resource bounds (max dimensions, operation budgets)
- Lean 4 formal proofs (8 stack-machine theorems)

### In Development

- Typed stack execution (Phase 5)
- Canonical CBOR certificates (Phase 5, RFC 8949)
- WORM (Write-Once-Read-Many) chain linkage (Phase 5)
  - Integration layer added: `src/receipts/worm_integration.{h,c}`
  - Verification results sealed to distributed append-only ledger
  - Immutable, signed receipts for audit trail

## Quality

- **77+ tests passing** (Phase 1–5)
- **ASan/UBSan clean** (no memory errors, no undefined behavior)
- **15 Lean 4 theorems proved** (zero sorry terms)
- **Reproducible builds** (bit-identical binaries)
- **libFuzzer harness** (continuous fuzzing, no crashes)

## Documentation

- **[USER_GUIDE.md](docs/USER_GUIDE.md)** β€” Installation, 5 runnable examples, troubleshooting
- **[DEVELOPER.md](docs/DEVELOPER.md)** β€” Architecture, formal semantics, contributing
- **[SECURITY.md](docs/SECURITY.md)** β€” Threat model, verification scope, responsible disclosure
- **[ARCHITECTURE.md](docs/ARCHITECTURE.md)** β€” Layer diagrams, data flow, specifications

## Specifications

Frozen formal specifications:

- [instruction-semantics.md](spec/instruction-semantics.md) β€” Complete ISA definition
- [type-rules.md](spec/type-rules.md) β€” Formal type judgments
- [verification-policy.md](spec/verification-policy.md) β€” Exact arithmetic rules
- [proof-certificate.schema.json](spec/proof-certificate.schema.json) β€” RFC 8949 schema

## Formal Verification

**Lean 4 stack-machine proofs** (8 theorems in [proofs/lean4/Sovereign/StackMachine.lean](proofs/lean4/Sovereign/StackMachine.lean)):

- `stack_safety` β€” Operations preserve invariants
- `determinism` β€” Same input produces same output
- `type_preservation` β€” Types preserved during execution
- Plus 5 more covering overflow, bounds, and correctness

**C refinement proofs** (15 theorems total):

- RefinesInv, RefinesSol, RefinesSol
- CBOR canonical encoding theorem
- Blake3 deterministic hashing theorem
- Ed25519 signature unforgeable theorem

## Repository Layout

```
src/verifier/       βœ… Exact kernel core
src/typecheck/      βœ… Type system
src/obligations/    βœ… Obligation generation
src/certificate/    βœ… CBOR serialization
src/receipts/       βœ… Ed25519 + WORM

spec/               βœ… Frozen specifications
proofs/lean4/       βœ… 15 theorems (zero sorry)

tests/
  conformance/      βœ… 11/11 PASS
  adversarial/      βœ… 31/31 PASS
  typecheck/        βœ… 12/12 PASS
  certificate/      βœ… 10/10 PASS
  receipts/         βœ… 8/8 PASS
  refinement/       βœ… 5/5 PASS
  fuzzing/          βœ… libFuzzer harness

docs/               User and developer guides
```

## Contributing

See [DEVELOPER.md](docs/DEVELOPER.md) for:

- Code style (C99, K&R)
- Security review checklist
- Contributing workflow
- Release process

## License

Business Source License 1.1 β€” See [LICENSE](LICENSE)

---

**Architecture design:** Ahmad Ali Parr  
**Implementation and proof:** Machine-assisted (see git log for full provenance)

---

> Compute may be untrusted. Verification must be small enough to inspect.