test: Giza reaches bitcoin-kmp's confederation API (confederation update, Phase 4)
ConfederationReachableJvmTest runs a local confederation DKG and two signatures -- one plain, one under a taproot tweak checked against the P2TR output key -- through the desktop JNI library Giza loads. A compile proves only that the classes are on the classpath; a libsecp256k1 built from an older secp256k1-zkp fails here with an UnsatisfiedLinkError. Not a ceremony: dkgLocal and signLocal run every role in one process, and nothing in the app calls them. The plan records Phases 1-4, the Android launch over an existing build, and why secp256k1-kmp's instrumented tests do not build (FrostRefreshTest's spaced method names, from before this update). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4555f5d13c
commit
37079ee41b
2 files changed
+124
-4
No files matched your search
@@ -0,0 +1,105 @@
|
||||
package mobi.giza.compose
|
||||
|
||||
import fr.acinq.bitcoin.ByteVector
|
||||
import fr.acinq.bitcoin.ByteVector32
|
||||
import fr.acinq.bitcoin.Crypto
|
||||
import fr.acinq.bitcoin.PrivateKey
|
||||
import fr.acinq.bitcoin.crypto.confederation.Confederation
|
||||
import fr.acinq.bitcoin.crypto.confederation.ConfederationDkgOutput
|
||||
import fr.acinq.bitcoin.crypto.confederation.ConfederationRoleId
|
||||
import fr.acinq.bitcoin.crypto.confederation.ConfederationRoster
|
||||
import fr.acinq.bitcoin.crypto.confederation.ConfederationSignerSelection
|
||||
import fr.acinq.bitcoin.crypto.confederation.ConfederationTweak
|
||||
import fr.acinq.secp256k1.Hex
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
* That bitcoin-kmp's confederation API reaches Giza, and that the native library Giza loads has
|
||||
* the module in it (docs/confederation-submodule-update.md, Phase 4).
|
||||
*
|
||||
* A compile only proves the classes are on the classpath. A libsecp256k1 built from an older
|
||||
* secp256k1-zkp compiles just the same and fails at the first call, with an
|
||||
* UnsatisfiedLinkError -- here, rather than in whatever first needs a confederation.
|
||||
*
|
||||
* This is not a ceremony and nothing in the app calls it. [Confederation.dkgLocal] and
|
||||
* [Confederation.signLocal] run every role in one process, holding every host key and every
|
||||
* share: upstream's test harness, because the distributed rounds are not public at the pinned
|
||||
* native revision. The module is experimental and unaudited. Seeds are fixed so a failure
|
||||
* reproduces; a real caller would use fresh randomness.
|
||||
*/
|
||||
class ConfederationReachableJvmTest {
|
||||
|
||||
/** The "rpd" roster of bitcoin-kmp 0c34097's confederation/vectors.json: 2-of-(2-of-3), nine roles. */
|
||||
private val roster: ConfederationRoster = ConfederationRoster.fromData(
|
||||
ByteVector(
|
||||
Hex.decode(
|
||||
"""
|
||||
435250440000000100000000000000010000000000000001000000000000000000000000000000000000000000000000
|
||||
0000000000000000000000020000000330ba64f9170cd7e6016549ab4473dfe9b79529c1a43b0a2428b18e8c0b027397
|
||||
0000000000000000000000010000000200000003000000003846c95d6a3be4a58e967cac9f00fc967cf4ec256eb13189
|
||||
bd3f48b2d2f282920222ca50390e660f601036dd7502bb973bdcd104b5dcb8f2e74de8edc6c292b03a00000001b477fa
|
||||
af5c8b288892943134b4231d034dcaaa63c607e7170b3bae0f07a19bfe02141481bf1181ed61aa025f1fe708f68cb018
|
||||
c2c9d6eb719ccd94b3f6ff61530800000002155964e6d8547e42ed7d0c2075244afd27193891e7c99e7a886799ca6752
|
||||
8c6803cfc18f02cc004640f2116fdd1f6ca2022e39be25df75e27c80bde842e6b6f93800000001000000000000000100
|
||||
00000200000003000000009c92cab2d63e63afb08ae7ff625dc6efc9268839a61782f15e498ec1140609a302dde3f965
|
||||
b67e7b28007619e4ac6efdebdab9b8e09b308c81cccef3bd1c31432c00000001a96960a7d148d5b5116ac89ef1255780
|
||||
f2a3eb860449084a3c7cb15a10f0c3e5023388bcc23425458e991f46ca6235c50a57490556becbaf259d3c14f99a80a0
|
||||
87000000026676fee565b3a3f7ef818ac3992247def729b18f954c419b7865160782e71ae9039f04c563cb1b1ab0a325
|
||||
e23cc2768a986d44de723aecaeb60e99b175efe26a060000000200000000000000010000000200000003000000007aa1
|
||||
7bba982198be36ceac68bbb124d5a83e8e6a2e8f63d5386fccb9a94abf1803d26bd0131b8c12de3dd8fefc136d9f9544
|
||||
ac963d4cbcbaa802ba941ef0b46a19000000019dadfeaa8750d16ae95ff7f9250cc43800291aa10ff8a552e798f9c2d4
|
||||
917ac0026a209f2385a83ebf8884aeb2c70949a496eeb1bc2354c62361f2f5a6c21f10ae00000002b5e114d8c490796d
|
||||
4fac253d6c4dd8652801d0a0fcf72799ff55c150b9e11c8203dcd3370cdb67e8f2163960edfef5f66b465a03d4d447f5
|
||||
ca1d99d29e57d1fdb9
|
||||
""".filterNot { it.isWhitespace() },
|
||||
),
|
||||
),
|
||||
).right!!
|
||||
|
||||
private fun seed(tag: Int, i: Int) = ByteVector32(ByteArray(32).also { it[0] = tag.toByte(); it[31] = (i + 1).toByte() })
|
||||
|
||||
/** The vectors' host keys, which the roster's host public keys are made from. */
|
||||
private val hostSecrets: Map<ConfederationRoleId, PrivateKey> =
|
||||
roster.roleIds.withIndex().associate { (i, id) -> id to PrivateKey(ByteArray(32).also { it[30] = 0x10; it[31] = (i + 1).toByte() }) }
|
||||
|
||||
private val dkg: ConfederationDkgOutput = Confederation.dkgLocal(
|
||||
roster,
|
||||
seed(0x5e, 0),
|
||||
hostSecrets,
|
||||
roster.roleIds.withIndex().associate { (i, id) -> id to seed(0xd0, i) },
|
||||
roster.roleIds.withIndex().associate { (i, id) -> id to seed(0x42, i) },
|
||||
).right!!
|
||||
|
||||
/** Groups 0 and 2, two admins of each: one of the smallest coalitions the roster accepts. */
|
||||
private val selection = ConfederationSignerSelection(mapOf(0u to setOf(0u, 2u), 2u to setOf(1u, 2u)))
|
||||
|
||||
@Test
|
||||
fun `the roster is the vectors' roster`() {
|
||||
assertEquals(ByteVector32("7cae865ba55ff2433a59cbc25795f6a2b968694daf2c8ecc8980e3ed584c4973"), roster.hash)
|
||||
assertEquals(9, roster.roleIds.size)
|
||||
assertEquals(9, dkg.shares.size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a confederation key signs and the signature verifies`() {
|
||||
val message = seed(0x99, 0)
|
||||
val sig = Confederation.signLocal(dkg.keyState, dkg.shares, hostSecrets, selection, emptyList(), seed(0x7a, 0), message).right!!
|
||||
assertTrue(Crypto.verifySignatureSchnorr(message, sig, dkg.keyState.publicKey))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a taproot tweak signs for the P2TR output key and not the internal key`() {
|
||||
val internalKey = dkg.keyState.publicKey
|
||||
val tapTweak = Crypto.TaprootTweak.KeyPathTweak
|
||||
val message = seed(0x99, 1)
|
||||
val sig = Confederation.signLocal(
|
||||
dkg.keyState, dkg.shares, hostSecrets, selection,
|
||||
listOf(ConfederationTweak.taproot(internalKey, tapTweak)), seed(0x7a, 1), message,
|
||||
).right!!
|
||||
assertTrue(Crypto.verifySignatureSchnorr(message, sig, internalKey.outputKey(tapTweak).first))
|
||||
assertFalse(Crypto.verifySignatureSchnorr(message, sig, internalKey))
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,20 @@ Measured on 2026-11-21 after `git fetch --all` at every level, against Giza `d04
|
||||
|
||||
| phase | result |
|
||||
|---|---|
|
||||
| 0 | done 2026-11-21. FROST, ChillDKG, enrollment, refresh, MuSig and schnorrsig sources identical between zkp `31ea015c` and `c68e2384`. Natives rebuilt from scratch for Linux and four Android ABIs, each exporting 30 `secp256k1_confederation_*` symbols. secp256k1-kmp `:tests:jvmTest` 125/125 (13 confederation); bitcoin-kmp `jvmTest` 293/293 (19 confederation, 51 FROST/ChillDKG). `connectedAndroidTest` not run: no emulator |
|
||||
| 0 | done 2026-11-21. FROST, ChillDKG, enrollment, refresh, MuSig and schnorrsig sources identical between zkp `31ea015c` and `c68e2384`. Natives rebuilt from scratch for Linux and four Android ABIs, each exporting 30 `secp256k1_confederation_*` symbols. secp256k1-kmp `:tests:jvmTest` 125/125 (13 confederation); bitcoin-kmp `jvmTest` 293/293 (19 confederation, 51 FROST/ChillDKG). `connectedAndroidTest` **cannot build**: see below |
|
||||
| 1 | done. lightning-kmp `ab8d4760` on `claude/confederation`. `:lightning-kmp-core:jvmTest` `crypto` + `channel` 568/568, `iceberg` + `prefractal` 47/47 |
|
||||
| 2 | done. lightning-kmp-app `e6be5e5` on `claude/confederation`. `:library:compileKotlinJvm`, `:library:compileAndroidMain` |
|
||||
| 3 | done. Giza `4555f5d1`. `compileDebugKotlinAndroid`; `jvmTest` 1411/1411; `check` with the brand, M3, Magpie lock, Marmot and wallet audits all at 0. No app change |
|
||||
| 4 | done but for the device checks below. `ConfederationReachableJvmTest` 3/3 through the desktop JNI library Giza loads. Android: a debug build installed over the existing one on `Medium_Phone` (API 36, x86_64; its Room schema was 42, the same as this branch's) launches and loads `libsecp256k1-jni.so` with no crash or link error. That profile had no group, so **no group was signed in**. The Alice/Bob/Charlie emulators were left alone. Desktop run and iOS build not done. `libsecp256k1-jni.so` is now 1.6–2.0 MB per ABI; no pre-bump APK was at hand to compare |
|
||||
|
||||
**secp256k1-kmp's instrumented tests don't build, and this update didn't cause it.**
|
||||
`:tests:dexBuilderDebugAndroidTest` fails because D8 rejects the method name
|
||||
`` `the zkp vectors come out the same through the bindings` `` in `FrostRefreshTest`: names with
|
||||
spaces need DEX 040, i.e. a minSdk of 30. `-Pandroid.injected.build.api=36` doesn't get around
|
||||
it. The test came in with `0f5a710` (2026-11-19, FROST share refresh) and is already in `bcaa985`,
|
||||
which Giza pinned before this update. None of the confederation tests use spaced names. The
|
||||
fix is to rename the methods in `FrostRefreshTest`. That is a secp256k1-kmp commit, and the
|
||||
chain above it would have to be bumped again, so it is left for its own change.
|
||||
|
||||
This worktree does **not** use `git submodule update --init`. That would share, and repoint,
|
||||
the main checkout's `.git/modules`. Instead each level is an independent `git clone` of the
|
||||
@@ -241,11 +254,13 @@ A bump that compiles proves the classes are on the classpath. It does not prove
|
||||
Giza loads has the confederation symbols in it. Add one JVM test in `composeApp/src/jvmTest`,
|
||||
`ConfederationReachableJvmTest`, that:
|
||||
|
||||
- parses the roster from bitcoin-kmp's `confederation/vectors.json`, copied into Giza's test
|
||||
resources with a comment naming bitcoin-kmp `0c34097`;
|
||||
- parses the `rpd` roster from bitcoin-kmp's `confederation/vectors.json`, inlined as hex with a
|
||||
comment naming bitcoin-kmp `0c34097`, and checks its hash against the vectors' `rpd_hash`;
|
||||
- runs `Confederation.dkgLocal` and `signLocal` once, and verifies the signature with
|
||||
`Crypto.verifySignatureSchnorr`;
|
||||
- runs `signTaprootInputLocal` once and checks the witness against the P2TR output key.
|
||||
- signs under `ConfederationTweak.taproot` and checks the signature against the P2TR output key,
|
||||
and not against the internal key. It does not build or spend a transaction: Giza keeps no
|
||||
wallet, and bitcoin-kmp's own `ConfederationTaprootTestsCommon` already covers the spend.
|
||||
|
||||
It is a test, not a feature. Nothing in `commonMain` imports `crypto.confederation`, and the
|
||||
test's KDoc repeats upstream's single-process warning, so nobody reads it as a ceremony.
|
||||
|
||||
Reference in new issue
Block a user