### U7. Every signer derives `D_sign` itself and checks the coordinator's against it
`sign_session_init` stays a local computation from the installed RPD and KSD, the selection, the
tweaks and the session id. A new `sign_session_check` compares the coordinator's `D_sign` bytes
with the local one. That is F-25's signer-side validation as a function rather than prose. A
caller cannot reach `signer_nonce_gen` without a session it built itself.
### U8. Every message gets a canonical encoding, including the ones that lack one
New encodings:
| message | format |
|---|---|
| authorization or acknowledgment list | `u32 count` followed by `count × (role8 ‖ sig64)`, in role order: the same 72-byte entries the certificate already uses |
| group partial | 36 bytes: `u32 group_id ‖ scalar32`, with serialize and parse |
| `confirmation_verify` | any | the above and the certificate | valid or not |
| `signer_partial` | each signer | signer state, share, and everything above | member partial, 32 bytes; the state is consumed first |
| `member_partial_verify` | group coordinator | one member partial and its index | valid or not |
| `group_partial_aggregate` | group coordinator | its group's member partials | group partial, 36 bytes (U8) |
| `group_partial_verify` | outer coordinator | one group partial | valid or not |
| `outer_aggregate` | outer coordinator | every group partial | BIP 340 signature under the tweaked key |
**Who is a group coordinator** is the caller's choice; the protocol requires none. Giza's Phase 14
picks the selected admin of each group with the lowest admin id, so every device knows it without a
round. Code and protocol differ on one point, and the header records it: there is no per-group
nonce aggregation step. The outer coordinator builds the transcript from every public nonce, and
every signer recomputes the aggregates (`sign_partial_impl.h:14`).
---
## What a Giza device stores, per role
This is the contract the header documents and [confederation.md](./confederation.md)'s Phase 11
builds to. Everything here is bytes, so nothing depends on the build that wrote it.
| after | store | erase |
|---|---|---|
| step 1 | own record; own ciphertext vector (until the coordinator has it) | the dealer seed, once the record is stored |
| step 2 | the broadcast | — |
| acknowledgment | the authorization list; the recovery nonce; the KSD | — (must be durable before acknowledging, U4) |
| finalization | the recovery package and the certified transition; the share stays recomputable | the broadcast and own record may go once the recovery package is stored |
| a signing attempt | public messages and the partial once sent (§8.5 allows resending, never recomputing) | the signer state, at abort, timeout or restart |
The host secret key is derived from the member's nsec on each use
([confederation.md](./confederation.md), Phase 10), so it is never stored.
---
## Phases
### Phase Z0: settle the protocol text the API will cite (zkp, docs only)
No code. The step API's header comments cite the protocol by section, so the sections have to say
what the code will do. Owned by the protocol owner, in `doc/confederation-protocol.md` and
`doc/confederation-implementation-plan.md` §3.7:
1. §7.4: the recipient derives the KSD and the genesis transition itself (U3).
2. §7.6: authorization, verify all, store durably, acknowledge, as separate calls (U4). Name what
"store durably" covers, which closes part of F-35.
3. §6.2 and §7.2: dealer-seed labels (U10), and that the seed is erased after the record is stored,
not after it is sent (U2).
4. §7.6: what happens to a pending genesis when another genesis installs. F-35 leaves this open.
5. §8.2 to §8.5: the signer state machine as the API states it (U6), and fresh randomness as a
required input. This is the text F-24 asks for.
6. §8.1: the signer-side checks `sign_session_check` performs (U7). This is F-25's list.
7. A new §3.8 in the implementation plan: the function table above, with the storage contract.
**Done when** the protocol owner has signed off the text, and F-24 and F-25 can be answered by
pointing at it.
### Phase Z1: bring the reference model and vectors up to the text (zkp, Python)
F-30 says the vectors "must not be used to test protocol code" until
`tools/test_vectors_confederation_generate.py` implements the revised text. Step tests are protocol
code tests, so this comes first.
1.**The model's DKG follows §7.4:** the recipient compares its own record, uses the recipient
pad, checks the digest in an investigation, and derives the KSD itself. Coefficients are drawn
in the code's order. If U10 changes the labels, the model follows.
2.**Per-step vectors** for the 3 × (2-of-3), T = 2 roster:
- role 0's record and ciphertexts;
- the broadcast;
- role 0's step-2 outputs (KSD, transition hash, authorization);
- the authorization and acknowledgment lists;
- the certificate;
- role 0's share check and recovery package;
- for signing: `D_sign`, the transcript, one confirmation, one member partial, one group partial
and the signature.
3.**Rejection vectors**, at least one per fault the API can return:
- a tampered record (`ROLE`, with its index);
- a broadcast whose sum is wrong (`COORDINATOR`, after investigation);
- a substituted own record (`COORDINATOR`);
- a bad authorization (`ROLE`);
- a `D_sign` with a different selection (refused by `sign_session_check`);
- a transcript missing the signer's nonce.
4. Regenerate `vectors.h` and `doc/confederation-vectors.json`.
**Done when** the model's outputs match the current code byte for byte on the happy path (they
already do for DKG artifacts, review §7.1), and every rejection vector is produced by the model
rather than by hand.
### Phase Z2: the DKG step API (zkp, C)
1.**Header.** Declarations in `include/secp256k1_confederation.h` under a new "Distributed DKG"
section. Its module comment lists the message flow as `secp256k1_chilldkg.h:14-47` does, and
says which inputs are secret and which outputs may be stored. One fault convention (U5).
2.**Implementation**, in a new `src/modules/confederation/dkg_api_impl.h`, as thin wrappers over
the existing statics:
-`participant_step1`: argument checks and the size convention; the step is unchanged.
-`coordinator_step1`: changed to report which dealer failed (U5). Its internal loop already
knows the index.
-`participant_step2`: a new composition of `broadcast_parse`, own-record comparison,
`derive_ksd`, `recipient_verify` (the share is cleansed before return), `genesis_prepare` and
`transition_evidence_sign` with the authorize tag.
-`participant_acknowledge`: `verify_authorizations` and then `transition_evidence_sign` with
the acknowledge tag.
-`participant_finalize`: recomputes the share with `recipient_verify` and continues as today.
- The evidence-list and investigation-request codecs (U8).
3.**Re-express `secp256k1_confederation_dkg`** over the public steps in protocol order (U9). Its
outputs for the fixed seeds must not change. The `dkg_fixed_*` vectors in
`run_confederation_api_test` are the check, and a change there means U3 or U4 changed a byte
they should not have.
4.**Stack.**`dkg_record` is about 17 KB, `transition_hash` uses a 43,976-byte buffer and
`params_hash` 32,020 (F-38). These now run on application threads, and a Kotlin/Native
background thread on iOS has 512 KB. Move the two hash preimages to streaming
`sha256_write` calls. They are hashes of a concatenation, so nothing needs the whole preimage at
once. Take F-38's 4-byte `PARAMS_MAX_SIZE` shortfall with it.
5.**Tests** (`tests_impl.h`, new `run_confederation_dkg_api_test`):
- every per-step vector from Z1;
- every rejection vector, checking the fault and index;
- **step-by-step equals one-process:** nine roles driven through the public steps, each role's
inputs and outputs copied through byte buffers only, reaching the same KSD, transition and
shares as `secp256k1_confederation_dkg`;
- **restart:** steps 1 and 2 run twice from the same stored inputs give identical bytes, and
finalization after "losing" the share recomputes the same one;
- **misuse:** an acknowledgment with an incomplete authorization list is refused; step 2 with
a foreign own record is refused; finalization with a transition for another KSD is refused;
- **investigation:** a coordinator that substitutes one summed ciphertext is named; a dealer
that sends one bad evaluation is named by index.
6.**Build plumbing.**
-`tools/symbol-check.py` and `tools/check-abi.sh` learn the new exports. `security.md`'s
"exports 30 functions" becomes the new count.
-`examples/confederation_distributed.c` uses only the public header and runs each role in its
own function, with nothing passed but byte buffers.
-`src/confederation_fuzz.c` gains the broadcast and evidence-list parsers.
**Done when**`./build/bin/tests --target=confederation` passes under the CMake and Autotools builds,
with sanitizers and Valgrind as in review §7.1, and the example runs.
### Phase Z3: the signing step API (zkp, C)
1.**Header.**
-`secp256k1_confederation_signer` becomes a public opaque type with the same "must not be
copied, read or written" text as `secp256k1_frost_secnonce`. Its magic and state stay internal.
-`secp256k1_confederation_sign_session` becomes public too. It can be copied: it holds no secret
and is recomputed from inputs.
- The function table above, with the group-partial codec.
2.**Implementation.** Wrappers over the statics, plus:
-`sign_session_check` (U7), which is `d_sign_check` made public;
-`signer_nonce_gen` takes the caller's randomness and wipes it (U6). It already wipes; the
change is that `sign()` no longer derives it (U9).
-`signer_partial` keeps its order: the state is consumed before the scalar is computed, as
today.
3.**Re-express `secp256k1_confederation_sign`** over the public steps. It now takes the
caller's per-signer randomness. The derived-randomness helper moves to the test harness with a
name that says it must not be copied.
4.**Tests** (`run_confederation_sign_api_test`):
- Z1's signing vectors, with the signature verifying under the tweaked key;
- every signer and both coordinator roles driven separately through byte buffers;
- **misuse:** a second confirmation from one state; a partial before confirmation; a partial
after abort; a nonce absent from the transcript; a certificate over a different message; a
`D_sign` with another selection. Each is refused, and the state is wiped;
`aggregateGroup`, `verifyGroup`, `aggregate`. A `signTaprootInput` helper sits beside
`Confederation.signTaprootInputLocal`.
- **Tests:**
- the steps across nine roles reach a signature `Crypto.verifySignatureSchnorr` accepts under
the tweaked key, and under the taproot output key;
- every Z3 misuse case through the Kotlin API;
-`ConfederationSigner` refuses a second use from two threads.
**Done when**`jvmTest` passes as in B1.
### Phase C1: carry it up to Giza
The procedure in [confederation-submodule-update.md](./confederation-submodule-update.md), with its
checks:
1. lightning-kmp: bump bitcoin-kmp. `:lightning-kmp-core:jvmTest` (`crypto` and `channel`) still
passes. `PrefractalSigner` uses FROST, which this work does not touch; re-check that zkp's FROST
sources are byte-identical across the bump, as that plan's Phase 0 does.
2. lightning-kmp-app: bump lightning-kmp. `:library:compileKotlinJvm` and `:library:compileAndroidMain`.
3. Giza: bump lightning-kmp-app.
-`compileDebugKotlinAndroid`, `jvmTest` and `check`.
- Extend `ConfederationReachableJvmTest` with a three-group run through `ConfederationDkg` and
`ConfederationSigning`, signing as the room's id. That proves the bound library, not only
the classes, reached the app.
- Android and desktop runs, and an iOS build on a Mac, where cinterop regenerates from the
header.
4. Land bottom up: push each child before its parent, and fast-forward `threshold` and `master`.
If [giza-wallet-removal.md](./giza-wallet-removal.md)'s Phase 7b has landed by then, Giza pins
bitcoin-kmp directly, and steps 1 to 3 collapse into one bump.
**Done when** Giza is green on the bumped chain. [confederation.md](./confederation.md)'s Phase 9 is
then done, and its Phases 10 to 13 (Part B) and 14 to 16 (Part C) can start.
---
## An alternative for the case where every group must sign
zkp's `secp256k1_prefractal_*` (four functions) and bitcoin-kmp's `Prefractal` are **already public
and already wrapped**; lightning-kmp signs with them in `PrefractalSigner`. Prefractal lets a FROST
t-of-n group occupy one participant slot of an ordinary MuSig2 session. So groups that keep their
own ChillDKG keys can sign as one MuSig2 aggregate of those keys. zkp's review notes an integration
test that does exactly that for three ChillDKG groups.
| | nested DKG (this plan) | Prefractal over the groups' own keys |
|---|---|---|
| upstream work | Z0 to K2 above | none |
| outer threshold | any `T` from 2 to N | every group must sign (`T = N`) |
| new key ceremony | yes, every admin of every group | none: each group's existing key |
| a group's admins change | the confederation's roster is fixed at genesis | follows the group's own key, rotations included |
| nonces | memory only; a restart abandons the attempt | a pure function of the share and a session label, so a restart can reproduce one. One label must sign one message, group-wide |
| tweaks | any x-only tweaks (D10 proven in Giza's Phase 1) | outer aggregate key only; the FROST tweak cache must be the identity. Giza's room-key tweaks are on the outer key, so they should fit, but that is unproven |
| review status | open findings, no sign-off | "neither the scheme nor this implementation has been reviewed" |
It does not replace this plan; `T < N` needs the nested DKG. But if the confederations Giza's users
want are all-must-sign, this path could reach signing without any of Phases Z0 to K2.
**Recommended:** decide that question before starting Z2. The decision is the user's, not this
plan's. If all-must-sign is enough, a smaller Giza-only plan replaces Parts B and C.
---
## Risks
| risk | what to do |
|---|---|
| A public step lets a caller skip a check that the one-process path made for it | U3, U4 and U7 put each check inside the step that needs it. Z2's and Z3's misuse tests call the steps out of order on purpose |
| Re-expressing `dkg` and `sign` over the steps (U9) changes a vector | that is a protocol change. Stop, find the byte, and confirm with the protocol owner before regenerating anything |
| Stack use on mobile threads | Z2 step 4. Also run the K1 and K2 native tests on a background thread with a 512 KB stack |
| The FROST sources move under the zkp bump | C1 re-runs the FROST-unchanged diff. A non-empty diff means Giza's signing changes and needs its own plan |
| The signer state copied by a binding | K2 writes it back and zeroes the native copy; B2 makes it unserialisable. A misuse test in each layer |
| Review findings stay open | Giza builds behind its flag, and ships nothing until Z4's review closes |
---
## Order and size
| phase | where | rough size | depends on |
|---|---|---|---|
| Z0 | zkp docs | a few days of the protocol owner's time | — |