Skip to content

feat(mix): DoS protection integration#3931

Open
chaitanyaprem wants to merge 4 commits into
masterfrom
feat/mix-dos-protection-libp2p-v2.0.0
Open

feat(mix): DoS protection integration#3931
chaitanyaprem wants to merge 4 commits into
masterfrom
feat/mix-dos-protection-libp2p-v2.0.0

Conversation

@chaitanyaprem

@chaitanyaprem chaitanyaprem commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Adds DoS / spam protection to the mix protocol (RLN-based).

The libp2p v2.0.0 bump, the logos_delivery/ folder restructure (#3935), and the service-discovery framework (#3947) are now in master. This branch is rebased onto current master, so they're no longer part of this diff — this PR's delta is the mix DoS-protection work + minor fixes only.

What's in this PR

Mix DoS / spam protection (RLN)

  • Integrates mix-rln-spam-protection-plugin into the mix protocol — mix messages carry an RLN proof, intermediate hops verify it, per-sender rate-limited via userMessageLimit. (waku_mix/protocol.nim, waku_node.nim)
  • Stateless RLN (Nim-side IMT, ffi_verify_with_roots; no local Merkle tree).
  • DoS self-registration split into a background retry task off the startup path.
  • Spam-protection coordination over Waku filter (waku_mix_coordination.nim, new).

Adaptive mix-peer discovery — generic runServicePeerTopUp loop pulls more mix-service peers via the ServicePeersRequest broker while the pool is below target; keeps WakuKademlia generic.

Minor — chat2mix demo + mixnet sim harness (simulations/mixnet/); dep pins (mix-rln-spam-protection-plugin, libp2p_mix, nim-sds); small build/test fixes.

Validation

  • wakunode2 + chat2mix build clean; tests/waku_kademlia 14/14.
  • Mixnet sim: 5-node mixnet boots, RLN spam-protection runs, mix pool fills via the broker top-up, end-to-end message delivered (alice → bob over mix).

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

You can find the image built from this PR at

quay.io/wakuorg/nwaku-pr:3931

Built from fbb612b

@Ivansete-status

Copy link
Copy Markdown
Collaborator

Thanks for that PR @chaitanyaprem
Nevertheless, we want to have the nim-libp2p bump to v2.0.0 into a separate PR and @fcecin is currently working on that. We'll keep you posted.

@fcecin

fcecin commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for that PR @chaitanyaprem Nevertheless, we want to have the nim-libp2p bump to v2.0.0 into a separate PR and @fcecin is currently working on that. We'll keep you posted.

Also it may be possible that some of the work in this PR should be ported to the other bump PR in any case (i.e. if what is done here to bump is preferred over what I did in my PR to bump)

@chaitanyaprem

Copy link
Copy Markdown
Contributor Author

Thanks for that PR @chaitanyaprem Nevertheless, we want to have the nim-libp2p bump to v2.0.0 into a separate PR and @fcecin is currently working on that. We'll keep you posted.

Makes sense, i was doing this more from a point of validating using single zerokit compiled lib for both rln relay and mix DoS protection. I got stuck and had to do this update, so i thought it would be useful for whoever is doing the bump hence checked it in.

The idea is once you guys bump libp2p, i will just rebase onto that and only have mix related changes :)

@chaitanyaprem

chaitanyaprem commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Also it may be possible that some of the work in this PR should be ported to the other bump PR in any case (i.e. if what is done here to bump is preferred over what I did in my PR to bump)

I would leave that upto you, i just took shortest and easiest path to make it work in order to test mix DoS protection simulation with zerokit-2.0.2 statless built and reused across rln relay and mix. You may have better idea if some of these changes make sense or not.

Let me know once 2.0.0 bump branch is ready so that i can rebase onto it.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

This PR may contain changes to configuration options of one of the apps.

If you are introducing a breaking change (i.e. the set of options in latest release would no longer be applicable) make sure the original option is preserved with a deprecation note for 2 following releases before it is actually removed.

Please also make sure the label release-notes is added to make sure any changes to the user interface are properly announced in changelog and release notes.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

This PR may contain changes to database schema of one of the drivers.

If you are introducing any changes to the schema, make sure the upgrade from the latest release to this change passes without any errors/issues.

Please make sure the label release-notes is added to make sure upgrade instructions properly highlight this change.

@chaitanyaprem
chaitanyaprem force-pushed the feat/mix-dos-protection-libp2p-v2.0.0 branch from 111f0a3 to d529be1 Compare June 8, 2026 15:28
@chaitanyaprem
chaitanyaprem force-pushed the feat/mix-dos-protection-libp2p-v2.0.0 branch 2 times, most recently from efe5e1e to 3f0f14c Compare June 22, 2026 06:59
@chaitanyaprem chaitanyaprem changed the title feat(mix): DoS protection + bump libp2p stack to v2.0.0 feat(mix): DoS protection Jun 22, 2026
…based onto #3935)

Squash of 13 commits from feat/mix-dos-protection-libp2p-v2.0.0 onto the
logos_delivery/ folder-restructure base from #3935 (build-messaging-folder).

Original commit history (squashed):
- d8e6dce feat(mix): integrate mix protocol with extended kademlia + RLN spam protection
- fb72f18 refactor(mix): split DoS-protection self-registration into background retry
- d8bbef0 feat(mix): bump libp2p stack to v2.0.0 + adopt stateless RLN spam protection
- 2f24448 fix(tests): use HmacDrbgContext.new() instead of crypto.newRng()
- 5a21455 fix(ci): regen nimble.lock for v2.0.0 + disambiguate rng in wakucore
- 03ef02a fix(tests): wrap HmacDrbgContext via newBearSslRng for libp2p v2.0.0
- 167ab1d fix(nix): regenerate deps.nix from updated nimble.lock
- 97a2722 fix(tests): wrap or pass Rng correctly for 3-arg PrivateKey.random
- 5561fcb fix(tests): replace removed newStandardSwitch with SwitchBuilder
- ba39ee4 fix(tests): libp2p v2.0.0 API migrations across test suite
- 328e11d fix: gitignore test binaries + remove accidentally-committed binary
- cc71244 fix(tests): more v2.0.0 API migrations (rng template, PeerId.random, etc.)
- 412d97a fix(tests): unblock CI — nph, excise orphan waku_noise, complete v2.0.0 Rng migration

Conflict resolutions (#3935 → ours):
- 11 import-path migrations: waku/X → logos_delivery/waku/X
- waku_node/waku_node/relay.nim: dropped our `registerRelayHandler` proc
  (relocated to subscription_manager.nim by #3935; see cascade fix below)
- factory/builder.nim: combined both sides' new imports (net_config + waku_switch)
- factory/conf_builder/mix_conf_builder.nim: libp2p_mix package (not libp2p/protocols/mix)
- waku_mix/protocol.nim: combined paths + our mix_rln_spam_protection/relay/nimchronos imports
- 3 test files: dropped noise_utils import (replicates noise excision from original PR)
- 2 UA file moves: option_shims.nim and waku_mix_coordination.nim added at new paths

Cascade fixes (#3935 lost our work, restored):
- subscription_manager.nim: added `mixHandler` to #3935's `registerRelayHandler`,
  and added `waku_mix` to its imports. Without this, mix messages were silently
  dropped from the relay handler chain.
- config.nims: option_shims auto-import path migrated to logos_delivery/...

Validation:
- nph check on all 82 staged .nim files: clean (0 reformats needed)
- wakunode2 build: exit 0, 38 MB binary
- (sim PASS confirmed in earlier identical-state run: 5/5 mix init,
  5 RLN proofs gen/verify, 0 errors)

Backup tag at original tip: backup/3931-pre-3935-rebase (412d97a).
Rename the call site to the typedesc constructor
MixRlnSpamProtection.new (was newMixRlnSpamProtection) to match
nim-libp2p conventions, and bump the mix-rln-spam-protection-plugin
pin to 61ee3e5 which provides the renamed constructor.
Add a generic runServicePeerTopUp loop in waku_node that, while a service's provider count is below target, pulls more peers through the ServicePeersRequest broker; wired for mix in WakuNode.start(). Move the ServicePeersRequest provider registration into the startProvidersAndListeners/stopProvidersAndListeners lifecycle (gated on kademlia) so chat2mix gets it too, keeping WakuKademlia generic. Also fix pre-existing chat2mix build errors (toHashSet, valueOr, std/sets import).
@chaitanyaprem
chaitanyaprem force-pushed the feat/mix-dos-protection-libp2p-v2.0.0 branch from 3f0f14c to eea07b1 Compare June 22, 2026 09:05
@chaitanyaprem
chaitanyaprem marked this pull request as ready for review June 22, 2026 09:08
@chaitanyaprem chaitanyaprem changed the title feat(mix): DoS protection feat(mix): DoS protection integration Jun 22, 2026

@Ivansete-status Ivansete-status left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some comments so far. Thanks!

Comment thread apps/chat2mix/chat2mix.nim Outdated
Comment thread apps/chat2mix/chat2mix.nim Outdated
Comment thread apps/chat2mix/chat2mix.nim Outdated
Comment thread logos_delivery/waku/node/peer_manager/peer_manager.nim Outdated
Comment thread logos_delivery/waku/factory/waku.nim Outdated
Comment thread logos_delivery/waku/waku_mix/protocol.nim Outdated
Comment thread logos_delivery/waku/waku_mix/protocol.nim Outdated
Comment thread logos_delivery/waku/waku_mix/protocol.nim Outdated
Comment thread logos_delivery/waku/waku_mix/protocol.nim Outdated
Comment thread logos_delivery/waku/waku_mix/protocol.nim Outdated
- protocol.nim: use isOkOr in handleMessage/start, drop identity mapErr,
  drop redundant gcsafe on handleMessage
- waku_node.nim: handle relay publish error; simplify runServicePeerTopUp
  (drop count-getter param, use getMixNodePoolSize directly)
- factory/waku.nim: drop redundant explicit service setup calls (the loop
  over switch.services already sets them up)
- peer_manager.nim: drop duplicate waku_switch import
- chat2mix.nim: remove redundant echo, simplify async signature, capture
  spam-protection maintenance future and cancel it on /exit
- delete unused waku_mix_coordination.nim (dead duplicate of chat2mix logic)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants