fix(dkg): a Marmot room hosts its subgroups' ceremonies and never one of its own (Phase 1)

proposeRitual now refuses a ceremony with no parent in a Marmot room, and
acceptProposal drops one arriving there. A Marmot room's id is derived from
the key it already has, so a key of its own is one it could never use -- and
the shared-key screen offering to start one in a parent's room is how a
second, whole-room ceremony opened beside a subgroup's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5.5 committed 2026-10-23 16:19:28 +02:00
1 parent 30e425f201
commit e259634513
2 files changed
+104

No files matched your search

@@ -138,6 +138,14 @@ object ChillDkgRitualManager {
fun canRunRitual(localChatRoom: LocalChatRoom): Boolean =
memberPublicKeys(localChatRoom).size >= MINIMUM_PARTICIPANTS
/**
* Whether [localChatRoom] is a Marmot room, and so can host a subgroup's
* ceremony but never one of its own. The same reading [broadcast] makes to
* pick a transport.
*/
fun isMarmotRoom(localChatRoom: LocalChatRoom): Boolean =
localChatRoom.chatRoom.mlsGroupState != null
/**
* Everyone a ceremony is being run with — which is not the same question as
* who is in the room it runs in.
@@ -245,6 +253,15 @@ object ChillDkgRitualManager {
"${(members - room).joinToString { it.take(8) }}, who are not in it"
}
// A Marmot room's id is derived from the key it already has, so a ceremony
// of its own would make a key the room could never answer to. It hosts its
// subgroups' ceremonies and nothing else. The screens stopped offering one
// here, and this is what makes that a rule rather than a screen not drawing
// a button -- see docs/ceremony-creation.md.
require(parentChatRoomId != null || !isMarmotRoom(localChatRoom)) {
"${localChatRoom.chatRoom.id} is a Marmot room; it can only host a subgroup's ceremony"
}
require(members.size >= MINIMUM_PARTICIPANTS) {
"A shared key needs at least $MINIMUM_PARTICIPANTS members, this ceremony has ${members.size}"
}
@@ -399,6 +416,20 @@ object ChillDkgRitualManager {
): DkgSession? {
database.dkgSessionDao().getSessionById(sessionId)?.let { return it }
// The receiving half of `proposeRitual`'s refusal. A build from before it
// can still put a group's own ceremony on the wire in a Marmot room, and
// recording it would show every member a ceremony whose key the room can
// never use -- which is how a second ceremony ended up beside a subgroup's.
if (isMarmotRoom(localChatRoom) &&
DkgRitualEvents.parseParentChatRoomId(innerEvent.tags) == null
) {
logger.w(
"DKG proposal $sessionId names no parent in Marmot room " +
"${localChatRoom.chatRoom.id}; dropping"
)
return null
}
// The participant set is the proposal's own p-tags plus its sender, NOT
// this device's view of the room. `n` is hashed into the session identity,
// so two devices that disagree on it cannot complete a ritual together —