amuzetnoM commited on
Commit
9aeeb4a
·
verified ·
1 Parent(s): 2468627

Upload whitepaper/whitepaper-adam.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. whitepaper/whitepaper-adam.md +254 -0
whitepaper/whitepaper-adam.md ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # ADAM Protocol — Constitutional Program & Policy Engine
3
+
4
+ <p align="left">
5
+ <img src="https://img.shields.io/badge/Status-Stable-brightgreen?style=flat-square" alt="Status"/>
6
+ <img src="https://img.shields.io/badge/Chain-Base%20(EVM)-blue?style=flat-square" alt="Chain"/>
7
+ <img src="https://img.shields.io/badge/License-AGPL--3.0-blueviolet?style=flat-square" alt="License"/>
8
+ <img src="https://img.shields.io/badge/Admin-Timelock%2BSafe-orange?style=flat-square" alt="Admin"/>
9
+ <img src="https://img.shields.io/badge/Integrates-ARCxGovernor%2C%20EAS%2C%20MACI%2C%20RWA%20Registry-9cf?style=flat-square" alt="Integrates"/>
10
+ </p>
11
+
12
+ ---
13
+
14
+ **Version:** 1.0 BETA (hardened)
15
+
16
+ ## 0. Purpose & Scope
17
+
18
+ Deterministic, Wasm-sandboxed policy engine that gates proposal lifecycles, parameter diffs, and RWA updates via explicit guards, proofs, pre/post-conditions, 2FA, and bytecode allowlists. All paths auditable, fuel/memory bounded, replay-safe.
19
+
20
+ ## 1. Core Objects
21
+
22
+ * **Constitutional Program (CP):** Wasm (wasm32-unknown-unknown), pure/deterministic, fixed ABI, fuel+memory capped, no syscalls/time/random.
23
+ * **Policy Chain:** Ordered CP list per topic; each returns `ALLOW | DENY | AMEND(ChangeSet) | REQUIRE_2FA(hash)`. First terminal wins; default `DENY`.
24
+ * **ChangeSet:** Canonical param ops `{op:uint8 key:bytes32 val:bytes32}` where `op∈{1=setUint,2=setAddr,3=setBool}`; ABI-encoded array.
25
+ * **ProofBundle:** Deterministic CBOR (RFC 8949 Canonical) containing `easUIDs[]`, `oracleSigs[]`, `roleCountersign[]`, `payloadHash`, `snapshotBlock`; Host keccak256 over CBOR = `proofHash`.
26
+ * **Inter-Block 2FA:** Second, disjoint confirmation within `[min2FA,max2FA]` blocks via configured profile.
27
+
28
+ ## 2. Hooks & Topics
29
+
30
+ Hooks: `onSubmit`, `onVoteStart`, `onTally`, `onQueue`, `onExecute`, `onRwaUpdate`, `onEmergency`. Topics: `TREASURY, PARAMS, ENERGY, CARBON, GRANTS`. Each `(topic,hook)` has a Policy Chain.
31
+
32
+ ## 3. Host Evaluation Pipeline
33
+
34
+ 1. Governor/Executor calls Host `evaluate(hook,topic,proposalId,proofBundle,diff)`.
35
+ 2. Host builds immutable **Context** at `snapshotBlock`: topic config (WAD), eligibility snapshots, params, oracle state, EAS verifies, `proofHash`.
36
+ 3. Stream Context to CPs in order; stop on terminal verdict.
37
+ 4. AMEND → validate against allowlist/bounds; produce `newDiff`.
38
+ 5. REQUIRE\_2FA(h) → record pending hash and DENY for this step.
39
+ 6. Emit `VerdictEmitted`; queue/execute uses final, amended `diff`.
40
+
41
+ ## 4. Constitutional Invariants (hard)
42
+
43
+ * No fund movement without topic `TREASURY`.
44
+ * PARAMS must stay within `ParamBounds`; monotonic flags enforced.
45
+ * RWA updates require `(≥2-of-N) ∧ active-operator-stakes ∧ recency window met`.
46
+ * Emergency limited to `pause()` and `cancel()` only.
47
+ * If `pending2FA`, queue/execute blocked until satisfied within window and with disjoint signers.
48
+
49
+ ## 5. Wasm Sandbox & Metering
50
+
51
+ Fuel per call: `fuelMax` (config); memory cap: `<=256KiB`; floats disabled; only Host imports permitted; OOM/fuel-exhaust → `DENY`. `wasmHash=keccak256(code)` pinned in registry; upgrades via governance only.
52
+
53
+ ## 6. ABI (Solidity↔Wasm)
54
+
55
+ **Host→CP imports (read-only, deterministic):**
56
+
57
+ ```
58
+ getParam(bytes32)->bytes32
59
+ getTopicCfg(uint256)->bytes
60
+ getSnapshot(bytes32 addr,uint256 layerMask)->uint256
61
+ getQuorumReached()->bool
62
+ getSupermajorityReached()->bool
63
+ getOracleImpact(bytes32 addr,uint256 topic)->uint256
64
+ verifyEAS(bytes32 uid)->bool
65
+ getProofHash()->bytes32
66
+ getBlockTime()->uint64
67
+ ```
68
+
69
+ `getTopicCfg` returns canonical CBOR: `{qTotalWad,qTokenWad,qSbtWad,qRwaWad,supermajorityWad,votingDays,timelockDays,challengeHours}`.
70
+
71
+ **CP→Host exports (one per hook):**
72
+
73
+ ```
74
+ onSubmit(bytes ctx)->Verdict
75
+ onVoteStart(bytes ctx)->Verdict
76
+ onTally(bytes ctx)->Verdict
77
+ onQueue(bytes ctx)->Verdict
78
+ onExecute(bytes ctx)->Verdict
79
+ onRwaUpdate(bytes ctx)->Verdict
80
+ onEmergency(bytes ctx)->Verdict
81
+ ```
82
+
83
+ ## 7. Solidity Interfaces (authoritative)
84
+
85
+ ```solidity
86
+ interface IAdamHost{
87
+ event VerdictEmitted(uint256 indexed proposalId, bytes4 hook, uint8 verdict, bytes32 proofHash, bytes newDiff);
88
+ event Pending2FA(uint256 indexed proposalId, bytes4 hook, bytes32 hash);
89
+ event Satisfied2FA(uint256 indexed proposalId, bytes4 hook, bytes32 hash);
90
+ function evaluate(bytes4 hook, uint256 topicId, uint256 proposalId, bytes calldata proofBundle, bytes calldata diff) external returns (uint8 verdict, bytes memory newDiff);
91
+ }
92
+ interface IAdamRegistry{
93
+ event PolicySet(uint256 indexed topicId, bytes4 indexed hook, bytes32 policyId, uint8 order);
94
+ event PolicyRemoved(uint256 indexed topicId, bytes4 indexed hook, bytes32 policyId);
95
+ function setPolicy(uint256 topicId, bytes4 hook, bytes32 policyId, uint8 order) external;
96
+ function removePolicy(uint256 topicId, bytes4 hook, bytes32 policyId) external;
97
+ function policyChainOf(uint256 topicId, bytes4 hook) external view returns (bytes32[] memory);
98
+ }
99
+ interface IAdamPolicy{
100
+ function wasmHash() external view returns (bytes32);
101
+ function evaluate(bytes calldata ctx) external view returns (uint8 verdict, bytes memory data);
102
+ }
103
+ ```
104
+
105
+ ## 8. Storage Layout (stable)
106
+
107
+ ```
108
+ AdamHost:
109
+ address timelock
110
+ address executor
111
+ address governor
112
+ address eas
113
+ address rwaRegistry
114
+ mapping(uint256=>mapping(bytes4=>bytes32[])) chain
115
+ mapping(uint256=>mapping(bytes4=>bytes32)) pending2FAHash
116
+ mapping(bytes32=>bool) usedEasUID
117
+ uint64 min2FABlocks, max2FABlocks
118
+ bytes32[] paramAllowlist
119
+ mapping(bytes32=>ParamBounds){uint256 min,max;bool monoUp;bool monoDown;}
120
+ uint32 fuelMax
121
+ uint32 memMax
122
+ ```
123
+
124
+ ## 9) Exact Semantics
125
+
126
+ * **evaluate(...)**: decode deterministic CBOR proof; reject if any UID `usedEasUID[uid]==true`; EAS.verify(uid)==true; mark UIDs used for this evaluation only when verdict != DENY OR when 2FA satisfied (prevents grief replay). Iterate chain; on AMEND run `validateChangeSet` (allowlist/bounds); return `(verdict,newDiff)`.
127
+ * **Queue/Execute 2FA**: if `pending2FAHash[proposal,hook]!=0`, require 2FA proof where `keccak(proofBundle)==pending` and `block.number ∈ [min2FA,max2FA]` and signer set disjointness enforced by profile (e.g., SBT-only quorum or `EAS:PolicyCounterSign_v1`). Clear pending and allow.
128
+ * **Disjointness**: dual-quorum profile enforces second step uses SBT-layer-only weights; EAS profile enforces attesters not in first attester-set (CP stores first-set hash in pending).
129
+
130
+ ## 10) Policy Examples (canonical)
131
+
132
+ * **ParamsGuard:** ALLOW iff all ops within bounds/monotonic; else DENY.
133
+ * **TreasuryLimiter:** ALLOW iff epoch outlay + requested ≤ cap; requires `GRANTS` refUID if tag present.
134
+ * **RWARecency:** ALLOW iff each oracle proof within topic recency `R_k` and operator SLA ≥ threshold; else DENY.
135
+ * **Dual2FA:** REQUIRE\_2FA(proofHash) on high-impact keys; else pass through.
136
+
137
+ ## 11) 2FA Profiles
138
+
139
+ * **DUAL\_QUORUM:** Pass 1: TOKEN+SBT; Pass 2: SBT-only quorum within window.
140
+ * **EAS\_AUDITOR:** Pass 2 requires attestation `PolicyCounterSign_v1` from auditor set.
141
+ * **ORACLE\_SPLIT:** Pass 2 requires disjoint oracle-operator set signatures.
142
+
143
+ ## 12) Allowlist & Bounds
144
+
145
+ `ParamBounds{min,max,monoUp,monoDown}` keyed by `bytes32`. Only keys in `paramAllowlist` may be amended by CPs; others must be direct proposals. Bounds in WAD for numeric keys; adapters map to native units where needed.
146
+
147
+ ## 13) Events & Errors
148
+
149
+ Errors: `PolicyFail()`, `NotGovernor()`, `OutOfBounds()`, `DisjointQuorumRequired()`, `TwoFAWindow()`, `ProofHashMismatch()`, `DiffNotAllowed()`, `WasmTrap()`, `FuelExceeded()`, `MemExceeded()`, `UIDReplay()`.
150
+
151
+ ## 14) Security Model
152
+
153
+ Wasm code pinned by `wasmHash`; Host has no `delegatecall`; Executor allowlist-only; proofs single-use; bounded loops; OOG protection via batching; revert/trap→`DENY`; formal invariants hold irrespective of CP behavior.
154
+
155
+ ## 15) On-Chain Config JSON (WAD strings)
156
+
157
+ ```
158
+ {
159
+ "adam":{
160
+ "version":"1.2.0",
161
+ "fuelMax": 2000000,
162
+ "memMax": 262144,
163
+ "policyChains":{
164
+ "TREASURY":{"onTally":["0xPOLICY_TREASURY_LIMIT"],"onQueue":["0xPOLICY_DUAL2FA"]},
165
+ "PARAMS":{"onTally":["0xPOLICY_PARAMS_GUARD"]},
166
+ "ENERGY":{"onRwaUpdate":["0xPOLICY_RWA_RECENCY","0xPOLICY_DUAL2FA"]},
167
+ "CARBON":{"onRwaUpdate":["0xPOLICY_RWA_RECENCY","0xPOLICY_DUAL2FA"]},
168
+ "GRANTS":{"onTally":["0xPOLICY_GRANTS_BUDGET"]}
169
+ },
170
+ "twoFA":{"minBlocks":2,"maxBlocks":7200,"profiles":["DUAL_QUORUM","EAS_AUDITOR"]},
171
+ "allowlist":["ENERGY_CAP","CARBON_CAP","FEE_BPS","QUORUM_PCT"],
172
+ "bounds":{
173
+ "FEE_BPS":{"min":"0","max":"500","monoUp":false,"monoDown":false},
174
+ "QUORUM_PCT":{"min":"30000000000000000","max":"200000000000000000","monoUp":true,"monoDown":false}
175
+ }
176
+ }
177
+ }
178
+ ```
179
+
180
+ ## 16) Tests & Formal Methods
181
+
182
+ Unit/property: deterministic verdicts; AMEND within bounds; 2FA windows; disjointness; UID single-use; AMEND encoding/decoding.
183
+ Fuzz: malformed CBOR, adversarial diffs, Wasm fuel/mem exhaustion, chain reorderings.
184
+ Invariants (TLA+/Scribble): I1 no TREASURY→no funds; I2 bounds/monotonic; I3 RWA `(2-of-N ∧ stake ∧ recency)`; I4 pending2FA blocks queue/execute unless satisfied; I5 emergency only pause/cancel.
185
+
186
+ ## 17) Reference Wasm Policy Skeleton (Rust, no comments)
187
+
188
+ ```rust
189
+ #![no_std]
190
+ #[no_mangle] pub extern "C" fn onTally(ctx_ptr:*const u8, ctx_len:usize)->u32{ 1 }
191
+ ```
192
+
193
+ ## 18) Reference Host/Registry Skeleton (no comments)
194
+
195
+ ```solidity
196
+ pragma solidity ^0.8.24;
197
+ interface IAdamPolicy{function evaluate(bytes calldata ctx) external view returns(uint8,bytes memory);}
198
+ contract AdamRegistry{
199
+ mapping(uint256=>mapping(bytes4=>bytes32[])) public chain;
200
+ event PolicySet(uint256 indexed t,bytes4 indexed h,bytes32 indexed id,uint8 o);
201
+ function setPolicy(uint256 t,bytes4 h,bytes32 id,uint8 o) external { chain[t][h].push(id); emit PolicySet(t,h,id,o); }
202
+ function policyChainOf(uint256 t,bytes4 h) external view returns(bytes32[] memory){ return chain[t][h]; }
203
+ }
204
+ contract AdamHost{
205
+ address public governor; address public timelock; address public executor; address public eas; address public rwaRegistry;
206
+ uint64 public min2FABlocks=2; uint64 public max2FABlocks=7200; uint32 public fuelMax=2_000_000; uint32 public memMax=262_144;
207
+ mapping(uint256=>mapping(bytes4=>bytes32[])) public chain; mapping(uint256=>mapping(bytes4=>bytes32)) public pending2FAHash;
208
+ mapping(bytes32=>bool) public usedEasUID;
209
+ event VerdictEmitted(uint256 indexed p,bytes4 h,uint8 v,bytes32 ph,bytes nd);
210
+ function evaluate(bytes4 h,uint256 t,uint256 p,bytes calldata proof,bytes calldata diff) external returns(uint8,bytes memory){
211
+ bytes32 ph = keccak256(proof); uint8 v=1; bytes memory nd=diff; emit VerdictEmitted(p,h,v,ph,nd); return (v,nd);
212
+ }
213
+ }
214
+ ```
215
+
216
+ ## 19) Rollout
217
+
218
+ T-2w publish ABI/bounds/allowlist; deploy Registry/Host; register policies; shadow-run. T-1w enable PARAMS; shadow TREASURY/RWA. T-0 bind Host to Governor, enable 2FA; emit config. T+2w audit; extend policies.
219
+
220
+ ## 20) Changelog
221
+
222
+ v1.2 — Canonical CBOR proofs; stricter UID lifecycle; hook-scoped chains; disjointness enforcement; hardened storage/types; fuel/mem caps; WAD-aligned bounds; expanded events/errors; code skeletons.
223
+
224
+ ## Community & Governance
225
+
226
+ - [ ] Community Guidelines
227
+ - [ ] Governance Structure
228
+ - [ ] Decision-Making Processes
229
+ - [ ] Conflict Resolution Mechanisms
230
+ - [ ] Engagement & Communication Strategies
231
+ - [ ] Community Feedback & Iteration Processes
232
+ - [ ] Inclusivity & Diversity Initiatives
233
+ - [ ] Continuous Improvement Mechanisms
234
+ - [ ] Community Building Activities
235
+ - [ ] Knowledge Sharing & Education Initiatives
236
+ - [ ] Feedback Loops & Iterative Development
237
+ - [ ] Community Recognition & Incentives
238
+ - [ ] Community Representation & Advocacy
239
+ - [ ] Community Engagement & Outreach
240
+ - [ ] Community Resources & Support
241
+ - [ ] Community Tools & Infrastructure
242
+ - [ ] Community Events & Activities
243
+ - [ ] Community Sustainability & Environmental Initiatives
244
+ - [ ] Community Health & Wellbeing Initiatives
245
+ - [ ] Community Safety & Security Initiatives
246
+ - [ ] Community Empowerment & Capacity Building
247
+ - [ ] Community Innovation & Experimentation
248
+ - [ ] Community Resilience & Adaptability
249
+ - [ ] Community Building & Networking Initiatives
250
+ - [ ] Community Mentorship & Support Programs
251
+ - [ ] Community Resource Sharing & Collaboration
252
+ - [ ] Community Advocacy & Representation Initiatives
253
+ - [ ] Community Digital Literacy & Skills Development
254
+ - [ ] Community Access & Inclusion Initiatives