Skip to content

Commit 775b2c8

Browse files
authored
docs: align ADN documentation with v3 contract implementation
1 parent 3361bc8 commit 775b2c8

1 file changed

Lines changed: 21 additions & 259 deletions

File tree

docs/v3/CONTRACT.md

Lines changed: 21 additions & 259 deletions
Original file line numberDiff line numberDiff line change
@@ -1,278 +1,40 @@
11
# 🔐 ADN — Shield Contract v3
2-
32
**Component:** ADN (Active Defence Network)
4-
**Contract Version:** `3`
5-
**Repository:** DigiByte-ADN (formerly DigiByte-ADN-v2)
6-
**License:** MIT
7-
**Author:** DarekDGB
8-
9-
---
10-
11-
## Purpose
12-
13-
This document defines the **public, contract-facing interface** of ADN under **Shield Contract v3**.
14-
15-
The v3 contract exists to ensure that ADN is:
16-
- **Fail-closed** (invalid input is rejected)
17-
- **Deterministic** (same input → same output → same `context_hash`)
18-
- **Auditable** (behavior is enforced by tests)
19-
- **Non-consensus** (ADN does not modify DigiByte rules)
20-
- **Read-only with respect to keys** (ADN never signs)
21-
22-
This contract is designed to survive review from skeptical engineers who only trust:
23-
- schema
24-
- tests
25-
- deterministic output behavior
26-
27-
---
28-
29-
## Core Guarantees (v3)
30-
31-
### 1) Hard Version Gate
32-
Any request where `contract_version != 3` **MUST fail closed**.
33-
34-
### 2) Fail-Closed by Default
35-
Invalid requests **MUST** return:
36-
- `decision: "ERROR"`
37-
- `meta.fail_closed: true`
38-
- a v3 reason code explaining the rejection
39-
40-
### 3) Strict Schema
41-
- Unknown **top-level** keys are rejected.
42-
- Unknown **event-level** keys are rejected.
43-
- NaN / Infinity values are rejected.
44-
- Oversized requests are rejected.
45-
46-
### 4) Deterministic Outputs
47-
`context_hash` is computed from stable input fields and decision results.
48-
49-
**Never include**:
50-
- timestamps
51-
- latency values
52-
- random identifiers
53-
- host state
54-
55-
### 5) No Signing, No Execution
56-
ADN:
57-
- does **not** hold keys
58-
- does **not** sign transactions
59-
- does **not** execute wallet actions
60-
- does **not** change chain consensus rules
3+
**Contract Version:** 3
4+
**Authoritative Package:** `adn_v3`
615

62-
ADN outputs **defensive decisions and recommended actions only**.
6+
This document is **normative** for ADN v3 contract behavior.
637

648
---
659

66-
## Request Contract (v3)
10+
## Public API
6711

