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))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user