Repository navigation
Expand file tree
/
Copy pathdriver.nim
More file actions
125 lines (107 loc) · 5.71 KB
/
Copy pathdriver.nim
File metadata and controls
125 lines (107 loc) · 5.71 KB
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
## Driver interface and the driver-generic core (spec:
## contracts/specs/derived-exo-2dc.spec.json, invariant 6).
##
## The core never interprets contribution bytes — drivers do. Rounds, the
## serialization domain, the threshold, and finality are all *driver-described*
## via describe(), never hardcoded in the core. The core treats a contribution as
## an opaque blob: it asks the driver to verify it and routes on the boolean result
## plus the descriptor, so a different driver (different round count / threshold /
## finality) needs no core change. Every driver is NAMED — contributions are bound
## to the member who made them (anonymous membership was retired, ADR-015).
##
## A stub driver lives here for the conformance probes; real drivers (Safe at
## P2, threshold at P6) implement the same interface.
import ../security/levels
export levels
type
FinalityType* = enum
finImmediate = "immediate"
finProbabilistic = "probabilistic"
finExternal = "external"
DriverDescriptor* = object
rounds*: int ## e.g. Safe r=1, FROST r=2 — never assumed
serializationDomain*: string ## domain tag for contribution bytes
finality*: FinalityType
threshold*: int ## accepted contributions needed to close a round
Contribution* = object
bytes*: seq[byte] ## OPAQUE to the core; only the driver reads it
Driver* = ref object of RootObj
proc securityLevel*(desc: DriverDescriptor): SecurityLevel =
## The null-ladder AUTHENTICATION level a driver provides (exo-1ec.5): every driver
## binds each contribution to the member who made it, so authentication is real. A
## driver governs neither confidentiality (the epoch layer) nor provenance (the log),
## so those axes stay null.
securityLevel(
axisLevel(rungReal, "bound identity (the driver verifies who contributed)"),
axisLevel(rungNull, "provenance is the log's, not the driver's"),
axisLevel(rungNull, "confidentiality is the epoch layer's, not the driver's"))
method describe*(d: Driver): DriverDescriptor {.base, gcsafe.} =
raise newException(CatchableError, "Driver.describe is abstract")
method verifyContribution*(d: Driver, c: Contribution, round: int): bool {.base, gcsafe.} =
raise newException(CatchableError, "Driver.verifyContribution is abstract")
method environment*(d: Driver): string {.base, gcsafe.} =
## The environment a signature under this driver is bound to (invariant 2's first
## field) — driver-described, never hardcoded in the core (invariant 6). A driver
## that settles on a chain names it (Safe: "eip155:<chainId>"); a room-native
## driver's decisions live in the room, so the default is "room".
"room"
method laterRoundsInApp*(d: Driver): bool {.base, gcsafe.} =
## Whether a member's contribution to a round after the first is the same in-app
## signature as their first, sent for them on the intents tick (liveNextRounds). A
## driver whose later rounds attest to something only another step can do (a Monero
## multisig: "my wallet signed after its check", exo-dcc.34.3) says no, and that step
## publishes the contribution itself.
true
# ── The driver-generic core: a round-based collection driven only by describe() ─
type Collection* = object
descriptor*: DriverDescriptor
round*: int ## 1-based current round
acceptedThisRound*: int
complete*: bool
proc startCollection*(driver: Driver, desc: DriverDescriptor): Collection =
## The core snapshots the driver's declared policy once; everything downstream
## reads from this descriptor, never from a hardcoded constant. `desc` is the policy
## for the proposal being collected (describeFor, exo-a90.2): a family whose parties
## are named in the effect declares its threshold per proposal.
result.descriptor = desc
result.round = 1
result.acceptedThisRound = 0
result.complete = false
proc startCollection*(driver: Driver): Collection =
## The family's one policy (describe()).
startCollection(driver, driver.describe())
proc submit*(col: var Collection, driver: Driver, c: Contribution) =
## Core routing. It does NOT read c.bytes. It asks the driver whether the
## contribution is valid this round, then advances round/finality purely from
## the descriptor. Round count and completion are describe()-derived.
if col.complete: return
let accepted = driver.verifyContribution(c, col.round) # only the driver reads bytes
if accepted:
inc col.acceptedThisRound
if col.acceptedThisRound >= col.descriptor.threshold:
if col.round >= col.descriptor.rounds:
col.complete = true
else:
inc col.round
col.acceptedThisRound = 0
# Core-observable policy, always sourced from the descriptor (never hardcoded).
proc roundCount*(col: Collection): int = col.descriptor.rounds
proc finalityHandling*(col: Collection): FinalityType = col.descriptor.finality
# ── Stub driver: a configurable descriptor + a byte-independent verify result ──
# The verify result is fixed by construction (not derived from bytes) so a probe
# can prove the CORE's routing is byte-independent while holding the driver's
# answer constant. Real drivers interpret the bytes here.
type StubDriver* = ref object of Driver
descriptor*: DriverDescriptor
verifyResult*: bool
method describe*(d: StubDriver): DriverDescriptor = d.descriptor
method verifyContribution*(d: StubDriver, c: Contribution, round: int): bool =
d.verifyResult
proc newStubDriver*(rounds = 1, threshold = 2, domain = "muster.stub.v1",
finality = finImmediate,
verifyResult = true): StubDriver =
StubDriver(
descriptor: DriverDescriptor(
rounds: rounds, serializationDomain: domain,
finality: finality, threshold: threshold),
verifyResult: verifyResult)