Skip to content

Feat/nmv3 agents subscription#6567

Merged
jstuczyn merged 8 commits intofeat/mix-stress-testingfrom
feat/nmv3-agents-subscription
Apr 23, 2026
Merged

Feat/nmv3 agents subscription#6567
jstuczyn merged 8 commits intofeat/mix-stress-testingfrom
feat/nmv3-agents-subscription

Conversation

@jstuczyn
Copy link
Copy Markdown
Contributor

@jstuczyn jstuczyn commented Mar 17, 2026

NR-759

Nym node chain watcher and network monitors agents bypass

Summary

This PR introduces real-time blockchain monitoring for network monitor agent authorizations and implements replay protection bypass for authorized network monitor (NM) agents. This allows NM agents to perform node stress testing, while maintaining security for regular traffic.

Key Changes

1. Real-Time Blockchain Subscription for Network Monitor Agents

  • New Module: nym-node/src/node/nyxd_watcher/network_monitor_agents.rs

    • Implements MsgModule trait to watch for Network Monitors smart contract messages
    • Automatically updates authorized NM agent list when AuthoriseNetworkMonitor, RevokeNetworkMonitor, or RevokeAllNetworkMonitors messages are executed on-chain
  • Integration: Websocket subscription to nyx blockchain using the enhanced nyxd-scraper framework

    • Real-time updates without polling overhead
    • Survives transient network failures with automatic reconnection

2. Replay Protection Bypass for Authorized Network Monitors

  • Implementation Location: nym-node/src/node/mixnet/handler.rs
    • Checks if replayed packet originates from an authorized NM agent IP
    • Allows NM agents to bypass replay detection while enforcing it for all other traffic
    • Maintains per-connection authorization check via is_from_authorised_network_monitor_agent()

3. Enhanced Prometheus Metrics

  • New/Fixed Metrics:
    • ingress_replayed_packet() - Now properly tracked when replay detection triggers
    • ingress_network_monitor_packet() - Counts packets from authorized NM agents

Technical Details

Packet Journey for Replay Protection

handle_received_nym_packet()
  ↓
handle_received_packet_with_replay_detection()
  ↓
try_partially_unwrap_packet() [derive secrets, check MAC]
  ↓
batch_check_and_set() [bloomfilter replay detection]
  ↓
handle_post_replay_detection_packets()
  ↓
if replayed && !is_from_authorised_network_monitor_agent():
    → drop packet + increment metrics
else:
    → finalise_unwrapping() + forward packet

Authorization Flow

Contract ExecuteMsg::AuthoriseNetworkMonitor { address: IpAddr }
  ↓
Blockchain transaction committed
  ↓
NetworkMonitorAgentsModule receives message via MsgModule
  ↓
DeclaredNetworkMonitors.add_known(address)
  ↓
ArcSwap updates live filter (lock-free)
  ↓
ConnectionHandler checks is_from_authorised_network_monitor_agent()

Testing Considerations

  • Network monitor agents can now intentionally send replayed packets for testing
  • Operators can monitor NM activity via new Prometheus metrics
  • Real-time authorization updates without node restarts

Breaking Changes

None - fully backward compatible with existing configurations.

Security Implications

  • Authorization is on-chain and requires execute privileges
  • Only specific IP addresses can bypass replay protection
  • All bypass activity is logged and metrics-tracked
  • Operators should monitor ingress_network_monitor_packet metric for unexpected activity

Related Issues


This change is Reviewable

@jstuczyn jstuczyn force-pushed the feat/nmv3-agents-contract branch from 0d448ec to 8b74347 Compare March 17, 2026 15:04
@jstuczyn jstuczyn force-pushed the feat/nmv3-agents-subscription branch from 46a5856 to add8d89 Compare March 17, 2026 15:04
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nym-explorer-v2 Ready Ready Preview, Comment Apr 23, 2026 0:20am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs-nextra Ignored Ignored Preview Apr 23, 2026 0:20am
nym-node-status Ignored Ignored Preview Apr 23, 2026 0:20am

Request Review

Comment thread nym-node/src/config/mod.rs
}

fn swap(&self, new: HashSet<IpAddr>) {
self.inner.known.store(Arc::new(new))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's not a compare and swap, if by any chance two threads arrive at the same time, the first update will be lost

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

which is not a problem because there is only ever one thread performing writes to the list of known addresses. the arcswap exists here for the purposes of lock-free reads and eventual consistency

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we then update the comment about it being thread-safe?

Comment thread nym-node/src/node/shared_network/refresher.rs
.iter()
.all(|p| allowed.contains(p) || denied.contains(p))
{
return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the pending addresses are already resolve, we might want to clear them no?

Comment thread nym-node/src/node/nym_apis_client.rs Outdated
Comment thread nyx-chain-watcher/src/chain_scraper/mod.rs
Comment thread nym-node/src/config/mod.rs
// NO → Process normally (finalise_unwrapping)
// YES → Go to step 2
//
// 2. Is source IP an authorised network monitor?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This might not be enough, IP addresses can be spoofed

Comment thread nym-node/src/node/nyxd_watcher/network_monitor_agents.rs
///
/// # Thread Safety
///
/// Safe to use across threads - updates to `network_monitors` use lock-free ArcSwap internally.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actually not, as the update is not a compare and swap. Badly timed updates will overwrite each other. See comment in network_filter.rs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

as I mentioned there's only a single writer thread, so it's fine. the module wasn't designed with multiple writers in mind

@jstuczyn jstuczyn force-pushed the feat/nmv3-agents-subscription branch from c01b728 to 617acd4 Compare April 23, 2026 11:46
Base automatically changed from feat/nmv3-agents-contract to feat/mix-stress-testing April 23, 2026 12:12
@jstuczyn jstuczyn merged commit bac39a2 into feat/mix-stress-testing Apr 23, 2026
10 of 15 checks passed
@jstuczyn jstuczyn deleted the feat/nmv3-agents-subscription branch April 23, 2026 12:20
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