๐ณ The Tree of Secret Keys
How MLS Manages Group Keys Efficientlyโ
In 10 minutes: Understand ratchet trees - MLS's secret weapon
Prerequisite: None
๐ฏ The Simple Storyโ
Remember how we said MLS encrypts once for the whole group?
How does everyone get the same key without sending it over and over?
The secret: A special tree called a ratchet tree
๐ง Mental Modelโ
Hold this picture in your head:
Ratchet Tree (Horizontal Binary Tree):
Alice Bob Charlie David
โ โ โ โ
โโโ A โโโ โโโ B โโโโโ
โ โ
โโโโโโโโ C โโโโโ
โ
Group Secret
Each leaf = One person (Alice, Bob, Charlie, David)
Each node = Shared secret between descendants
C = Group secret (everyone can derive it)
Think of it like a family tree on its side:
Family Tree Metaphor:
๐ด Grandpa C
โโ ๐จ Dad A
โ โโ ๐ฆ Alice
โ โโ ๐จ Bob
โโ ๐จ Dad B
โโ ๐ฆ Charlie
โโ ๐จ David
Family secret at Grandpa:
Everyone in family knows Grandpa's secret
Alice can go up to Grandpa
Bob can go up to Grandpa
Charlie can go up to Grandpa
David can go up to Grandpa
๐ See How It Worksโ
Let's watch how Alice sends to everyone:
Watch Alice send a message:
Step 1: Alice goes up the tree
Alice โ A (her leaf)
A โ AB (her parent)
AB โ C (everyone's parent)
Step 2: Alice has Group Secret C
Alice encrypts message with C
Step 3: Everyone else gets C the same way
Bob โ B โ AB โ C
Charlie โ C โ CD โ C
David โ D โ CD โ C
Step 4: Everyone can decrypt
All have C, so all can decrypt Alice's message
๐ญ The Magic Pathโ
Each person has a path to the root:
Alice's path: Alice โ A โ AB โ C
Bob's path: Bob โ B โ AB โ C
Charlie's path: Charlie โ C โ CD โ C
David's path: David โ D โ CD โ C
The magic: Every path leads to the same group secret
๐๏ธ How MLS Builds the Treeโ
When Alice Creates the Groupโ
Step 1: Alice creates ratchet tree
- She's the only one (leaf index 0)
- Her leaf node: A
- Tree root: C
Step 2: Bob joins
- New leaf added (leaf index 1)
- New parent node: AB
- Tree root updated: ABCD
Step 3: Charlie joins
- New leaf added (leaf index 2)
- New parent node: CD
- Tree root updated: ABCDEF
Step 4: David joins
- New leaf added (leaf index 3)
- Tree root updated (no new node needed)
๐ Key Rotation with Ratchet Treesโ
What Happens When Someone Leaves?โ
David leaves the group:
Before David leaves:
Alice (0), Bob (1), Charlie (2), David (3)
Tree has 4 leaves
After David leaves:
Alice (0), Bob (1), Charlie (2)
Tree now has 3 leaves
MLS updates tree:
- Remove David's leaf (3)
- Update path: D โ CD โ ABCD
- Generate new secrets on the path
- New group secret at root
Alice sends a message after rotation:
Alice โ A โ AB โ C (new)
Bob โ B โ AB โ C (new)
Charlie โ C โ CD โ C (new)
David:
โ D (deleted)
โ CD (deleted)
โ Can't get C (new)
Result: David can't decrypt any more messages
๐ฎ Try It Yourselfโ
Question 1: In a ratchet tree, Alice (index 0) wants to send a message. What's her path to the root?
Show Answer
Tree layout:
Alice(0) Bob(1) Charlie(2) David(3)
โ โ โ โ
โโ A โโ โ โโ B โโโโโโโโ
โ โ
โโโโโโ C โโโโ
Alice's path:
Alice (leaf 0)
โ
A (parent)
โ
C (root/group secret)
Answer: Alice โ A โ C
Question 2: David (index 3) leaves the group. Can he still read messages?
Show Answer
When David leaves:
- MLS removes David's leaf (3)
- MLS updates secrets on David's path:
- D (David's new secret at leaf) โ deleted
- CD (parent of C and D) โ new secret
- ABCD (root) โ new secret
David trying to decrypt:
- David's leaf deleted โ Can't start path
- Old CD secret โ Doesn't work (changed)
- Old ABCD secret โ Doesn't work (changed)
Answer: No, David can't read messages after key rotation
Question 3: Why use a binary tree instead of a list?
Show Answer This
Using a list (naive approach):
- For 1000 people, need to update 999 nodes
- Each update takes O(n) time
Using a binary tree (MLS approach):
- For 1000 people, need to update log2(1000) = 10 nodes
- Each update takes O(log n) time
Efficiency:
- List: O(n) = slow
- Tree: O(log n) = fast
Answer: Binary trees are MUCH faster for updates (O(log n) vs O(n))
๐ก Why Ratchet Trees Workโ
Three Magic Propertiesโ
-
Everyone can reach the root
- Every leaf has a path to the root
- Path length: O(log n)
- Very efficient
-
Removing someone updates the path
- Only need to update O(log n) nodes
- Not O(n) nodes like a list
- Fast๏ผ
-
Adding someone updates the path
- Only need to update O(log n) nodes
- Scalable to thousands
- Efficient๏ผ
โ Quick Checkโ
Can you explain ratchet trees to a 5-year-old?
Try saying this out loud:
A ratchet tree is like a family tree on its side. Each person is a leaf at the bottom. The grandpa at the top has the family secret. Everyone can climb up to the grandpa and learn the secret. If someone leaves the family, we change the secret, so they can't learn new secrets!
๐ Key Takeawaysโ
โ
Ratchet tree = Family tree on its side
โ
Leaves = Group members
โ
Root = Group secret
โ
Path = How each person gets the group secret
โ
Efficiency = O(log n) for updates
โ
Rotation = Change secrets on path when someone leaves
โ
Scalability = Works for 2 to 1000+ people
๐ What You'll Learn Nextโ
Now you understand ratchet trees Next, we'll learn about MLS's concept of time:
โฐ Continue: Time Traveling Messages
We'll learn about epochs and how MLS manages message history
Now you understand how MLS manages keys with ratchet trees. Next: How MLS tracks time with epochs