68-
### Top-Level Schema
69-
70-
```json
71-
{
72-
"contract_version": 3,
73-
"component": "adn",
74-
"request_id": "string",
75-
"events": [ ... ]
76-
}
12+
```python
13+
from adn_v3 import ADNv3
14+
v3 = ADNv3()
15+
response = v3.evaluate(request_dict)
7716
```
7817

79-
### Field Requirements
80-
81-
- `contract_version` (int)
82-
- MUST equal `3`
83-
- `component` (string)
84-
- MUST equal `"adn"`
85-
- `request_id` (string)
86-
- REQUIRED
87-
- SHOULD be stable and caller-supplied
88-
- `events` (array)
89-
- REQUIRED
90-
- MAY be empty (but still valid)
91-
- MUST not exceed **MAX_EVENTS** (default: 200)
92-
93-
### Unknown Key Rejection
94-
95-
- Any unknown top-level key → fail-closed
96-
- Any unknown event-level key → fail-closed
97-
9818
---
9919

100-
## Event Schema (v3)
101-
102-
Each element in `events[]` MUST be a JSON object containing **only**:
103-
104-
```json
105-
{
106-
"event_type": "string",
107-
"severity": 0.0,
108-
"source": "string",
109-
"metadata": {}
110-
}
111-
```
112-
113-
### Event Fields
20+
## Request schema
11421

115-
- `event_type` (string, required)
116-
- non-empty
117-
- `severity` (number, required)
118-
- range: `0.0 <= severity <= 1.0`
119-
- NaN/Infinity rejected
120-
- `source` (string, required)
121-
- non-empty
122-
- `metadata` (object, optional)
123-
- defaults to `{}` if missing or null
124-
- MUST be an object if present
125-
- serialized size MUST not exceed **MAX_METADATA_BYTES** (default: 16KB)
22+
Allowed top-level keys:
23+
- contract_version (must be 3)
24+
- component ("adn")
25+
- request_id
26+
- events
12627

127-
### Unknown Event Keys
128-
129-
Any extra keys (example: `"evil": "inject"`) **MUST fail closed**.
28+
Unknown keys fail closed.
13029

13130
---
13231

133-
## Oversize / Abuse Protection
134-
135-
ADN v3 enforces:
32+
## Fail-closed guarantees
13633

137-
- **MAX_EVENTS**: 200
138-
- **MAX_METADATA_BYTES**: 16,384 bytes (16KB), per event
139-
140-
If exceeded, ADN MUST fail closed with:
141-
- `decision: "ERROR"`
142-
- reason code `ADN_ERROR_OVERSIZE`
143-
144-
---
145-
146-
## Response Contract (v3)
147-
148-
### Success Response (valid request)
149-
150-
```json
151-
{
152-
"contract_version": 3,
153-
"component": "adn",
154-
"request_id": "string",
155-
"context_hash": "sha256_hex",
156-
"decision": "ALLOW | WARN | BLOCK",
157-
"risk": {
158-
"level": "normal | elevated | high | critical",
159-
"lockdown_state": "none | partial | full"
160-
},
161-
"actions": [
162-
{
163-
"action_type": "string",
164-
"reason": "string",
165-
"metadata": {}
166-
}
167-
],
168-
"reason_codes": ["ADN_OK | ADN_V2_SIGNAL"],
169-
"evidence": {
170-
"active_events_count": 0
171-
},
172-
"meta": {
173-
"latency_ms": 0,
174-
"fail_closed": true
175-
}
176-
}
177-
```
178-
179-
### Error Response (fail-closed)
180-
181-
```json
182-
{
183-
"contract_version": 3,
184-
"component": "adn",
185-
"request_id": "string",
186-
"context_hash": "sha256_hex",
187-
"decision": "ERROR",
188-
"risk": { "level": "unknown", "lockdown_state": "unknown" },
189-
"actions": [],
190-
"reason_codes": ["<REASON_CODE>"],
191-
"evidence": { "details": { "error": "<REASON_CODE>" } },
192-
"meta": { "latency_ms": 0, "fail_closed": true }
193-
}
194-
```
195-
196-
---
197-
198-
## Decision Semantics
199-
200-
ADN maps internal defense state into contract decisions using **deny-by-default** rules:
201-
202-
- `lockdown_state == full``BLOCK`
203-
- `lockdown_state == partial``WARN`
204-
- otherwise by `risk.level`:
205-
- normal → ALLOW
206-
- elevated → WARN
207-
- high/critical → BLOCK
208-
209-
If uncertain → **BLOCK** (deny-by-default).
210-
211-
---
212-
213-
## Reason Codes (Contract-Facing)
214-
215-
Minimal, stable v3 reason codes:
216-
217-
### Normal outcome
218-
- `ADN_OK`
219-
- `ADN_V2_SIGNAL` (valid request produced a defensive signal)
220-
221-
### Fail-closed errors
222-
- `ADN_ERROR_SCHEMA_VERSION`
223-
- `ADN_ERROR_INVALID_REQUEST`
224-
- `ADN_ERROR_UNKNOWN_KEY`
225-
- `ADN_ERROR_BAD_NUMBER`
226-
- `ADN_ERROR_EVENT_UNKNOWN_KEY`
227-
- `ADN_ERROR_OVERSIZE`
228-
229-
---
230-
231-
## Context Hash Rules (Deterministic)
232-
233-
`context_hash` MUST be computed from stable fields only.
234-
235-
Allowed inputs:
236-
- `component`
237-
- `contract_version`
238-
- `request_id`
239-
- `events` (canonical request form)
240-
- `node_defense_config` fingerprint
241-
- `decision`, `risk`, `actions`, `reason_codes`
242-
243-
Forbidden inputs:
244-
- timestamps
245-
- latency values
246-
- random data
247-
- environment-dependent values
248-
249-
---
250-
251-
## Non-Goals / Explicit Forbidden Powers
252-
253-
ADN MUST NOT:
254-
- sign anything
255-
- generate keys
256-
- transmit private material
257-
- modify node consensus behavior
258-
- interfere with block acceptance rules
259-
- claim to “stop quantum attacks” by itself
260-
261-
ADN provides:
262-
> **decisions + recommended defensive actions**
263-
not authority, not execution, not consensus.
264-
265-
---
266-
267-
## Test Enforcement
268-
269-
This contract is enforced by CI tests which prove:
270-
- version gating fails closed
271-
- unknown keys rejected (top-level and event-level)
272-
- NaN/Infinity rejected
273-
- oversize rejected (events and metadata)
274-
- behavior remains consistent via v2→v3 no-drift regression locks
275-
276-
If tests fail, the contract is considered broken.
34+
Any invalid request returns:
35+
- decision = ERROR
36+
- meta.fail_closed = True
37+
- explicit reason_codes
27738

27839
---
40+
**Author:** DarekDGB

0 commit comments

Comments
 (0)