crytic / attacknet

Tool and testing methodology for subjecting blockchain devnets to simulated network and side channel attacks
https://www.trailofbits.com/
GNU Affero General Public License v3.0
55 stars 8 forks source link

Attacknet

Blockchain networks in the wild are subject to a lot of real life variances that have historically been difficult to capture in local or controlled tests. Chaos testing is a disciplined approach to testing a system by proactively simulating and identifying failures. Attacknet is a tool that allows you to simulate these real life variances in a controlled environment. Examples would include adding network latency between nodes, killing nodes at random, or filesystem latency.

The overall architecture of Attacknet relies on Kubernetes to run the workloads, Kurtosis to orchestrate a blockchain network and Chaos Mesh to inject faults into nodes. Attacknet can then be configured to run healthchecks and reports back the state of the network at the end of a test.

docs/attacknet.svg

Capabilities

The faults supported by Attacknet include:

Attacknet can be used in the following ways:

See DOCUMENTATION.md for specific usage examples.

Getting started

Installation/Building

  1. Install Go 1.21 or newer
  2. In the project root, run go build ./cmd/attacknet
  3. Copy the "attacknet" binary path to your PATH variable or directly invoke it

Setting up the other bits

  1. Set up a containerd k8s cluster. (1.27 or older), ideally without auto-scaling (as high provisioning time leads to timeouts on kurtosis)
  2. Authenticate to the cluster for kubectl
  3. Install chaos-mesh
    1. kubectl create ns chaos-mesh
    2. helm repo add chaos-mesh https://charts.chaos-mesh.org
    3. helm install chaos-mesh chaos-mesh/chaos-mesh -n=chaos-mesh --version 2.6.1 --set chaosDaemon.runtime=containerd --set chaosDaemon.socketPath=/run/containerd/containerd.sock --set dashboard.securityMode=false --set bpfki.create=true
    4. To access chaos dashboard, use kubectl --namespace chaos-mesh port-forward svc/chaos-dashboard 2333
  4. Install kurtosis locally
  5. Run kurtosis cluster set cloud, more information here
  6. If running in digitalocean, edit the kurtosis-config.yml file from kurtosis config path and add the following setting under kubernetes-cluster-name: storage-class: "do-block-storage"
  7. In a separate terminal, run kurtosis engine start
  8. In a separate terminal, run kurtosis gateway. This process needs to stay alive during all attacknet testing and cannot be started via SDK.

Usage/Configuration

See DOCUMENTATION.md

Contributing

This tool was developed as a collaboration between Trail of Bits and the Ethereum Foundation. Thank you for considering helping out with the source code! We welcome contributions from anyone on the internet, and are grateful for even the smallest of fixes!

If you use this tool for finding bugs, please do ensure that the bug is reported to the relevant project maintainers or to the Ethereum foundation Bug bounty program. Please feel free to reach out to the tool maintainers on Discord, Email or Twitter for any feature requests.

If you want to contribute to Attacknet, we recommend running pre-commit before making changes:

  1. Install pre-commit
  2. Run pre-commit install

When making pull requests, please target the develop branch, not main.

Changelog

July 11, 2024 version v1.0.1

March 18, 2024 version v1.0.0

First public release!

New

Fixed

Jan 30, 2024 version v0.3 (internal)

Jan 11, 2024 version v0.2 (internal)

Dec 15, 2023 version v0.1 (internal)