Skip to content
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

RFC: Introducing Watchdog, a cross-layer anomaly detection module #18987

Closed
wants to merge 5 commits into from

Conversation

ariard
Copy link
Member

@ariard ariard commented May 16, 2020

This PR proposes to introduce a new subsystem for anomaly detection and notifications of those for corrective behaviors. It showcases a proof-of-concept laying out the design of such a new system with a new heuristic.

Prevention of eclipse-attacks and network partitions is critical for application security and user funds. Beyond fork detection and obvious protocol misbehavior, Bitcoin Core doesn't implement any active anomalies detection. These vulnerabilities may be even more destructive for time-sensitive protocol with harder security assumptions, such as those requiring real-time block processing with regards to honest majority network. Active detection at the base-layer, where it's easier to monitor, may be used in two ways:
a) With an application, like a payment system or a LN node, cutting its deposit flow or closing its channels in reaction or stopping HTLC processing, and therefore limiting exposure.
b) With an internal Bitcoin Core module, triggering rescue header-fetching -- see the AltNet subsystem proposal as an example of consumer usage.

Even if notifications must be interpreted according to application requirements, such automatic reactions, well-implemented, would be a positive increase for their security.

Detection may rely on a wide range of cross-layer heuristics, including the local clock, packets RTT, ASN distribution among addrman, abnormal peer rotation, stalling or delayed block issuance, mempool congestion and bandwidth consumption surges. You may combine heuristics to increase confidence, but due to the p2p nature of the network or Poisson block interval false positives must be taken into account. Ideally consumer would be able to fine-tune their false-positives exposure with regards to application security and the cost of their reaction.

This PR introduces a new module (CWatchdog), with low-reliance on other modules beyond synchronous events harvesting (LogHeader). Anomalie detections (ScanAnomalie) is scheduled each SCAN_ANOMALIES_INTERVAL on its own thread. Integration is done with NodeContext, making the module accessible to future RPCs. A subscription interface (CWatchdogInterface) is added, the model of CValidationInterface. This can host the actual fork detection in the future after refactoring CheckForkWarningConditions.

This new module, less intertwined with current code can be disabled by default, and only activated with --enable-watchdog by node operators willingly to use it.

Antoine Riard added 5 commits May 16, 2020 02:51
CWatchdog is a cross-layer anomalies detection module aims to
cover block issuance, peer management, local clock or net level.

If any anomalie is detected an event is triggered to inform an
application layer or any internal consumer of a future watchdog
interface.

This code is only integrated in next commit.
CWatchdogInterface is consumed by another module or application
willingly to take corrective actions based on anomalies detected.

CWatchdogInterface only callback is BlockHeaderAnomalies, meaning
block header aren't received at a normal rate modulo block variance.
CWatchdog is integrated in NodeContext to make it accessible to any
futute rpc calls. Some application may fine-tune watchdog according
to their requirements.

This code is not scheduled yet.
Run ScanAnomalies to process any heuristics and trigger watchdog
interface callback.

As of present commit, there is no heuristic implemented, callback
is blankly called to exerce watchdog interface.
Insert watchdog LogHeader after a successful ProcessNewBlockHeaders,
therefore updating last time watchdog have seen a step forward
on headers tree construction.

Watchdog loggers should be designed on being invasive-minimal at they
may encumber hot paths.
@DrahtBot
Copy link
Contributor

DrahtBot commented May 16, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

@0xB10C
Copy link
Contributor

0xB10C commented Aug 3, 2021

I haven't looked at this PR closer, but I think anomaly detection could be done via USDT in an external application hooking into Bitcoin Core internals too.

bandwidth consumption surges

This could be done with the net tracepoints for inbound / outbound P2P messages. See this example https://bitcoind.observer/p2p-network-traffic and code https://github.com/0xB10C/bitcoind-observer.

Prevention of eclipse-attacks, ASN distribution among addrman

I've added a few tracepoints (not in a PR yet) to addrman to externally observe the new and tried tables too. See e.g. this realtime visualization (colors are addr type here, but could also be AS based) of my addrman tables:

image

Let if you think this might be an alternative to a module in Bitcoin Core. Happy to chat.

@ariard
Copy link
Member Author

ariard commented Aug 4, 2021

Honestly, I've not been that far in the design of a specific hook interface servicing watchdog/statistical tools.

This PoC was relying on a CWatchdogInterface inspired from the current CValidationInterface. Though one of the prevailing feedback I received with this proposal was that it would be far better to have the module separated in another runtime, and even external to Bitcoin Core internals or build system. Thus letting any module to be plugged in.

One solution I'm working on is pursuing on the work done by multiprocess with the newly introduced abstract interfaces (src/interfaces), where your potential external modules could be written in Rust to talk directly to core C++ code through Cap'n Proto or in the future another protocol (fyi, see chaincodelabs/libmultiprocess#56).

Of course, w.r.t to event collection, the USDT approach you're proposing sounds the right tool. One could imagine a watchdog module where the low-level event collection is gathered through tracing and the high-level corrective logic relying on a *.capnp interface, all bundled in the same runtime.

This could be done with the net tracepoints for inbound / outbound P2P messages. See this example https://bitcoind.observer/p2p-network-traffic and code https://github.com/0xB10C/bitcoind-observer.

I need to think more, but I think tracepoints could cover the whole range of proposed heuristics: local clock, packets RTT, peer rotation frequency, mempool feerate groups, ... ?

Let if you think this might be an alternative to a module in Bitcoin Core. Happy to chat.

First impression, I think this tracepoint approach is far better than yet-another-non-critical-module in core for sure. Yeah happy to chat, on this PR, a new issue or irc :)

@DrahtBot
Copy link
Contributor

There hasn't been much activity lately and the patch still needs rebase. What is the status here?
  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

@maflcko
Copy link
Member

maflcko commented Apr 29, 2022

Closing for now. Let us know when this should be reopened.

@maflcko maflcko closed this Apr 29, 2022
@bitcoin bitcoin deleted a comment Apr 29, 2022
@bitcoin bitcoin locked and limited conversation to collaborators Apr 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants