Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

feat(54/WAKU2-X3DH-SESSIONS): include topic usage #587

Merged
merged 6 commits into from
Apr 17, 2023
Merged

Conversation

rymnc
Copy link
Contributor

@rymnc rymnc commented Mar 23, 2023

After confirming with the implementation, this PR includes the topic usage and negotiation for x3dh based sessions used by the status desktop app.

@rymnc rymnc marked this pull request as ready for review March 23, 2023 10:22
@rymnc rymnc requested a review from kaiserd March 23, 2023 10:22
@rymnc rymnc self-assigned this Mar 23, 2023
@rymnc
Copy link
Contributor Author

rymnc commented Mar 23, 2023

cc: @felicio

Copy link
Contributor

@kaiserd kaiserd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this :).
I left some comments in-line.

content/docs/rfcs/54/README.md Outdated Show resolved Hide resolved
@@ -29,13 +29,73 @@ A node identifies a peer by their `installation-id` which MAY be interpreted as
## Discovery of pre-key bundles

The node's pre-key bundle SHOULD be broadcasted on a content topic derived from the node's public key.
<!--- TODO: We need to move other specs from status to vac research, including STATUS-WAKU-USAGE -->
The derivation is further described in [10/WAKU-USAGE](https://specs.status.im/spec/10#contact-code-topic)
Peers MUST derive a topic from their public key to broadcast their pre-key bundles on, so that the first message may be PFS-encrypted.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence and the one before overlap.
Suggestion: replace both with:

The node's pre-key bundle MUST be broadcast on a content topic derived from the node's public key,
, so that the first message may be PFS-encrypted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: What is the first message in this context?

Copy link
Contributor Author

@rymnc rymnc Mar 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in c03a83b

The first message is the pre-key bundle they send

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, the phrasing suggests that the PFS of this message is dependent on the fact that the topic name is derived from the key. How are these connected?

Copy link
Contributor

@kaiserd kaiserd Mar 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is any data appended the message that also contains the pre-key bundle?

Would this match what is done in the impl:

Nodes MUST derive a topic from their public key to broadcast their pre-key bundles on.
This allows peers to infer the topic on which they can receive this pre-key bundle.
Data appended to the pre-key bundle message, as well as following messages, can be PFS-encrypted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc: @felicio for confirmation, afaik, this is not done in the impl

content/docs/rfcs/54/README.md Outdated Show resolved Hide resolved
content/docs/rfcs/54/README.md Outdated Show resolved Hide resolved
content/docs/rfcs/54/README.md Show resolved Hide resolved

var hash []byte = keccak256(partitionTopic)
var topicLen int = 4

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why limiting topicLen like this and not simply using keccak256(partitionTopic) as the topic name.
It only saves 4 bytes, and topic names are typically descriptive, i.e. 4 more bytes should not matter much.

Also what is the resulting topic name?
Is it simply the content of var topic [4]byte

To be more in line with https://rfc.vac.dev/spec/23/ , the topic could be named:

/status/<version>/1to1/<keccak256(partitionTopic)>

cc @felicio

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure, this is how its implemented afaik

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait for Status feedback :).

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got back from a vacation, will check this PR today.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I don't have the historical context for the length, I believe it was inherited from Whisper where even there I'd say it was an arbitrary constant that was considered collision resistant enough.

About the resulting topic name, see #567 (comment).

And as far as being in line goes, I agree. The way I see it now we're "overloading" the bridging spec and should revisit the need for bridging or send to both format. Actually following Waku v2 spec for content topics would help with monitoring too I believe, see https://discord.com/channels/864066763682218004/1075738141681528863/1075747858067759174.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it answers why this was chosen :).
Thanks @felicio for poiting out the bridge.
Bridge copies v2 contentTopics into v1 topics (which have a 4bytes limit).
Imo, we should update the bridge spec to hash contentTopic to a 4byte topic instead of simply copying it,
because v2 topics do not have the size limit. The current version of the bridging spec does not take the size limit into consideraiton.
If we do this, we can also move to Waku v2 contentTopic names, as suggested above.

Also, bridging to v1 would introduce scaling problems and we should not do that for the MVP... Imo, it should be limited to specific cases.
Adding @jm-clius to the discussion regarding bridge.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. Bridging from/to v1 is not considered for this MVP (and likely wouldn't be required in future either).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying this :).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felicio we could integrate hierarchical topic naming into the RFC now in this PR, or wait until post-MVP and integrate topic naming as the current version of this PR reflects.
What would Status app prefer?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post-MVP, please. But would appreciate a follow-up issue for tracking.


After the peers have performed the initial key exchange, they MUST derive a topic from their shared secret to send messages on.
To obtain this value, take the first four bytes of the keccak256 hash of the shared secret encoded in hexadecimal format.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(see above: why only 4 bytes; does not save much in this context.)

content/docs/rfcs/54/README.md Show resolved Hide resolved
content/docs/rfcs/54/README.md Outdated Show resolved Hide resolved
@kaiserd
Copy link
Contributor

kaiserd commented Mar 24, 2023

Thanks :). I added a few more comments.

@rymnc rymnc requested a review from kaiserd April 11, 2023 04:57
Copy link
Contributor

@kaiserd kaiserd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for pre-MVP.
I'll open a follow-up issue for open points.

@rymnc rymnc merged commit ff6ccb0 into master Apr 17, 2023
@rymnc rymnc deleted the topic-usage-1to1 branch April 17, 2023 08:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants