-
Notifications
You must be signed in to change notification settings - Fork 25
feat: operator doppelgänger protection with slot-based detection #692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mergify
merged 60 commits into
sigp:unstable
from
diegomrsantos:feat/operator-doppelganger-protection
Nov 5, 2025
Merged
Changes from 4 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
dfaf1b4
feat: add CLI config for operator doppelgänger protection
diegomrsantos 5e2b95e
feat: implement operator doppelgänger detection service
diegomrsantos fd01236
feat: integrate operator doppelgänger detection with message receiver
diegomrsantos 4237308
Merge branch 'unstable' into feat/operator-doppelganger-protection
diegomrsantos be56784
Merge branch 'unstable' into feat/operator-doppelganger-protection
diegomrsantos f776d11
Merge branch 'unstable' into feat/operator-doppelganger-protection
diegomrsantos eb99a99
fix: pass current epoch explicitly instead of using unwrap_or_else
diegomrsantos 3117374
fix: handle slot clock read failure in doppelgänger check
diegomrsantos 67b7126
refactor: simplify doppelgänger state management with Mutex
diegomrsantos 4834057
chore: change stale message log from warn to debug
diegomrsantos 8f98ea0
refactor: remove redundant enabled field from doppelgänger service
diegomrsantos 91836e3
test: add comprehensive tests for doppelgänger service
diegomrsantos d93ef67
Merge branch 'unstable' into feat/operator-doppelganger-protection
diegomrsantos 64146a6
refactor: extract operator doppelgänger initialization and add monito…
diegomrsantos e268715
refactor: apply best practices to operator doppelgänger feature
diegomrsantos 982db2e
refactor: parameterize slot duration in operator doppelganger service
diegomrsantos 892fcf6
refactor: remove update_and_check_freshness in favor of separate oper…
diegomrsantos 8006a91
test: remove redundant operator doppelganger tests
diegomrsantos 741c8ad
test: remove redundant initial state test
diegomrsantos 58170c6
lint
diegomrsantos 9276f25
refactor: extract operator_doppelganger to separate crate
diegomrsantos 632f5d4
refactor: remove blocking wait for operator doppelganger monitoring
diegomrsantos db1d9b2
refactor: simplify operator doppelganger by removing intermediary cha…
diegomrsantos ffc12a2
Merge branch 'unstable' into feat/operator-doppelganger-protection
diegomrsantos 90b58b1
docs: add architectural principles to CLAUDE.md
diegomrsantos e0bd8b2
refactor: replace height-based with grace period approach for operato…
diegomrsantos 2d1b48c
style: apply cargo fmt
diegomrsantos fc962b0
feat: expand doppelgänger detection to all operator-signed messages
diegomrsantos 00c7546
chore: simplify redundant grace period comments
diegomrsantos c06e7ce
refactor: simplify operator doppelgänger state management
diegomrsantos 571c3f8
refactor: replace epoch-based monitoring with single sleep timer
diegomrsantos 5a8ba76
refactor: remove unnecessary create_operator_doppelganger wrapper
diegomrsantos 433feba
refactor: remove unnecessary generics from OperatorDoppelgangerService
diegomrsantos b4212b1
test: add async timer tests for operator doppelgänger monitoring
diegomrsantos ba86842
refactor: convert all detection logic tests to use async timers
diegomrsantos de1a339
refactor: simplify async timer tests by using single yield
diegomrsantos 26ff439
refactor: replace boolean flags with explicit state enum
diegomrsantos 2aa1ffb
refactor: move DoppelgangerState to private implementation
diegomrsantos 56ef9a8
chore: remove unused dependencies from operator_doppelganger
diegomrsantos 7122d72
perf: use RwLock for read-optimized state access
diegomrsantos 885ab36
feat: block all outgoing messages during doppelgänger monitoring
diegomrsantos 072924a
Merge branch 'unstable' into feat/operator-doppelganger-protection
diegomrsantos 716b85c
docs: update CLAUDE.md with session learnings
diegomrsantos cd826ae
Merge branch 'unstable' into feat/operator-doppelganger-protection
diegomrsantos c56dd46
Merge branch 'unstable' into feat/operator-doppelganger-protection
diegomrsantos 550aea5
Merge branch 'unstable' into feat/operator-doppelganger-protection
diegomrsantos ff3c4a9
refactor: align operator doppelgänger grace period with message TTL w…
diegomrsantos 0fda8d4
fix: block outgoing messages during entire doppelgänger protection wi…
diegomrsantos a1a59b3
docs: update operator doppelgänger CLI help text
diegomrsantos 3ea5c20
refactor: replace grace period with slot-based operator doppelgänger …
diegomrsantos ba750d4
refactor: pass ValidatedSSVMessage to eliminate redundant SSZ decoding
diegomrsantos 42a1756
refactor: remove unnecessary start_operator_doppelganger wrapper
diegomrsantos 03f56a0
refactor: simplify doppelgänger protection with blocking monitoring
diegomrsantos 9ca3edb
Merge branch 'unstable' into feat/operator-doppelganger-protection
diegomrsantos fccefd0
remove unused dep
diegomrsantos d1499db
refactor: notifier with layered state architecture
diegomrsantos 0d9948a
Merge branch 'unstable' into feat/operator-doppelganger-protection
diegomrsantos b2172a6
refactor: store operator_id in OperatorState enum to eliminate unsafe…
diegomrsantos 9b53677
refactor: simplify startup_slot initialization
diegomrsantos 1269e0c
feat: disable operator doppelgänger protection by default
diegomrsantos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -484,6 +484,43 @@ pub struct Node { | |
| #[clap(long, help = "Disables gossipsub topic scoring.", hide = true)] | ||
| pub disable_gossipsub_topic_scoring: bool, | ||
|
|
||
| // Operator Doppelgänger Protection | ||
| #[clap( | ||
| long, | ||
| help = "Enable operator doppelgänger protection. When enabled, the node will monitor \ | ||
| for messages signed by its operator ID on startup and shut down if a twin \ | ||
| (duplicate operator) is detected. Enabled by default.", | ||
| display_order = 0, | ||
| default_value_t = true, | ||
| help_heading = FLAG_HEADER, | ||
| action = ArgAction::Set | ||
| )] | ||
| pub operator_dg: bool, | ||
|
|
||
| #[clap( | ||
| long, | ||
| value_name = "EPOCHS", | ||
| help = "Number of epochs to wait in monitor mode before starting normal operation. \ | ||
| During this period, the node listens for messages from its own operator ID \ | ||
| to detect if another instance is running.", | ||
| display_order = 0, | ||
| default_value_t = 2, | ||
| requires = "operator_dg" | ||
dknopik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| )] | ||
| pub operator_dg_wait_epochs: u64, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we are not actually waiting anywhere
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's a bit weird that when we use this, we need to set |
||
|
|
||
| #[clap( | ||
| long, | ||
| value_name = "HEIGHTS", | ||
| help = "The freshness threshold for detecting operator twins. Only messages within \ | ||
| this many consensus heights from the maximum observed height are considered \ | ||
| fresh evidence of a twin. This prevents false positives from replayed old messages.", | ||
| display_order = 0, | ||
| default_value_t = 3, | ||
| requires = "operator_dg" | ||
dknopik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| )] | ||
| pub operator_dg_fresh_k: u64, | ||
diegomrsantos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| #[clap(flatten)] | ||
| pub logging_flags: FileLoggingFlags, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| mod service; | ||
| mod state; | ||
|
|
||
| pub use service::OperatorDoppelgangerService; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| use std::{marker::PhantomData, sync::Arc}; | ||
|
|
||
| use parking_lot::RwLock; | ||
| use slot_clock::SlotClock; | ||
| use ssv_types::{ | ||
| OperatorId, consensus::QbftMessage, message::SignedSSVMessage, msgid::DutyExecutor, | ||
| }; | ||
| use tracing::{error, info, warn}; | ||
| use types::EthSpec; | ||
|
|
||
| use super::state::{DoppelgangerMode, DoppelgangerState}; | ||
|
|
||
| /// Service for detecting operator doppelgängers (duplicate instances) | ||
| pub struct OperatorDoppelgangerService<E: EthSpec, S: SlotClock> { | ||
| /// Our operator ID to watch for | ||
| own_operator_id: OperatorId, | ||
| /// Current state | ||
| state: Arc<RwLock<DoppelgangerState>>, | ||
| /// Slot clock for epoch tracking | ||
| slot_clock: S, | ||
| /// Enabled flag | ||
| enabled: bool, | ||
| /// Phantom data for EthSpec | ||
| _phantom: PhantomData<E>, | ||
| } | ||
|
|
||
| impl<E: EthSpec, S: SlotClock> OperatorDoppelgangerService<E, S> { | ||
| /// Create a new operator doppelgänger service | ||
| pub fn new( | ||
| own_operator_id: OperatorId, | ||
| slot_clock: S, | ||
| wait_epochs: u64, | ||
| fresh_k: u64, | ||
| enabled: bool, | ||
| ) -> Self { | ||
| let current_epoch = slot_clock | ||
| .now() | ||
| .map(|slot| slot.epoch(E::slots_per_epoch())) | ||
| .unwrap_or_else(|| types::Epoch::new(0)); | ||
|
|
||
| let state = Arc::new(RwLock::new(DoppelgangerState::new( | ||
| current_epoch, | ||
| wait_epochs, | ||
| fresh_k, | ||
| ))); | ||
|
|
||
| if enabled { | ||
| info!( | ||
| operator_id = *own_operator_id, | ||
| current_epoch = current_epoch.as_u64(), | ||
| wait_epochs, | ||
| fresh_k, | ||
| "Operator doppelgänger protection enabled, entering monitor mode" | ||
| ); | ||
| } else { | ||
| info!("Operator doppelgänger protection disabled"); | ||
| } | ||
|
|
||
| Self { | ||
| own_operator_id, | ||
| state, | ||
| slot_clock, | ||
| enabled, | ||
| _phantom: PhantomData, | ||
| } | ||
| } | ||
|
|
||
| /// Check if a message indicates a potential doppelgänger | ||
| /// | ||
| /// Returns true if a twin is detected (should trigger shutdown) | ||
| pub fn check_message( | ||
| &self, | ||
| signed_message: &SignedSSVMessage, | ||
| qbft_message: &QbftMessage, | ||
| ) -> bool { | ||
| if !self.enabled { | ||
| return false; | ||
| } | ||
|
|
||
| // Update mode based on current epoch | ||
| if let Some(slot) = self.slot_clock.now() { | ||
| let current_epoch = slot.epoch(E::slots_per_epoch()); | ||
| self.state.write().update_mode(current_epoch); | ||
| } | ||
|
|
||
| let state = self.state.read(); | ||
|
|
||
| // Only check in monitor mode | ||
| if !state.is_monitoring() { | ||
| return false; | ||
| } | ||
|
|
||
| // Extract committee ID from message | ||
| let committee_id = match signed_message.ssv_message().msg_id().duty_executor() { | ||
| Some(DutyExecutor::Committee(committee_id)) => committee_id, | ||
| _ => return false, // Not a committee message | ||
| }; | ||
|
|
||
| // Update the maximum height we've seen for this committee | ||
| drop(state); | ||
| self.state | ||
| .write() | ||
| .update_max_height(committee_id, qbft_message.height); | ||
| let state = self.state.read(); | ||
|
|
||
| // Check if this is a single-signer message with our operator ID | ||
| let operator_ids = signed_message.operator_ids(); | ||
| if operator_ids.len() != 1 { | ||
| // Not a single-signer message (could be aggregate/decided) | ||
| return false; | ||
| } | ||
|
|
||
| let signer = operator_ids[0]; | ||
| if signer != self.own_operator_id { | ||
| // Not signed by us | ||
| return false; | ||
| } | ||
|
|
||
| // Check if the message is fresh | ||
| if !state.is_fresh(committee_id, qbft_message.height) { | ||
| // Stale message, likely a replay - not evidence of a twin | ||
| warn!( | ||
| operator_id = *self.own_operator_id, | ||
| committee = ?committee_id, | ||
| height = qbft_message.height, | ||
| "Received stale message with our operator ID (likely replay), ignoring" | ||
| ); | ||
| return false; | ||
| } | ||
|
|
||
| // Fresh single-signer message with our operator ID = twin detected! | ||
| error!( | ||
| operator_id = *self.own_operator_id, | ||
| committee = ?committee_id, | ||
| height = qbft_message.height, | ||
| round = qbft_message.round, | ||
| message_type = ?qbft_message.qbft_message_type, | ||
| "OPERATOR DOPPELGÄNGER DETECTED: Received fresh message signed with our operator ID. \ | ||
| Another instance of this operator is running. Shutting down to prevent equivocation." | ||
| ); | ||
|
|
||
| true | ||
| } | ||
|
|
||
| /// Get the current mode | ||
| #[allow(dead_code)] | ||
| pub fn mode(&self) -> DoppelgangerMode { | ||
| self.state.read().mode() | ||
| } | ||
|
|
||
| /// Check if we're still in monitor mode | ||
| #[allow(dead_code)] | ||
| pub fn is_monitoring(&self) -> bool { | ||
| self.enabled && self.state.read().is_monitoring() | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.