File size: 10,107 Bytes
9425aed | 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 | // seb_policy.dl β SEB Sovereign Policy Engine (Souffle)
//
// Cherry-picked from systemic-intelligence/datalog/ and merged with
// SEB_SOVEREIGN_EVENT_BUS_MASTER_SPECIFICATION.xml L3 layer.
//
// Three source layers combined:
// 1. systemic-intelligence authority rules (who can do what)
// 2. systemic-intelligence base facts (actor/capability/target registry)
// 3. SEB master spec policy strata (plasma gate, fiscal gate, kernel_authorize)
//
// Actor β SEB Agent mapping:
// 1 "bob" β devops_001 (execute, write) β INFRA_PROVISION, CONFIG_DEPLOY
// 2 "metatron" β arch_001 (read, verify) β ARCH_DECISION
// 3 "edaulc" β treasury_001 (observe) β PROBLEM_SOLVED, ATTACK_DETECTED
// 4 "autonomous" β council_001 (vacuum_collapse) β SOVEREIGN_ROOT
//
// Compile: souffle -c seb_policy.dl -o seb_policy
// Link: shared lib for Erlang port (seb_datalog_bridge.erl)
// ββ TYPE DECLARATIONS ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
.type AgentID = symbol
.type ActorNum = number
.type EventID = unsigned
.type Hash32 = symbol
.type Capability = symbol
.type EventType = unsigned
.type Weight = unsigned
// ββ BASE FACTS (from systemic-intelligence/datalog/facts/base.dl) βββββββββ
// Mapped to SEB agent registry (GenesisConfig.toml)
.decl actor(id: ActorNum, name: AgentID)
actor(1, "bob"). // devops_001
actor(2, "metatron"). // arch_001
actor(3, "edaulc"). // treasury_001 / shadow builder
actor(4, "autonomous"). // council_001
.decl capability(actor_id: ActorNum, cap: Capability)
capability(1, "execute").
capability(1, "write").
capability(2, "read").
capability(2, "verify").
capability(3, "observe").
capability(4, "vacuum_collapse").
.decl target(id: number, resource: symbol)
target(100, "memory").
target(101, "stack").
target(102, "entropy_pool").
target(200, "seb_chain"). // SEB WORM chain
target(201, "seb_partition"). // SEB partition
target(202, "seb_fiscal"). // SEB fiscal ledger
.decl precondition_met(actor_id: ActorNum, target_id: number)
precondition_met(1, 100).
precondition_met(1, 101).
precondition_met(1, 200). // bob can write to chain
precondition_met(1, 201). // bob can write to partition
precondition_met(2, 100).
precondition_met(2, 200). // metatron can read chain
precondition_met(3, 200). // edaulc observes chain
precondition_met(4, 102).
precondition_met(4, 202). // council controls fiscal
// ββ AUTHORITY RULES (from systemic-intelligence/datalog/rules/authority.dl)
.decl si_authorized(actor_id: ActorNum, target_id: number, cap: Capability)
.decl si_denied(actor_id: ActorNum, target_id: number, reason: symbol)
si_authorized(A, T, C) :-
actor(A, _),
capability(A, C),
target(T, _),
precondition_met(A, T).
si_denied(A, T, "no_capability") :-
actor(A, _),
target(T, _),
!capability(A, _).
si_denied(A, T, "precondition_failed") :-
actor(A, _),
capability(A, _),
target(T, _),
!precondition_met(A, T).
// ββ SEB INPUT FACTS (populated by Erlang runtime) βββββββββββββββββββββββββ
.decl agent_competency(a: AgentID, c: Capability)
.decl agent_status(a: AgentID, s: symbol)
.decl event_schema(t: EventType, schema_hash: Hash32, req_cap: Capability, weight: Weight)
.decl event_header(offset: EventID, agent: AgentID, etype: EventType,
prev_hash: Hash32, event_hash: Hash32, sig: symbol, payload_hash: Hash32)
.decl bifrost_confirmed(offset: EventID)
// Bridge systemic-intelligence actors to SEB agents
agent_competency("bob", "execute") :- capability(1, "execute").
agent_competency("bob", "write") :- capability(1, "write").
agent_competency("metatron", "read") :- capability(2, "read").
agent_competency("metatron", "verify") :- capability(2, "verify").
agent_competency("edaulc", "observe") :- capability(3, "observe").
agent_competency("autonomous", "vacuum_collapse") :- capability(4, "vacuum_collapse").
// ββ STRATUM 1: PLASMA GATE + WORM INTEGRITY ββββββββββββββββββββββββββββββββ
.decl verified_agent(a: AgentID, offset: EventID)
verified_agent(A, O) :-
event_header(O, A, _, _, EH, Sig, PH),
ed25519_verify(A, EH, Sig),
lattice_verify(PH, EH), // GF(2^8) lattice circuit replaces blake3
bifrost_confirmed(O).
// ββ STRATUM 2: COMPETENCY ROUTING βββββββββββββββββββββββββββββββββββββββββ
.decl authorized(a: AgentID, offset: EventID)
authorized(A, O) :-
verified_agent(A, O),
event_header(O, _, ET, _, _, _, _),
event_schema(ET, _, C, _),
agent_competency(A, C),
agent_status(A, "active"),
!agent_status(A, "revoked").
// ββ STRATUM 3: CONSTITUTIONAL GATE (from SEB_Constitution.agda) βββββββββββ
// Maps Agda Verdict to Datalog fact.
// denied-no-exec theorem: if constitution_denied(A,O) then !kernel_authorize(A,O)
.decl constitution_denied(a: AgentID, offset: EventID, reason: symbol)
// Capability mismatch (Theorem 4: wrong-cap-denied)
constitution_denied(A, O, "capability_mismatch") :-
event_header(O, A, ET, _, _, _, _),
event_schema(ET, _, ReqCap, _),
!agent_competency(A, ReqCap).
// SOVEREIGN_ROOT requires vacuum_collapse exclusively (Theorem 5)
constitution_denied(A, O, "requires_vacuum_collapse") :-
event_header(O, A, 0xFFFF, _, _, _, _), // SOVEREIGN_ROOT = 0xFFFF
!agent_competency(A, "vacuum_collapse").
// ββ STRATUM 4: FISCAL GATE βββββββββββββββββββββββββββββββββββββββββββββββββ
.decl fiscal_ok(a: AgentID, offset: EventID)
fiscal_ok(A, O) :-
event_header(O, _, ET, _, _, _, _),
event_schema(ET, _, _, W),
W != 0xFFFFFFFF.
fiscal_ok(A, O) :-
event_header(O, _, ET, _, _, _, _),
event_schema(ET, _, _, W),
W = 0xFFFFFFFF,
treasury_balance(A, B),
B >= W.
// ββ STRATUM 5: FINAL AUTHORIZATION GATE βββββββββββββββββββββββββββββββββββ
.decl kernel_authorize(a: AgentID, offset: EventID)
kernel_authorize(A, O) :-
authorized(A, O),
fiscal_ok(A, O),
!constitution_denied(A, O, _). // Constitution gates must all pass
// ββ STRATUM 6: P/NP CONVERGENCE EVENTS (from seb_pnp_bridge.erl) βββββββββ
.decl convergence_event(offset: EventID, event_type: symbol, delta: float)
.decl attack_condition(reason: symbol)
attack_condition("negative_universe_sum") :-
convergence_event(_, "attack_detected", D),
D < 0.0.
// ββ OUTPUT RELATIONS βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
.decl si_actor_authorized(name: AgentID, resource: symbol)
si_actor_authorized(N, R) :-
actor(A, N),
target(T, R),
si_authorized(A, T, _).
.output kernel_authorize
.output si_authorized
.output si_denied
.output constitution_denied
.output attack_condition
.output si_actor_authorized
// ββ EXTERNAL PRIMITIVES (Erlang port provides these) ββββββββββββββββββββββ
.external ed25519_verify(pubkey: symbol, msg: symbol, sig: symbol) : bool
.external lattice_verify(prev_hash: symbol, event_hash: symbol) : bool
.external treasury_balance(agent: symbol, balance: unsigned) : bool
// __ STRATUM 7: FLOATING AGENT DETECTION ____________________________________
// Cherry-picked from exo-synchronicity/logic/datalog/reachability.dl
//
// A floating_agent is an actor that exists in the registry but is never
// authorized for any target or event type.
// This is the Datalog version of exo-synchronicity's floating_port:
// floating_port(p) :- bound_port(p), !reachable("sigma", p)
// Here: floating_agent(A) :- actor(A,_), !si_authorized(A,_,_)
//
// Floating agents are a configuration error: they consume a partition slot
// but can never emit or receive events. Detected at policy compile time.
.decl floating_agent(a: AgentID, reason: symbol)
.decl reachable_agent(a: AgentID)
// An agent is reachable if it has at least one authorized action
reachable_agent(A) :- si_authorized(Num, _, _), actor(Num, A).
reachable_agent(A) :- kernel_authorize(A, _).
// A floating agent exists in registry but has no authorized path
floating_agent(A, "no_authorized_target") :-
actor(_, A),
!reachable_agent(A).
// An agent is floating if their only capability is revoked
floating_agent(A, "all_capabilities_revoked") :-
actor(_, A),
agent_status(A, "revoked").
// Transitive reachability: if A can authorize B's action, A is not floating
// (mirrors reachable(a,b) :- edge(a,b) from exo-synchronicity)
.decl agent_edge(from_agent: AgentID, to_agent: AgentID)
agent_edge(A, B) :-
kernel_authorize(A, O),
event_header(O, B, _, _, _, _, _).
.decl agent_reachable(a: AgentID, b: AgentID)
agent_reachable(A, B) :- agent_edge(A, B).
agent_reachable(A, C) :- agent_reachable(A, B), agent_edge(B, C).
.output floating_agent
.output reachable_agent
// __ STRATUM 8: P/NP CONVERGENCE EVENTS ____________________________________
// (from seb_pnp_bridge.erl integration)
.decl convergence_event(offset: EventID, etype: symbol, delta: float)
.decl attack_condition(reason: symbol)
attack_condition("negative_universe_sum") :-
convergence_event(_, "attack_detected", D),
D < 0.0.
.output attack_condition
|