Bumps lightning-kmp-app to 572b931, and with it the chain below: lightning-kmp 47a0f585 (its master, now carrying the threshold line), bitcoin-kmp bca235a, secp256k1-kmp 8022069 and secp256k1-zkp b5819301. zkp now exports the confederation's DKG and Option A signing steps, secp256k1-kmp binds them, and bitcoin-kmp wraps them as ConfederationDkg and ConfederationSigning. ConfederationReachableJvmTest gains a run in which three groups make a key one role at a time, through ConfederationDkg with only bytes between the roles, and then sign as their room's id through ConfederationSigning, with every signer spent at the end. Confederation.signLocal now takes nonce randomness, so the fixture gives its callers fixed per-signer values. docs/confederation-upstream.md records each phase's commit and what checked it, and how lightning-kmp's master was reconciled. docs/confederation.md marks Phase 9 done, so Parts B and C can start. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
681 lines
40 KiB
Markdown
681 lines
40 KiB
Markdown
# Upstream: the confederation's rounds, made public
|
||
|
||
A plan for the work below Giza that unblocks Parts B and C of
|
||
[confederation.md](./confederation.md). It covers the confederation's DKG and its Option A signing,
|
||
run one role per device, with messages crossing an untrusted network between rounds.
|
||
|
||
The work spans three repositories and then a submodule bump:
|
||
|
||
| level | repository | what it gets |
|
||
|---|---|---|
|
||
| 1 | secp256k1-zkp, branch `frost` | public round-step functions for the DKG and for signing, over code that already exists as `static` functions |
|
||
| 2 | secp256k1-kmp (`kngako`, `threshold`) | JNI and Kotlin/Native bindings for those functions |
|
||
| 3 | bitcoin-kmp (`kngako`, `threshold`) | `ConfederationDkg` and `ConfederationSigning`, Kotlin wrappers in the shape of `ChillDKG` and `Frost` |
|
||
| 4 | lightning-kmp, lightning-kmp-app, Giza | the bump, following [confederation-submodule-update.md](./confederation-submodule-update.md) |
|
||
|
||
Written against zkp `c68e2384`, secp256k1-kmp `fce4d81`, bitcoin-kmp `0c34097` and Giza `190cb9e9`, on
|
||
2026-11-21, by reading the sources rather than running them. **Not built.** Read
|
||
[confederation.md](./confederation.md) first: its Part B (phases 10 to 13) and Part C (phases 14 to
|
||
16) are what this work is for, and its decisions D5, D7 and D10 decide some of the shapes here.
|
||
|
||
## Status: done, merged and pushed
|
||
|
||
Every phase below is committed and pushed bottom up, each to its repository's default branch: zkp
|
||
`frost` (the branch secp256k1-kmp's `.gitmodules` tracks; the remote's `main` is upstream's),
|
||
secp256k1-kmp and bitcoin-kmp `threshold`, lightning-kmp and lightning-kmp-app `master`, Giza
|
||
`giza`.
|
||
|
||
lightning-kmp's `master` had not had the `threshold` line before. It held an earlier Iceberg port
|
||
of its own: JVM-only, over a secp256k1-kmp fork published to mavenLocal. The `threshold` line had
|
||
re-done that port multiplatform and gone on from it. The merge (`47a0f585`) takes the `threshold`
|
||
side for all 28 files both touched. It keeps `master`'s measurement harness, ported to the
|
||
multiplatform signer, and its two plans, each marked as superseded.
|
||
|
||
| phase | repository | commit | checked by |
|
||
|---|---|---|---|
|
||
| Z0 | secp256k1-zkp | `965fe8ac` | protocol and plan text only |
|
||
| Z1 | secp256k1-zkp | `5078a22e` | the reference model regenerates the vectors |
|
||
| Z2 | secp256k1-zkp | `a56e4a57` | `tests`, ASan/UBSan, Valgrind, the fuzz harness, an Autotools build |
|
||
| Z3 | secp256k1-zkp | `78cf4ebc` | the same |
|
||
| Z4 | secp256k1-zkp | `b5819301` | review intake, `doc/confederation-review.md` section 21 |
|
||
| K0 | secp256k1-kmp | `8394c82` | the Android tests dex |
|
||
| K1 | secp256k1-kmp | `a5aa35e` | `jvmTest`, `linuxX64Test`, `connectedAndroidTest` |
|
||
| K2 | secp256k1-kmp | `8022069` | the same, 138 tests each; 57 exported confederation symbols |
|
||
| B1 | bitcoin-kmp | `18cb99b` | `jvmTest` (298) |
|
||
| B2 | bitcoin-kmp | `bca235a` | `jvmTest` (306), including two threads racing one signer |
|
||
| C1 | lightning-kmp | `54c8c4e8`, merged into `master` as `47a0f585` | `:lightning-kmp-core:jvmTest` crypto, channel, iceberg and prefractal (615) |
|
||
| C1 | lightning-kmp-app | `572b931` | `:library:compileKotlinJvm`, `:library:compileAndroidMain` |
|
||
| C1 | Giza | the commit that adds this table | `compileDebugKotlinAndroid`, `check` (jvmTest 1,602, the audits) |
|
||
|
||
Two things came out differently from the text below:
|
||
|
||
- **K2's signer state** is a bare `CONFEDERATION_SIGNER_SIZE` array that the caller allocates
|
||
and the binding writes back after every call, as planned. The arrays the library reads with no
|
||
length (nonces, confirmations, partials, group partials) are copied into buffers padded to the
|
||
module maximum. A short array therefore fails on a NULL or zeroed entry instead of being read
|
||
past its end.
|
||
- **`Confederation.signLocal` takes nonce randomness**, one secret per selected signer. Z3 gave
|
||
`secp256k1_confederation_sign` a `nonce_secrands32` argument, and bitcoin-kmp has no secure
|
||
random source of its own to fill it. Giza's three callers, all tests, pass fixed values.
|
||
|
||
Not done: the iOS build. Kotlin/Native cinterop regenerates from the header there and needs a Mac.
|
||
`linuxX64Test` exercises the same Kotlin/Native code.
|
||
|
||
---
|
||
|
||
## Where it stands
|
||
|
||
**Everything this plan needs already runs, in one process.** zkp's own record says the
|
||
implementation through its milestone M8 is in: the nested DKG, Option A signing, tweaks, enrollment,
|
||
refresh, masking and resharing. The public header, `include/secp256k1_confederation.h`, exports 30
|
||
functions. Two of them run a whole protocol:
|
||
|
||
- `secp256k1_confederation_dkg` takes every role's host secret key, dealer seed and recovery nonce.
|
||
- `secp256k1_confederation_sign` takes every role's share and host key.
|
||
|
||
Both run in one process; `confederation.md` calls them "not a production DKG protocol driver". The
|
||
steps inside them are `static`:
|
||
|
||
| family | internal step | file |
|
||
|---|---|---|
|
||
| DKG | `dkg_participant_step1` | `dkg_participant_impl.h:38` |
|
||
| | `dkg_coordinator_step1` | `dkg_ceremony_impl.h:60` |
|
||
| | `dkg_derive_ksd`, `dkg_recipient_verify` | `dkg_ceremony_impl.h:130`, `:214` |
|
||
| | `dkg_genesis_prepare`, `dkg_verify_authorizations` | `dkg_finalization_impl.h:12`, `:61` |
|
||
| | `dkg_coordinator_finalize`, `dkg_participant_finalize` | `dkg_finalization_impl.h:86`, `:115` |
|
||
| | `transition_evidence_sign` | `dkg_participant_impl.h:192` |
|
||
| | `dkg_investigation_response`, `dkg_investigate` | `dkg_finalization_impl.h:157`, `:205` |
|
||
| signing | `sign_session_init`, `signer_nonce_gen` | `sign_impl.h:111`, `:357` |
|
||
| | `nonce_transcript_write` / `_parse` | `sign_impl.h:259`, `:303` |
|
||
| | `signer_confirm` | `sign_impl.h:427` |
|
||
| | `confirmation_certificate_write`, `confirmation_verify` | `sign_impl.h:467`, `:502` |
|
||
| | `signer_partial`, `member_partial_verify` | `sign_partial_impl.h:165`, `:151` |
|
||
| | `group_partial_aggregate` / `_verify` | `sign_partial_impl.h:289`, `:255` |
|
||
| | `outer_aggregate` | `sign_partial_impl.h:318` |
|
||
|
||
(The internal names drop the `secp256k1_confederation_` prefix here.) Most messages already have
|
||
canonical encodings:
|
||
|
||
| message | encoding | size for the 9-role vector |
|
||
|---|---|---|
|
||
| dealer record | `dkg_record_write` / `_parse` | 382 bytes (`205 + 33T + 4G + Σ33(t_g−1)`, at most 6,797) |
|
||
| ciphertext vector | `32 × n` bytes, one per recipient | 288 bytes |
|
||
| coordinator broadcast | `72 + n(record + 32)` bytes | 3,798 bytes |
|
||
| `D_sign` ("CSGN") | `d_sign_write`, compared by re-encoding | 273 bytes |
|
||
| nonce transcript ("CNON") | `12 + 74u` bytes | 308 bytes |
|
||
| confirmation certificate ("CCFM") | `44 + 72u` bytes | 332 bytes |
|
||
| genesis certificate | `transition_serialize` | 1,804 bytes |
|
||
| recovery package | public codec | 269 bytes |
|
||
| group partial | **none** (a `u32` and a scalar in memory) | — |
|
||
|
||
**The review record gates release, not the build.** `doc/confederation-review.md` says "No signed
|
||
sign-off has been recorded", that the new implementation code has had no independent review, and
|
||
that F-24, F-25, F-30, F-35 and F-38 are open. Each touches a step this plan exposes; see Phase Z0.
|
||
|
||
---
|
||
|
||
## What the reading found that changes the design
|
||
|
||
Three things the one-process functions do are fine inside one process and wrong across devices.
|
||
Exposing the steps as they are called today would carry them across.
|
||
|
||
1. **The coordinator derives the key state for everybody** (`api_impl.h:76-85`). Protocol §7.4 step
|
||
4 says each recipient derives the KSD from the broadcast itself and checks it. A participant step
|
||
that accepted a KSD from the coordinator would let the coordinator choose the confederation's
|
||
public key.
|
||
2. **Authorization and acknowledgment are signed together** (`api_impl.h:86-99`). Protocol §7.6
|
||
orders it: every role broadcasts its authorization, verifies everybody's, stores its share
|
||
durably, and only then acknowledges. The acknowledgment is the role saying it will never lose
|
||
the share. Signing both at once makes that claim before the share is stored anywhere.
|
||
3. **`sign()` derives each signer's nonce randomness from the session id** (`api_impl.h:175-189`):
|
||
`SHA256(signing_session_id)` with the role index XORed in. Protocol §8.2 requires fresh local
|
||
randomness. Across devices, two attempts under one session id would reuse a nonce, and leak the
|
||
share.
|
||
|
||
And two things make the public API simpler than it might have been:
|
||
|
||
4. **Nothing in the DKG draws randomness internally.** Every Schnorr signature passes `aux = NULL`,
|
||
and step 1's nonce, coefficients, proof of possession and pads all come from the dealer seed. So
|
||
every DKG step is a pure function of its explicit inputs, the same property that makes Giza's
|
||
ChillDKG ceremony restartable ([shared-key-ceremony.md](./shared-key-ceremony.md)). No
|
||
participant state needs a type of its own.
|
||
5. **The share can be recomputed rather than handed out.** `recipient_verify` produces the secret
|
||
share from the broadcast, the role's own record and its host secret key. Finalization can
|
||
recompute it, so no public function returns a bare secret scalar.
|
||
|
||
---
|
||
|
||
## Decisions
|
||
|
||
### U1. Only the initial DKG and Option A signing
|
||
|
||
That is all Giza's Parts B and C need. Enrollment, repair, refresh, masked outer enrollment and
|
||
resharing stay internal. They are the confederation's membership changes, which
|
||
[confederation.md](./confederation.md) lists under *What this does not do*. They come back in a
|
||
later plan once Parts B and C have run on devices. The API below reuses what they will need (the
|
||
fault type, the role ordering and the transition certificate), so nothing here has to be redone.
|
||
|
||
### U2. Steps are stateless and take their inputs explicitly
|
||
|
||
Every public DKG step takes the role's inputs and the messages it has received, and returns
|
||
messages and results. No participant-state struct crosses the API. That follows from finding 4, and
|
||
it is what Giza needs: a device that dies between rounds recomputes the step on restart, with the
|
||
same bytes, as `ChillDkgRitualManager.advance` does today.
|
||
|
||
The one input the protocol wants gone is the **dealer seed**. §6.2 and §7.2 say to erase it after
|
||
the record is submitted. Statelessness does not get in the way of that: once step 1's record and
|
||
ciphertexts are stored, nothing later needs the seed. Step 2 compares against the stored own record,
|
||
and finalization recomputes the share from the record and the host key. The header says so, and
|
||
Giza's Phase 11 stores the record and erases the seed. That differs from the ChillDKG ritual, which
|
||
keeps `round1Random`, and the plan says why where Giza takes it up.
|
||
|
||
### U3. The participant's second step does everything §7.4 asks, in one call
|
||
|
||
One public function, `dkg_participant_step2`, does the following:
|
||
|
||
1. parse the broadcast;
|
||
2. compare the role's own record byte for byte;
|
||
3. verify every record;
|
||
4. derive the KSD and the genesis transition itself;
|
||
5. decrypt and check its own share, then discard it;
|
||
6. sign the authorization.
|
||
|
||
It returns the KSD, the transition hash and the authorization signature, plus a fault. Splitting it
|
||
would leave a caller able to sign an authorization over a KSD it never derived. That is finding 1
|
||
reached by a different route.
|
||
|
||
### U4. Acknowledgment is its own step, after the authorizations are verified
|
||
|
||
`dkg_participant_acknowledge` takes the full authorization list, verifies it against the RPD and
|
||
the transition hash, and only then signs the acknowledgment. Its header comment says the caller
|
||
must have stored durably, before calling, what it needs to recompute its share: the RPD, the KSD,
|
||
the broadcast, its own record and its recovery nonce. This is finding 2, and it turns the protocol's
|
||
"store, then acknowledge" into a call order the API documents.
|
||
|
||
### U5. Faults are values with a culprit, as ChillDKG's are
|
||
|
||
Steps return `secp256k1_confederation_fault_code`, which is already public (`NONE`,
|
||
`INVALID_INPUT`, `INVALID_CONFIGURATION`, `COORDINATOR`, `ROLE`, `ROLE_OR_COORDINATOR`,
|
||
`UNKNOWN`). They also return a `uint32_t *fault_index`: the flattened role index, or `UINT32_MAX`.
|
||
|
||
`dkg_coordinator_step1` today returns 0 with no attribution. The public version names the dealer
|
||
whose record or ciphertext was refused. A participant step that fails to decrypt returns
|
||
`ROLE_OR_COORDINATOR`, as ChillDKG's step 2 does, and the caller runs the investigation to settle
|
||
which.
|
||
|
||
### U6. Signing nonces live in memory only, behind a guarded type
|
||
|
||
The signer state, `secp256k1_confederation_signer`, becomes a public opaque type. It carries a
|
||
magic and the issued → confirmed → consumed state machine, and its comment says, as
|
||
`secp256k1_frost_secnonce`'s does: must not be copied, serialized or restored. Nonce generation
|
||
takes `session_secrand32` from the caller, required unique per call, and wipes it. That is finding
|
||
3, and it is F-24's state machine made into the API.
|
||
|
||
**Giza cannot use its FROST pattern here.** `FrostSigningManager` stores `nonceRandom` and
|
||
regenerates the secret nonce on demand, which the protocol forbids for confederation signing. A
|
||
restart mid-attempt abandons the attempt; the proposer starts a new one under a new session id.
|
||
[confederation.md](./confederation.md)'s Phase 14 already says this.
|
||
|
||
### 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 |
|
||
| investigation request | §7.5's fields: RPD hash, session seed, dealer role, requester role |
|
||
|
||
Each has a `*_size` helper. The header's `outlen` convention applies: a short buffer reports the
|
||
size it needed.
|
||
|
||
### U9. The one-process functions are re-expressed over the public steps
|
||
|
||
After this work, `secp256k1_confederation_dkg` and `secp256k1_confederation_sign` call the public
|
||
steps in protocol order. So the shortcuts in findings 1 to 3 disappear from them too. Signing's
|
||
derived nonce randomness survives only as a test helper. It is named so nobody mistakes it for a
|
||
recipe, and the public `sign` takes one fresh secret per signer from the caller instead.
|
||
|
||
Every existing test and vector then runs through the public steps. That is the cheapest way to
|
||
show the steps compose into what was already reviewed.
|
||
|
||
### U10. Spec questions are settled before code, by whoever owns the protocol
|
||
|
||
F-35 found the dealer-seed labels differ between code (`"outer-<k>"`) and text (`"outer/" ‖ u32`).
|
||
Changing the code changes every DKG output and vector; changing the text changes nothing.
|
||
**Recommended: make the text say what the code does.** It is the protocol owner's call, not this
|
||
plan's, and Phase Z0 asks for it.
|
||
|
||
---
|
||
|
||
## The public API this plan adds
|
||
|
||
Names follow `secp256k1_chilldkg.h`. Arguments are listed in protocol terms; the header settles
|
||
the exact C signatures in Phase Z2 and Z3.
|
||
|
||
### DKG
|
||
|
||
| function | role | in | out |
|
||
|---|---|---|---|
|
||
| `dkg_record_size(rpd)`, `dkg_ciphertexts_size(rpd)`, `dkg_broadcast_size(rpd)`, `dkg_evidence_list_size(rpd)`, `dkg_investigation_response_size(rpd)` | any | the RPD | sizes |
|
||
| `dkg_participant_step1` | each role | RPD, role, host secret key, dealer seed, session seed | signed dealer record; ciphertext vector |
|
||
| `dkg_coordinator_step1` | coordinator | RPD, session seed, every record and ciphertext vector, in role order | broadcast; fault and index |
|
||
| `dkg_derive_ksd` | any | RPD, broadcast | KSD |
|
||
| `dkg_genesis_prepare` | any | RPD, KSD | unsigned genesis transition and its hash |
|
||
| `dkg_participant_step2` | each role | RPD, role, host secret key, session seed, own record, broadcast | KSD, transition hash, authorization signature; fault and index (U3) |
|
||
| `dkg_verify_evidence` | any | RPD, transition hash, an authorization or acknowledgment list | valid or not, with the first bad index |
|
||
| `dkg_participant_acknowledge` | each role | RPD, KSD, role, host secret key, transition hash, authorization list | acknowledgment signature (U4) |
|
||
| `dkg_coordinator_finalize` | coordinator | RPD, KSD, authorization list, acknowledgment list | certified genesis transition |
|
||
| `dkg_participant_finalize` | each role | RPD, KSD, transition, role, host secret key, own record, broadcast, recovery nonce | share; recovery package (the share is recomputed, U2) |
|
||
| `dkg_investigation_response` | coordinator | RPD, session seed, dealer role, that dealer's ciphertext vector | response |
|
||
| `dkg_investigate` | a recipient | RPD, broadcast, role, host secret key, every dealer's response | fault and index |
|
||
|
||
### Signing (Option A)
|
||
|
||
| function | role | in | out |
|
||
|---|---|---|---|
|
||
| `sign_session_init` | every signer and coordinator | RPD, KSD, session id, selection, tweak sequence | session; `D_sign` |
|
||
| `sign_session_check` | every signer | session, the coordinator's `D_sign` | equal or not (U7) |
|
||
| `signer_nonce_gen` | each signer | session, RPD, KSD, share, `D_sign`, fresh secret randomness | signer state (memory only); public nonce, 66 bytes |
|
||
| `nonce_transcript_size`, `nonce_transcript_write` | outer coordinator | session, every public nonce in selection order | transcript |
|
||
| `signer_confirm` | each signer | signer state, session, `D_sign`, transcript, message, host secret key | confirmation signature; the state moves to confirmed |
|
||
| `confirmation_certificate_size`, `confirmation_certificate_write` | outer coordinator | session, `D_sign`, transcript, message, every confirmation signature | certificate |
|
||
| `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;
|
||
- **tweaks:** Giza's room-key tweaks (three x-only tweaks,
|
||
[confederation.md](./confederation.md) D10) through the steps;
|
||
- **concurrency:** two sessions in flight for one role, which security.md §3.1 does not claim
|
||
to be safe. The test pins that the API refuses nothing here, and the header says the caller
|
||
must not.
|
||
5. `examples/confederation_distributed.c` signs after it forms the confederation.
|
||
|
||
**Done when** the target passes as in Z2, and `confederation_test_signer_inject`, the test that
|
||
writes signer internals directly, is no longer needed by any test the public API covers.
|
||
|
||
### Phase Z4: put the API to review (zkp, docs)
|
||
|
||
1. Add **"Distributed DKG API"** and **"Distributed signing API"** as scopes in
|
||
`doc/confederation-review.md`: what is new, what wraps reviewed code, and the storage contract.
|
||
2. Answer F-24 and F-25 with Z0's text and Z3's code and tests. Answer F-30 with Z1, and the parts
|
||
of F-35 and F-38 that Z0 and Z2 address. Each answer is the reviewer's to close.
|
||
3. Ask for the independent implementation review that review §7.1 already says is required before
|
||
an experimental release.
|
||
|
||
**Done when** the review is requested. Giza can build Parts B and C on the API before it closes.
|
||
Giza **cannot ship** them until it does; the flag stays off in release
|
||
([confederation.md](./confederation.md), *What this does not do*).
|
||
|
||
### Phase K0: unblock Android tests (secp256k1-kmp)
|
||
|
||
`FrostRefreshTest` has five method names with spaces (lines 32, 93, 104, 130 and 150). D8 needs
|
||
DEX 040 for those, which means minSdk 30, and the tests run at minSdk 21. So
|
||
`:tests:dexBuilderDebugAndroidTest` fails, and with it `connectedAndroidTest`. Rename them to
|
||
camelCase, as the ChillDKG and confederation tests already are.
|
||
|
||
**Done when** `connectedAndroidTest` builds and passes on an emulator. This is its own commit,
|
||
before K1, so the new bindings are tested on Android from the first commit.
|
||
|
||
### Phase K1: bind the DKG steps (secp256k1-kmp)
|
||
|
||
Bump `native/secp256k1` to Z2's commit. Then, for each function, the checklist the earlier
|
||
confederation commits followed:
|
||
|
||
1. JNI C (`jni/c/src/fr_acinq_secp256k1_Secp256k1CFunctions.c`): the `JNIEXPORT` function. The
|
||
templates are `secp256k1_confederation_dkg` (4319-4400: `goto cleanup`, zeroising) for anything
|
||
holding a secret, and `chilldkg_coordinator_step1` (2098-2155) for a fault and index. RPD and
|
||
KSD inputs go through `get_confederation_rpd`/`_ksd`, which validate after copying.
|
||
2. Copy the regenerated `jni/c/headers/java/...CFunctions.h` into the repository. It is marked
|
||
"machine generated", but the committed copy is what builds.
|
||
3. `Secp256k1CFunctions.java`: the native declarations and size constants.
|
||
4. `Secp256k1.kt`:
|
||
- the interface methods;
|
||
- a `ConfederationFault(code, roleIndex: UInt?)` beside `ChilldkgFault`;
|
||
- result data classes whose `toString` prints `<secret>` for anything secret.
|
||
5. `Secp256k1Jni.kt` and `Secp256k1Native.kt`: the actuals. On native, `try`/`finally` zeroes
|
||
host keys and seeds, as `confederationDkg` does at 2086.
|
||
6. No change to `native/build.gradle.kts` or `libsecp256k1.def`: same module, same header.
|
||
7. Tests in `tests/src/commonTest/.../ConfederationDistributedDkgTest.kt`, with camelCase names
|
||
(K0): Z1's per-step vectors from `tests/src/commonTest/resources/confederation/`, and the
|
||
step-by-step-equals-one-process check, in Kotlin.
|
||
8. README's "Confederation" section, which says the round steps are internal, is rewritten.
|
||
9. CI (`.github/workflows/test.yml`) already runs `ctest -R confederation`. It needs no change.
|
||
|
||
**Done when** `:tests:jvmTest`, a native test task and `connectedAndroidTest` pass, and
|
||
`nm native/build/linux/libsecp256k1.a | grep -c secp256k1_confederation_` counts the new symbols.
|
||
A stale native library shows up only at runtime.
|
||
|
||
### Phase K2: bind the signing steps (secp256k1-kmp)
|
||
|
||
The same checklist, with two differences:
|
||
|
||
- **The signer state crosses the boundary in and out.** `signer_confirm` and `signer_partial`
|
||
change it, so the binding takes the state as a `ByteArray` and writes it back: issued, then
|
||
confirmed, then zeroed. This is how `frostNonceGen` already hands a secret nonce to Kotlin. The
|
||
JNI function zeroes its native copy on every exit.
|
||
- **The signer state is never a result class field with a `toString`.** It is a bare `ByteArray`
|
||
the wrapper owns (B2).
|
||
|
||
Tests: Z1's signing vectors, every misuse case from Z3 asserted through the binding, and a signature
|
||
under the room-key tweaks checked with `Crypto.verifySignatureSchnorr`.
|
||
|
||
**Done when** the same three test tasks pass.
|
||
|
||
### Phase B1: `ConfederationDkg` (bitcoin-kmp)
|
||
|
||
New `crypto/confederation/ConfederationDkg.kt`, in the shape of `ChillDKG.kt`:
|
||
|
||
- **Messages as data classes** over `ByteVector`, each validating its size against the roster in
|
||
`init`, with `toByteArray()`: `DealerRecord`, `CiphertextVector`, `CoordinatorBroadcast`,
|
||
`EvidenceList`, `InvestigationResponse`.
|
||
- **Results:**
|
||
- `ParticipantStep1Result(record, ciphertexts)`;
|
||
- `CoordinatorStep1Result(fault, broadcast?)`;
|
||
- `ParticipantStep2Result(fault, keyState?, transitionHash?, authorization?)`;
|
||
- `ParticipantFinalizeResult(share, recovery)`.
|
||
`keyState` reuses `ConfederationKeyState`, and `share` reuses `ConfederationShare`.
|
||
- **`object ConfederationDkg`**, every step `@JvmStatic`, returning `Either` for local errors and
|
||
`ConfederationFault` for protocol faults, as `ChillDKG` does. Randomness is explicit
|
||
`ByteVector32` arguments. Inputs per role are keyed by `ConfederationRoleId`, as `Confederation`
|
||
already does. Host keys are filled with zeros in `finally`.
|
||
- **Tests (`ConfederationDkgTestsCommon`):**
|
||
- Z1's vectors;
|
||
- nine roles run through `ConfederationDkg` with only `toByteArray()` between them, landing on
|
||
`Confederation.dkgLocal`'s key state;
|
||
- a role that restarts after step 2 and finishes with the same share;
|
||
- an investigation that names the culprit.
|
||
|
||
**Done when** `./gradlew jvmTest` passes with the existing confederation, FROST and ChillDKG suites
|
||
unchanged.
|
||
|
||
### Phase B2: `ConfederationSigning` (bitcoin-kmp)
|
||
|
||
New `crypto/confederation/ConfederationSigning.kt`, in the shape of `Frost.kt`:
|
||
|
||
- `ConfederationSigningSession`, built locally with `create(keyState, sessionId, selection, tweaks)`;
|
||
`dSign`; `check(coordinatorDSign)`.
|
||
- `ConfederationSigner`: a private constructor, no serializer, an `AtomicBoolean` so it is used at
|
||
most once, and the state machine mirrored in Kotlin so a misuse fails before it reaches the
|
||
binding. The same guarantees `SecretNonce` gives today.
|
||
- `NonceTranscript`, `ConfirmationCertificate`, `GroupPartial`, each with `toByteArray()` and a
|
||
parser.
|
||
- **`object ConfederationSigning`:** `generateNonce` (randomness required, no default),
|
||
`transcript`, `confirm`, `certificate`, `verifyCertificate`, `sign`, `verifyMemberPartial`,
|
||
`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 | — |
|
||
| Z1 | zkp Python model | ~800 lines, vectors regenerated | Z0 |
|
||
| Z2 | zkp C | ~1,200 C, ~900 tests | Z1 |
|
||
| Z3 | zkp C | ~900 C, ~800 tests | Z1; Z2 for U9's shared helpers |
|
||
| Z4 | zkp docs | a review request | Z2, Z3 |
|
||
| K0 | secp256k1-kmp | five renames | — |
|
||
| K1 | secp256k1-kmp | ~1,500 across JNI, native and Kotlin, ~400 tests | Z2, K0 |
|
||
| K2 | secp256k1-kmp | ~1,300, ~400 tests | Z3, K1 |
|
||
| B1 | bitcoin-kmp | ~600, ~400 tests | K1 |
|
||
| B2 | bitcoin-kmp | ~700, ~400 tests | K2, B1 |
|
||
| C1 | lightning-kmp, lightning-kmp-app, Giza | three bumps and one test | B2 (or B1, for Part B alone) |
|
||
|
||
K0 can be done today. Z2 and Z3 can run side by side once Z1 lands, and so can K1/B1 beside Z3.
|
||
**Part B needs only Z0 to Z2, K0, K1, B1 and C1.** If the chain is bumped after B1, Giza's Phases 10
|
||
to 13 can start while signing (Z3, K2, B2) is still being written.
|
||
|
||
## Checking the work
|
||
|
||
At each level, before pushing:
|
||
|
||
```bash
|
||
cmake -S . -B build -DSECP256K1_EXPERIMENTAL=ON -DSECP256K1_ENABLE_MODULE_CONFEDERATION=ON -DSECP256K1_BUILD_TESTS=ON && cmake --build build && ./build/bin/tests --target=confederation
|
||
```
|
||
|
||
```bash
|
||
./gradlew :tests:jvmTest :tests:connectedAndroidTest
|
||
```
|
||
|
||
```bash
|
||
./gradlew jvmTest
|
||
```
|
||
|
||
```bash
|
||
./gradlew :composeApp:compileDebugKotlinAndroid :composeApp:jvmTest check
|
||
```
|
||
|
||
They run in zkp, secp256k1-kmp, bitcoin-kmp and Giza respectively.
|