feat(subgroup): the child's quorum holds its certificate to the policy it joined under (Phase 5)

SubgroupManager.refuseKeyState: a child signer refuses a key state whose
birth certificate decides a wallet policy other than the one its own
ceremony announced at the join gate -- undecided included. A ceremony
from an older build announced none and holds the certificate to nothing.
proposeSubgroupKeyState refuses the same thing before asking.

GroupKeyStateManager.parentageOf drops a state whose certificate's policy
does not read or contradicts its guardian keys, so a corrupt policy never
reads as undecided.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5.5 committed 2026-10-23 22:02:49 +02:00
1 parent 44a15e9bc2
commit 52ca030c8b
5 files changed
+129 -2

No files matched your search

@@ -1,5 +1,6 @@
package com.machankura.bennu.compose.managers
import com.machankura.bennu.compose.nostr.frost.GroupKeyStateEvent
import fr.acinq.bitcoin.OutPoint
import com.machankura.bennu.compose.database.model.GroupTransaction
import com.machankura.bennu.compose.database.model.types.FrostSigningSubject
@@ -571,6 +572,22 @@ object FrostSigningManager {
}
}
// A subgroup's key state carries its birth certificate, and the
// certificate's wallet policy has to be the one this group was made
// under: every admin was shown it at the join gate, so joining was
// agreeing to it. A certificate proposed later, by a parent admin
// resuming the flow, under another one would be the child signing a
// decision none of its members agreed to. [key] is the child's own
// ceremony here, which is where the policy was filed.
// `docs/subgroup-wallet-policy.md`, Phase 5.
unsignedEvents.forEach { rebuilt ->
if (rebuilt.kind != GroupKeyStateEvent.KIND) return@forEach
SubgroupManager.refuseKeyState(key, rebuilt)?.let { reason ->
logger.w("Signing proposal $sessionId carries a key state that $reason; dropping")
return null
}
}
val session = FrostSigningSession(
id = sessionId,
chatRoomId = localChatRoom.chatRoom.id,
@@ -423,6 +423,19 @@ object GroupKeyStateManager {
return null
}
// A wallet policy present and unreadable must never look absent: an
// undecided child is offered both wallets, so a corrupt `guarded` would
// hand it the plain one its parent took away -- the lesson of
// [GroupKeyStateEvent.claimsParentage], one tag further on.
// `docs/subgroup-wallet-policy.md`.
if (SubgroupBirthCertificateEvent.parseWalletPolicy(certificate.tags) == null) {
logger.w(
"Key state for $announced carries a certificate whose wallet policy does not " +
"read, or contradicts its guardian keys; dropping"
)
return null
}
return Parentage(
SubgroupParentage(parentChatRoomId = parentChatRoomId, certificate = certificate)
)
@@ -1,5 +1,6 @@
package com.machankura.bennu.compose.managers
import com.machankura.bennu.compose.nostr.frost.GroupKeyStateEvent
import com.machankura.bennu.compose.database.model.subgroupWalletPolicy
import com.machankura.bennu.compose.nostr.subgroup.isDecided
import com.machankura.bennu.compose.nostr.subgroup.SubgroupWalletPolicy
@@ -477,6 +478,12 @@ object SubgroupManager {
"cannot name a parent yet"
)
// Every other child signer refuses a certificate under another policy, so
// proposing it would only stall a quorum -- see [refuseKeyState].
refusePolicy(key, certificate.toEvent())?.let { reason ->
throw IllegalStateException("$parentChatRoomId's certificate for $subgroupChatRoomId $reason")
}
return GroupKeyStateManager.propose(
database = database,
localChatRoom = ceremonyRoom,
@@ -490,6 +497,33 @@ object SubgroupManager {
)
}
/**
* Why a child signer should not sign [keyState] under [key], its own
* ceremony, or null when it may: the birth certificate it carries decides a
* wallet policy other than the one the ceremony announced.
*
* Every admin was shown that policy at the join gate, so joining was agreeing
* to it. A certificate proposed later under another -- by a parent admin
* resuming the flow, or one whose device read the parent differently -- would
* be the child signing a decision none of its members agreed to. A ceremony
* that announced none, from an older build, has nothing to hold the
* certificate to. `docs/subgroup-wallet-policy.md`, Phase 5.
*/
fun refuseKeyState(key: DkgSession, keyState: Event): String? {
val certificate = GroupKeyStateEvent.parseBirthCertificate(keyState.tags) ?: return null
return refusePolicy(key, certificate)
}
private fun refusePolicy(key: DkgSession, certificate: Event): String? {
val agreed = key.subgroupWalletPolicy ?: return null
val certified = SubgroupBirthCertificateEvent.parseWalletPolicy(certificate.tags)
return if (certified.isDecided(agreed)) {
null
} else {
"carries a certificate whose wallet policy is not the one this group was made under ($agreed)"
}
}
/**
* A subgroup as the parent's own record has it, plus whatever this device
* happens to hold about it.