Scenario Authoring Guide¶
Core Concepts¶
A scenario defines the deterministic blockchain environment prior to the execution of an experiment. It provides the execution context for the attack plugin by specifying:
- Target Chains: The EVM networks to be forked.
- State Verification: Pre-execution assertions on storage slots or contract existence.
- Preconditions: Setup operations (e.g., helper contract deployment, account funding).
- Postconditions: Assertions validating the outcome of the experiment.
Architectural Separation¶
The testbed decouples environment setup from exploit execution to maximize reusability:
| Component | Purpose | Format |
|---|---|---|
Scenario (scenarios/<name>/scenario.yaml) |
Environment initialization, state preparation, and precondition enforcement. | Declarative YAML |
Attack Plugin (attacks/<name>/<name>.py) |
Exploit execution (calldata forging, transaction submission). | Python |
Experiment (experiments/<name>_replay.yaml) |
Orchestration layer binding the scenario, attack plugin, and topology. | Declarative YAML |
This decoupling allows researchers to: - Test the same attack plugin against multiple scenarios (e.g., different fork blocks or state variations). - Apply different attack variations within the same predefined scenario. - Swap underlying network topologies without modifying the attack implementation.
Scenario Definition Structure¶
Scenarios are defined in YAML. A standard scenario organizes operations into ordered phases.
name: my_attack_pre_exploit
description: >-
Initializes the Ethereum fork at block 15259100.
Verifies vulnerable contract state prior to exploit execution.
version: "1.0.0"
chains:
- ethereum
phases:
- name: setup
steps:
- type: log
message: "Initializing Ethereum fork at block 15259100"
- name: attack
steps:
- type: log
message: "Yielding execution to attack plugin"
- name: verify
steps:
- type: assert
name: exploit_succeeds
expected: true
actual: true
Unstructured Execution (Simple Format)¶
For scenarios that do not require explicit setup, attack, and verify phases, Crucible supports a flat execution model using the steps: array. In this format, all scenario steps execute sequentially prior to the attack plugin.
name: simple_scenario
chains: [ethereum]
steps:
- type: log
message: "Executing preconditions"
- type: impersonate
chain: ethereum
account: "0xAttacker"
Directory Hierarchy¶
scenarios/
my_attack_pre_exploit/
scenario.yaml # Scenario definition manifest
steps.py # Optional Python extensions (for python_script steps)
Phase Execution and Checkpointing¶
Scenarios execute in ordered phases. The attack plugin's execution is automatically interleaved between the scenario's phases by the ExperimentRunner.
flowchart LR
P1["Phase 1: setup<br>Precondition steps executed"]
P2["Phase 2: attack<br>Attack plugin execute() method invoked"]
P3["Phase 3: verify<br>Postcondition steps executed"]
P1 --> P2
P2 --> P3
Phase Checkpoints¶
The CheckpointManager captures a deterministic EVM state snapshot upon the completion of each phase.
Artifact Structure:
states/checkpoints/
<run_id>/
checkpoint.json # Execution manifest (phases, timestamps)
integrity.json # SHA-256 integrity hashes
setup.ethereum.json # EVM state snapshot post-setup
attack.ethereum.json # EVM state snapshot post-attack
verify.ethereum.json # EVM state snapshot post-verify
Mechanics:
1. Upon phase completion, anvil_dumpState captures the EVM state for all chains in the active topology.
2. Snapshots are structurally validated and hashed (SHA-256).
3. integrity.json maintains the authoritative hash record to prevent silent data corruption.
4. If execution is interrupted, ExperimentRunner.resume() restores the latest valid snapshot via anvil_loadState.
# Resume an interrupted experiment from the latest checkpoint
crucible experiment resume DS-2026-00155
# Enumerate available checkpoints
crucible experiment checkpoints
Note: Checkpoints are scoped to the active topology. Stale .meta.json artifacts from previous topologies are automatically excluded.
Scenario Step Reference¶
The following step types are supported within scenario phases.
1. log¶
Records an informational message to the experiment execution log (run.jsonl).
2. assert¶
Evaluates a boolean condition. Execution halts and the experiment is marked as a failure if the condition is false.
3. impersonate¶
Instructs the Anvil node to bypass private key validation for a specific address.
4. send_tx¶
Dispatches a transaction to the specified chain. Supports symbolic address resolution.
- type: send_tx
chain: ethereum
from: "0xAttackerAddress"
to: "bridge.ethereum"
value: 1000000000000000000
data: "0x123456"
5. advance_time¶
Advances the EVM timestamp and forces block generation.
6. assert_balance¶
Verifies that the native token balance of an address meets specific constraints.
- type: assert_balance
chain: ethereum
account: "0xVaultAddress"
min_value: 1000000000000000000 # Optional: Minimum balance in wei
exact_value: 0 # Optional: Exact expected balance
7. forge_script¶
Executes a Foundry Solidity script via subprocess, injecting the current RPC URL. The script must reside in scenarios/<name>/ or scripts/.
- type: forge_script
chain: ethereum
script: "Exploit.s.sol:ExploitScript"
extra_args:
- "--sender"
- "0xAttackerAddress"
8. python_script¶
Dynamically loads and executes a Python script. By default, it searches for steps.py within the scenario directory, though a custom path may be specified to execute shared scripts.
The script path is resolved in the following order:
1. Relative to the workspace root (e.g., for shared scripts).
2. Relative to the scenario directory (scenarios/<name>/).
The script must implement a run(context: ExperimentContext) entrypoint:
from crucible.rpc import JsonRpcClient
from crucible.sdk import ExperimentContext
def run(context: ExperimentContext):
rpc_url = context.chains.runtime_for("ethereum").rpc_url
client = JsonRpcClient(rpc_url)
# Implementation logic
9. verify_tracing¶
Validates that the instrumentation proxy has successfully captured transaction traces for the specified chains. Minimum threshold constraints may be enforced to ensure sufficient artifact generation.
- type: verify_tracing
chains:
- ethereum
- polygon
min_events: 1 # Optional: Require at least 1 event emitted
min_gas_entries: 1 # Optional: Require at least 1 gas profile entry
min_storage_diffs: 0 # Optional: Require minimum storage slots changed
min_balance_diffs: 0 # Optional: Require minimum balance changes
check_consistency: true # Optional: Ensure gas entries exist for every event tx
10. bridge_action¶
Executes a protocol-specific action via the active bridge plugin configured in the topology. Supported actions include: send_message, relay_messages, check_delivery, and verify_state.
- type: bridge_action
action: send_message
source_chain: ethereum
dest_chain: polygon
data: "0x..."
correlation_id: "msg-001" # Optional: Tag for cross-chain correlation
For checking delivery:
- type: bridge_action
action: check_delivery
correlation_id: "msg-001"
source_tx_hash: "0x..." # Match against the source transaction hash
Experiment Orchestration¶
The experiment YAML definition binds the scenario, attack plugin, and topology.
# experiments/my_attack_replay.yaml
name: my_attack_replay
scenario: my_attack_pre_exploit
attack: my_attack
topology: single
run:
traces: true
storage_diffs: true
gas_profiling: true
tags: [my_attack, l2]
Execution Pipeline:
sequenceDiagram
participant CLI as crucible CLI
participant Config as testbed.yaml & evidence.yaml
participant Runner as ExperimentRunner
participant Anvil as Anvil Forks
participant Scenario as Scenario Phases
participant Attack as Attack Plugin
CLI->>Runner: Request experiment execution
Runner->>Config: Merge fork_blocks from evidence.yaml
Runner->>Anvil: Spawn forks at target block heights
Runner->>Scenario: Execute `setup` phase steps
Runner->>Runner: Initialize artifact capture (tracing)
Runner->>Attack: Invoke `execute()` method (Exploit runs)
Runner->>Attack: Invoke `verify()` method
Runner->>Scenario: Execute `verify` phase steps
Runner->>Runner: Finalize and hash artifacts (run.jsonl, etc.)
Runner->>CLI: Return execution report
Step-by-Step Flow:
1. The fork_blocks configuration is automatically merged from attacks/<name>/evidence.yaml.
2. Target chains are forked at the merged block heights.
3. Scenario setup phase steps are executed.
4. The instrumentation proxy initiates trace capture.
5. The attack plugin's execute() method is invoked.
6. The attack plugin's verify() method is invoked.
7. Scenario verify phase steps are executed.
8. Artifacts (events.jsonl, run.jsonl, etc.) are finalized and hashed.
Note: To bypass fork block auto-merging from evidence.yaml, use the --no-auto-merge CLI flag.
Troubleshooting¶
| Error Condition | Root Cause | Remediation |
|---|---|---|
Scenario not found |
Directory structure mismatch | Ensure scenarios/<name>/scenario.yaml exists |
Unknown step type |
Invalid step declaration | Refer to the Step Reference section |
python_script missing steps.py |
Missing Python extension file | Ensure steps.py exists alongside scenario.yaml |
Chain X not in topology |
Scenario requests an unconfigured chain | Update the scenario chains array or topology definition |
Fork block mismatch |
testbed.yaml out of sync |
Update attacks/<name>/evidence.yaml (auto-merged at runtime) |
See Also¶
| Reference | Purpose |
|---|---|
docs/ATTACK_PACK_GUIDE.md |
Attack plugin development guidelines |
docs/CLI_REFERENCE.md |
Command-line interface documentation |
docs/REPRODUCIBILITY.md |
Determinism and provenance architectures |