Commit 2f1fd39
authored
feat(frost/roast): RFC-21 Phase 3.1 -- coordinator skeleton + seed bridge (#3968)
## Summary
First Phase-3 implementation PR for **RFC-21**. Introduces the ROAST
coordinator state-machine surface (`Coordinator` interface, in-memory
implementation, attempt-handle identity, state enum) plus the sterile
seed-folding adapter that lets the new `[32]byte` `AttemptSeed` drive
the legacy `SelectCoordinator` helper without modifying it.
**No production code path uses the new \`Coordinator\` yet.** Phase 3
"ships unused" per the RFC. Phase 4 wires it into receivers behind the
\`frost_roast_retry\` build tag.
## What lands
### \`pkg/frost/roast/coordinator_state.go\`
| Surface | Role |
|---|---|
| \`AttemptState\` enum | \`Pending / Collecting / Aggregating /
Succeeded / Transitioned\` with \`String()\`. |
| \`AttemptHandle\` | Opaque per-attempt identity. \`ContextHash()\`
accessor cross-checks the bound context. |
| \`Coordinator\` interface | \`BeginAttempt(ctx) → handle\`,
\`State(handle) → state\`, \`SelectedCoordinator(handle) → member\`.
Later Phase-3 PRs (3.2 / 3.3 / 3.4) extend with \`TransitionMessage\`,
\`AggregateBundle\`, \`VerifyBundle\`, and \`NextAttempt\`. |
| \`NewInMemoryCoordinator()\` | Concurrent-safe via \`sync.Mutex\` +
\`atomic.Uint64\` next-id counter. |
| \`ErrUnknownAttempt\` | Sentinel for handle/instance mismatch. |
### \`pkg/frost/roast/seed_bridge.go\`
| Surface | Role |
|---|---|
| \`foldAttemptSeed(seed [32]byte) int64\` | First 8 bytes BE → int64
reinterpretation. Sterile, named, non-cryptographic adapter. Documented
contract: byte-identical input must produce byte-identical output on
every honest signer. |
\`BeginAttempt\` calls \`foldAttemptSeed\` and forwards to the existing
\`SelectCoordinator\` to elect the attempt's coordinator. The legacy
helper itself is **not modified** -- the bridge is the only thing
between RFC-21 contexts and the legacy seed format.
## Why the seed bridge
The legacy \`SelectCoordinator\` takes \`(seed int64, attemptNumber
uint)\`
and is correct in isolation. RFC-21 widens \`AttemptSeed\` to
\`[32]byte\` for the canonical-hash binding. We could rewrite the
shuffle, but rewriting cryptographic-consensus logic that already
agrees across the network is the wrong trade-off; the audit and
behaviour are settled.
The bridge satisfies the resolved decision in RFC-21:
> \"BeginAttempt wraps it with a sterile bridge that folds the new
> [32]byte AttemptSeed into the legacy parameter shape... The bridge
> is named, isolated, and exhaustively tested so later edits cannot
> accidentally desynchronise it.\"
## Test coverage
### \`coordinator_state_test.go\` (9 tests)
- \`TestBeginAttempt_ReturnsHandleWithMatchingContextHash\`
- \`TestBeginAttempt_HandlesAreDistinctAcrossAttempts\`
- \`TestBeginAttempt_RejectsEmptyIncludedSet\` (defence-in-depth)
- \`TestState_ReturnsCollectingAfterBegin\`
- \`TestState_UnknownHandleReturnsSentinel\`
- \`TestSelectedCoordinator_ReturnsMemberFromIncludedSet\`
- \`TestSelectedCoordinator_IsDeterministicForSameContext\` -- two
independent \`Coordinator\` instances agree on the elected member
-
\`TestSelectedCoordinator_DifferentAttemptNumbersCanProduceDifferentLeaders\`
-- 16 attempts produce ≥2 distinct leaders, defending the ROAST
leader-rotation property
- \`TestSelectedCoordinator_UnknownHandleReturnsSentinel\`
- \`TestInMemoryCoordinator_ConcurrentBeginAttemptsAreRaceSafe\` --
16 goroutines × 50 calls each, all handles unique
- \`TestAttemptState_String\` -- all enum values + unknown sentinel
### \`seed_bridge_test.go\` (5 tests)
- \`TestFoldAttemptSeed_IsDeterministic\`
- \`TestFoldAttemptSeed_TakesFirst8BytesBigEndian\` -- specific
byte pattern verified
- \`TestFoldAttemptSeed_IgnoresBytesAfterIndex7\` -- documents the
contract: bytes 8..31 don't influence output (still bound at
the \`AttemptContext.Hash()\` layer)
- \`TestFoldAttemptSeed_FirstByteSwept\` -- 256-value sweep of the
high byte produces 256 distinct outputs (no collisions)
- \`TestFoldAttemptSeed_GoldenFixture\` -- literal int64 value
locks the wire-format reduction; literal drift caught at
code review
### Verification
| Command | Result |
|---|---|
| \`go build ./...\` | clean |
| \`go test ./pkg/frost/roast/...\` | pass (14 cases) |
| \`go test -race ./pkg/frost/roast/...\` | pass |
| \`go test -tags 'frost_native frost_tbtc_signer' ./pkg/frost/...\` |
pass (5 packages) |
| \`staticcheck -checks '-SA1019' ./pkg/frost/roast/...\` | silent |
| \`go vet ./pkg/frost/roast/...\` | clean |
## Test plan
- [ ] CI green.
- [ ] Reviewer confirms the seed bridge's discard of bytes 8..31 is
acceptable. (Bytes 8..31 still appear in \`AttemptContext.Hash()\`,
so any mutation is detected at the protocol-message layer in
Phase 1B; the bridge merely reduces 256-bit input to the 64-bit
width \`SelectCoordinator\` needs.)
- [ ] Reviewer confirms the \`Coordinator\` interface scope is
appropriate for Phase 3.1 (state surface only). Phase 3.2 will
extend with \`TransitionMessage\` types.
Refs RFC-21 Phase 3 (\`docs/rfc/rfc-21-*\`). Stacked at the integration
tip after #3967 merged.4 files changed
Lines changed: 606 additions & 0 deletions
File tree
- pkg/frost/roast
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments