Skip to content

Simple Operations & Ad-Hoc Testing

Purpose: Crucible isn't just for automated exploit reproduction. It's also a managed Anvil orchestrator for day-to-day development, manual testing, contract debugging, and chain exploration. This guide covers granular operational procedures.


Quick Start: Fork & Use in 30 Seconds

# 1. Fork a chain
crucible fork --topology single

# 2. See what's running
crucible status

# 3. Fund an address and start transacting
cast rpc anvil_setBalance 0xYourAddress \
  $(cast to-wei 1000 ether) \
  --rpc-url http://127.0.0.1:8545

cast send 0xTargetContract "transfer(address,uint256)" \
  0xRecipient $(cast to-wei 10 ether) \
  --unlocked --from 0xYourAddress \
  --rpc-url http://127.0.0.1:8545

# 4. Clean up when done
crucible clean

1. Forking Chains

Basic Fork

# Fork a single Ethereum chain (port 8545)
crucible fork --topology single

# Fork multiple chains (Ethereum on 8545, Polygon on 8546)
crucible fork --topology dual

# Fork with a longer timeout for cold-cache chains (e.g., Polygon)
crucible fork --topology dual --fork-timeout 600

Following instantiation, Anvil executes on localhost. Any compatible tool may interact with this endpoint: - cast, forge (Foundry) - curl (raw JSON-RPC) - web3.py, ethers.js, viem - Crucible's own JsonRpcClient

With Baseline Setup

# Full setup: fork + bootstrap + capture golden baseline
crucible setup --topology single

# Now the environment may be reset to this state at any time
crucible reset --scenario my_scenario --mode soft

Blank Fork (No Archive RPC Needed)

For testing contracts without forking from a historical block, set fork_block to null in your topology:

# testbed.local.yaml
chains:
  ethereum:
    fork_block: null   # blank fork — starts from genesis
    port: 8545

Then fork normally:

crucible fork --topology single   # clean Anvil, no remote dependency

2. Checking What's Running

# Show all running Anvil processes
crucible status

Output example:

┌──────────┬──────┬──────┬───────┬────────┬───────────┬──────────┬─────────────────────────┐
│ Name     │ PID  │ Port │ Block │ Status │ Gas Price │ Base Fee │ RPC                     │
├──────────┼──────┼──────┼───────┼────────┼───────────┼──────────┼─────────────────────────┤
│ ethereum │ 1234 │ 8545 │ 12996693 │ ALIVE │ 0         │ 1gwei    │ http://127.0.0.1:8545   │
│ polygon  │ 1235 │ 8546 │ 16332982 │ ALIVE │ 0         │ 1gwei    │ http://127.0.0.1:8546   │
└──────────┴──────┴──────┴───────┴────────┴───────────┴──────────┴─────────────────────────┘

Also see disk usage:

crucible status --disk

3. Managing State (Snapshots & Baselines)

Named Snapshots

Snapshots save the full EVM state (all contracts, storage, balances) of a running chain.

# Create a snapshot
crucible snapshot create my_state

# Restore a snapshot (instant — loads saved state back into memory)
crucible snapshot restore my_state --chain ethereum

# Snapshot specific chains in multi-chain topologies
crucible snapshot create phase1 --chain ethereum
crucible snapshot create phase1 --chain polygon

Snapshots are stored in states/snapshots/ as JSON files.

Three-Tier Reset

Reset to a clean baseline state without re-forking:

Mode Speed What Happens
soft <5s anvil_loadState from baseline snapshot — no process restart
medium <30s Kill Anvil, relaunch, then restore snapshot
hard <5min Kill, re-fork from archive RPC, re-run bootstrap, restore snapshot
# Fastest — just reload state
crucible reset --scenario single --mode soft

# Full clean restart
crucible reset --scenario single --mode hard

Save and Restore Custom States

from crucible.rpc import JsonRpcClient

client = JsonRpcClient("http://127.0.0.1:8545")

# Save the entire EVM state
state = client.dump_state()  # returns huge dict
import json
with open("my_state.json", "w") as f:
    json.dump(state, f)

# Later: restore it
with open("my_state.json") as f:
    saved = json.load(f)
client.load_state(saved)

4. Working With Accounts

Account Model

Crucible starts Anvil with --accounts 0 --balance 0. This means no pre-funded test accounts are created. This is intentional — some archive nodes fail when Anvil tries to prefetch balance for the default Foundry accounts at historical blocks.

Fund Any Address

Given that --auto-impersonate is permanently enabled, any address may be utilized, provided it is sufficiently funded.

With cast:

# Fund with 1000 ETH
cast rpc anvil_setBalance \
  0xYourWalletAddress \
  $(cast to-wei 1000 ether) \
  --rpc-url http://127.0.0.1:8545

# Fund with 10000 ETH (for contract deployment)
cast rpc anvil_setBalance \
  0xDeployerAddress \
  $(cast to-wei 10000 ether) \
  --rpc-url http://127.0.0.1:8545

With Python:

from crucible.rpc import JsonRpcClient

client = JsonRpcClient("http://127.0.0.1:8545")
client.set_balance("0xYourWalletAddress", hex(1000 * 10**18))

With curl:

curl -s http://127.0.0.1:8545 -H 'Content-Type: application/json' \
  -d '{
    "jsonrpc":"2.0","id":1,
    "method":"anvil_setBalance",
    "params":["0xYourWalletAddress", "0x3635C9ADC5DEA00000"]
  }'

💡 Tip: Create a shell script fund.sh that funds your test accounts:

#!/bin/bash
RPC="http://127.0.0.1:8545"
ETH1000=$(cast to-wei 1000 ether)
for addr in "$@"; do
  cast rpc anvil_setBalance "$addr" "$ETH1000" --rpc-url "$RPC"
done
Usage: ./fund.sh 0xAlice 0xBob 0xCharlie

Check Balances

cast balance 0xYourWalletAddress --rpc-url http://127.0.0.1:8545
cast balance 0xTargetContract --rpc-url http://127.0.0.1:8545

Use Auto-Impersonation (No Private Keys Needed)

The --auto-impersonate flag permits transaction dispatch from any address without cryptographic signatures:

# Send from a contract owner address (no private key needed!)
cast send 0xVulnerableContract "approve(address,uint256)" \
  0xSpender 1000000 \
  --unlocked --from 0xOwnerAddress \
  --rpc-url http://127.0.0.1:8545

The --unlocked flag tells Anvil to skip signature verification because the sender is impersonated.

Stop Impersonating

cast rpc anvil_stopImpersonatingAccount 0xOwnerAddress \
  --rpc-url http://127.0.0.1:8545

5. Sending Transactions

With cast send

# Simple ETH transfer
cast send 0xRecipient \
  --value $(cast to-wei 1 ether) \
  --unlocked --from 0xYourAddress \
  --rpc-url http://127.0.0.1:8545

# Contract call
cast send 0xTokenContract \
  "transfer(address,uint256)" \
  0xRecipient $(cast to-wei 100 ether) \
  --unlocked --from 0xTokenOwner \
  --rpc-url http://127.0.0.1:8545

# With custom gas
cast send 0xContract "exploit()" \
  --gas-limit 500000 \
  --unlocked --from 0xAttacker \
  --rpc-url http://127.0.0.1:8545

With Python (Crucible's built-in client)

from crucible.rpc import JsonRpcClient
from web3 import Web3

client = JsonRpcClient("http://127.0.0.1:8545")

# Fund the sender first
client.set_balance("0xSender", hex(10 * 10**18))

# Impersonate and send
client.impersonate_account("0xSender")
tx_hash = client.send_transaction({
    "from": "0xSender",
    "to": "0xRecipient",
    "value": hex(10**18),  # 1 ETH
    "gas": hex(21000),
    "gasPrice": hex(0),
})
print(f"Tx hash: {tx_hash}")

With forge script

forge script DeployMyContract \
  --rpc-url http://127.0.0.1:8545 \
  --unlocked --broadcast

⚠️ Note: When using forge script against a Crucible fork, the deployer address (default: 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266) needs to be funded first with anvil_setBalance since Crucible uses --accounts 0.


6. Calling Contracts (Read-Only)

With cast call

# Query any contract state
cast call 0xTokenContract "totalSupply()" \
  --rpc-url http://127.0.0.1:8545

cast call 0xTokenContract "balanceOf(address)" \
  0xSomeAddress --rpc-url http://127.0.0.1:8545

# With block specification
cast call 0xContract "owner()" \
  --block 12996693 --rpc-url http://127.0.0.1:8545

With Python

from crucible.rpc import JsonRpcClient

client = JsonRpcClient("http://127.0.0.1:8545")

# Raw eth_call
result = client.call("eth_call", [{
    "to": "0xTokenContract",
    "data": "0x18160ddd",  # totalSupply() selector
}, "latest"])

# Higher-level helpers
balance = client.get_balance("0xSomeAddress")  # returns int (wei)
code = client.get_code("0xContract")           # returns hex bytecode
storage = client.get_storage_at("0xContract", "0x0")  # slot 0

7. Manipulating Chain State

Set Storage Slots

# Directly write to a contract's storage
cast rpc anvil_setStorageAt \
  0xContractAddress \
  0xStorageSlotHex \
  0xNewValueHex \
  --rpc-url http://127.0.0.1:8545

Python:

client.set_storage_at("0xContract", "0x0", "0xNewValue")

Set Code

Replace a contract's bytecode at runtime (useful for testing upgrade patterns):

cast rpc anvil_setCode \
  0xContractAddress \
  0xNewBytecode \
  --rpc-url http://127.0.0.1:8545
client.call("anvil_setCode", ["0xContractAddress", "0xNewBytecode"])

Set Nonce

cast rpc anvil_setNonce \
  0xSomeAddress \
  0x10 \
  --rpc-url http://127.0.0.1:8545

Advance Time

# Jump forward 1 day
cast rpc evm_increaseTime 86400 --rpc-url http://127.0.0.1:8545
cast rpc evm_mine --rpc-url http://127.0.0.1:8545

# Or use Crucible's helper
python -c "
from crucible.rpc import JsonRpcClient
c = JsonRpcClient('http://127.0.0.1:8545')
c.advance_time(86400)  # advances time + mines a block
"

Mine Blocks

# Mine a single block
cast rpc evm_mine --rpc-url http://127.0.0.1:8545

# Mine with specific timestamp
cast rpc evm_mine $(date +%s) --rpc-url http://127.0.0.1:8545

# Mine N blocks
for i in {1..10}; do cast rpc evm_mine --rpc-url http://127.0.0.1:8545; done

8. Contract Deployment

Using forge create

# Fund the deployer first
cast rpc anvil_setBalance \
  0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
  $(cast to-wei 100 ether) \
  --rpc-url http://127.0.0.1:8545

# Deploy
forge create src/MyContract.sol:MyContract \
  --constructor-args arg1 arg2 \
  --unlocked --from 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
  --rpc-url http://127.0.0.1:8545

Using forge script

# 1. Fund the default deployer
cast rpc anvil_setBalance \
  0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
  $(cast to-wei 100 ether) \
  --rpc-url http://127.0.0.1:8545

# 2. Deploy with forge script
forge script script/Deploy.s.sol:DeployScript \
  --rpc-url http://127.0.0.1:8545 \
  --unlocked --broadcast --slow

Using Python (Crucible SDK)

from crucible.rpc import JsonRpcClient

client = JsonRpcClient("http://127.0.0.1:8545")
client.set_balance("0xDeployer", hex(100 * 10**18))
client.impersonate_account("0xDeployer")

# Deploy by sending to null address with init code
tx_hash = client.send_transaction({
    "from": "0xDeployer",
    "data": "0x" + bytecode_hex,  # contract init code
    "gas": hex(2000000),
    "gasPrice": hex(0),
})

9. Working With Artifacts (Free Instrumentation)

Even during ad-hoc manual testing, Crucible's instrumentation proxy captures everything automatically if you use crucible setup instead of crucible fork:

crucible setup --topology single   # fork + bootstrap + instrumentation

Now every transaction — whether sent via cast, curl, Python, or forge script — produces artifact streams:

# See captured events
cat logs/setup/bootstrap/events.jsonl | head -5

# See gas used per transaction
cat logs/setup/bootstrap/gas_profile.jsonl

# See storage changes
cat logs/setup/bootstrap/storage_diffs.jsonl

# See balance changes
cat logs/setup/bootstrap/balance_diffs.jsonl

Each JSONL line is structured and queryable:

# Find all Transfer events
grep '"event_name":"Transfer"' logs/setup/bootstrap/events.jsonl

# Find storage changes for a specific contract
grep "0xTargetContract" logs/setup/bootstrap/storage_diffs.jsonl

To use the proxy URL instead of the raw Anvil URL — the proxy port is dynamically assigned and printed in the setup output:

# After crucible setup, the proxy URL is shown in the CLI output.
# Example output: "started instrumented proxy for ethereum on http://127.0.0.1:34567"
# Use that URL for all your cast calls to get automatic artifact capture:
cast call 0xContract "owner()" --rpc-url http://127.0.0.1:34567

Note: The proxy URL changes on every crucible setup since the OS assigns an available port. Always get the current URL from the setup output or crucible status. To find the proxy URL programmatically, check the chain's meta file in states/*.meta.json for the proxied rpc_url field.


10. Advanced Operations

Cross-Chain Testing (Dual Fork)

# Fork Ethereum + Polygon simultaneously
crucible fork --topology dual

# Ethereum on :8545, Polygon on :8546
cast block-number --rpc-url http://127.0.0.1:8545
cast block-number --rpc-url http://127.0.0.1:8546

# Fund addresses on both chains
cast rpc anvil_setBalance 0xAddr $(cast to-wei 100 ether) \
  --rpc-url http://127.0.0.1:8545
cast rpc anvil_setBalance 0xAddr $(cast to-wei 100 ether) \
  --rpc-url http://127.0.0.1:8546

Interactive Jupyter Analysis

# Launch Jupyter with Crucible analysis helpers
crucible notebook

# In a notebook cell:
from crucible.analysis import load_run, list_runs
runs = list_runs()                     # all experiment runs
events = load_run(runs[0], "events")   # load events as DataFrame

Record and Replay RPC Fixtures

Record all RPC traffic during a session for later replay:

# Run with record mode
crucible experiment run experiments/attack.yaml \
  --record tests/fixtures/my_session.jsonl

Then replay in CI without needing a live archive node:

from crucible.recording import ReplayServer
server = ReplayServer("tests/fixtures/my_session.jsonl")
server.start()
# Now ethereum RPC is served from the fixture, not a real node

11. Cleaning Up

For the full list of clean commands — crucible clean, --all, --cache, --logs, --states, --checkpoints, --datasets, and --logs-older-than — see the Quick Reference.

Fresh Start

To completely reset the workspace (stop chains, remove all artifacts, cache, and logs):

crucible clean --all --logs --datasets --confirm
crucible init  # recreate runtime directories

12. Common Workflows

Workflow: Contract Development & Debugging

Topology Mismatch — Running Bridge Experiments on Single Topology

Problem: You run a bridge experiment (e.g., experiments/nomad_replay.yaml which declares topology: bridge) but forked with --topology single. The experiment runs and produces artifacts, but the fidelity check fails with:

Runtime Fidelity: FAILED
Fidelity level L2 requires complete trace artifacts, but 1 transaction(s) failed auto-instrumentation.

Cause: Experiment YAML files declare a topology field that tells Crucible which chain setup they expect. When you fork with --topology single but the experiment expects bridge, Crucible's instrumentation proxy expects trace artifacts from a multi-chain setup. On a single chain, the bridge-specific instrumentation steps can't complete, causing the fidelity check to fail.

Fix: Match the fork topology to what the experiment expects:

# Check what topology the experiment needs first:
head -10 experiments/nomad_replay.yaml
# Look for: topology: bridge

# Fork with the correct topology:
crucible fork --topology bridge
crucible experiment run experiments/nomad_replay.yaml --no-baseline

Common experiment topologies:

Experiment Expected Topology Notes
nomad_replay.yaml bridge Needs Ethereum + Polygon fork
wormhole_replay.yaml bridge Needs Ethereum + Polygon fork
poly_network_replay.yaml bridge Needs Ethereum + Polygon + BSC
demo_experiment.yaml single Ethereum only — works with single topology
horizon_replay.yaml single Ethereum only
bnb_token_hub_replay.yaml single_bsc BSC only

In the absence of multi-chain RPC endpoints, attack logic may still be validated by utilizing --no-fidelity:

crucible fork --topology single
crucible experiment run experiments/nomad_replay.yaml --no-baseline --no-fidelity

This skips the fidelity check. The attack plugin still executes and produces results. Important: Runs with --no-fidelity bypass the publication gates — exported bundles will not pass L2 verification. Use this for development only; publications require actual multi-chain trace artifacts.

# 1. Fork a clean chain
crucible fork --topology single

# 2. Fund the default Forge deployer
cast rpc anvil_setBalance \
  0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
  $(cast to-wei 10000 ether) \
  --rpc-url http://127.0.0.1:8545

# 3. Deploy and test iteratively
forge script Deploy --rpc-url http://127.0.0.1:8545 --unlocked --broadcast
forge test --fork-url http://127.0.0.1:8545 --match-test testFeature

# 4. Quick state check
cast call 0xDeployed "balanceOf(address)" 0xAddr --rpc-url http://127.0.0.1:8545
cast rpc anvil_setStorageAt 0xDeployed 0xSlot 0xValue --rpc-url http://127.0.0.1:8545

# 5. Snapshot before risky experiments
crucible snapshot create before_hack

# 6. If something breaks — restore instantly
crucible snapshot restore before_hack --chain ethereum

Workflow: Historical State Exploration

# 1. Fork at a specific block
crucible fork --topology single

# 2. Check what state looked like at that block
cast balance 0xOldContract --rpc-url http://127.0.0.1:8545
cast call 0xOldContract "owner()" --rpc-url http://127.0.0.1:8545

# 3. Try to exploit a known vulnerability
cast send 0xOldContract "vulnerableFunction(bytes)" \
  $(cast calldata "exploit()") \
  --unlocked --from 0xAttacker \
  --rpc-url http://127.0.0.1:8545

# 4. Did it work? Check storage
cast storage 0xOldContract 0xKeySlot --rpc-url http://127.0.0.1:8545

# 5. Reset and try a different approach
crucible reset --scenario single --mode soft

Workflow: Gas Optimization Testing

# 1. Fork and setup instrumentation
crucible setup --topology single

# 2. Fund deployer
cast rpc anvil_setBalance 0xDeployer $(cast to-wei 100 ether) \
  --rpc-url http://127.0.0.1:8545

# 3. Deploy optimized contract
forge create --rpc-url http://127.0.0.1:<proxy-port> \  # use proxy URL from crucible setup output
  --unlocked --from 0xDeployer \
  src/Optimized.sol:Optimized

# 4. Check gas profile
grep "Deploy" logs/setup/bootstrap/gas_profile.jsonl

# 5. Snapshot, deploy old version, compare
crucible snapshot create optimized
# ... deploy old version ...
grep "Deploy" logs/setup/bootstrap/gas_profile.jsonl
crucible snapshot restore optimized --chain ethereum

13. Troubleshooting Common Issues

Address Has No Balance

Problem: cast send fails with "insufficient funds" or "sender doesn't have enough funds".

Fix: Fund the address before using it:

cast rpc anvil_setBalance 0xYourAddress $(cast to-wei 100 ether) \
  --rpc-url http://127.0.0.1:8545

"No matching key" When Using --unlocked

Problem: cast send --unlocked fails because the account isn't impersonated.

Fix: --auto-impersonate is enabled by default in Crucible, but cast may need the --from flag explicitly:

cast send 0xContract "method()" \
  --unlocked --from 0xYourAddress \
  --rpc-url http://127.0.0.1:8545

Forge Script Default Deployer Not Working

Problem: forge script fails with "insufficient funds" for the default deployer.

Fix: The default Foundry deployer (0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266) is not pre-funded in Crucible (because of --accounts 0). Fund it:

cast rpc anvil_setBalance \
  0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
  $(cast to-wei 10000 ether) \
  --rpc-url http://127.0.0.1:8545

Port Already in Use

Problem: Can't fork because port 8545 is taken.

Fix: Check what's running and clean up:

crucible clean   # stop all Crucible-managed chains
# Or manually: kill the old Anvil process
lsof -i :8545
kill <pid>

Cold-Cache Fork Too Slow

Problem: Forking Polygon takes 3-5 minutes.

Fix: Increase timeout or use a faster archive RPC:

crucible fork --topology dual --fork-timeout 600

The second fork will use the cache and be much faster (<30s).


14. All Available Anvil Cheatcodes

These are all forwarded through Crucible's instrumentation proxy:

Method Purpose Example
anvil_setBalance Set ETH balance cast rpc anvil_setBalance 0xAddr 0xAmount
anvil_impersonateAccount Impersonate any address anvil_impersonateAccount(addr) (auto-enabled)
anvil_stopImpersonatingAccount Stop impersonating anvil_stopImpersonatingAccount(addr)
anvil_setCode Replace contract bytecode anvil_setCode(addr, bytecode)
anvil_setStorageAt Write storage slot anvil_setStorageAt(addr, slot, value)
anvil_setNonce Set account nonce anvil_setNonce(addr, nonce)
anvil_mine Mine blocks anvil_mine(blocks)
anvil_setCoinbase Set coinbase address anvil_setCoinbase(addr)
anvil_setChainId Set chain ID anvil_setChainId(id)
anvil_dumpState Export full EVM state dump_state() → JSON
anvil_loadState Import full EVM state load_state(json)
evm_increaseTime Jump forward increaseTime(seconds)
evm_setNextBlockTimestamp Set next block time setNextBlockTimestamp(timestamp)
evm_snapshot Create snapshot ID snapshot() → id
evm_revert Revert to snapshot revert(id)

All of these work through:

# cast (direct to Anvil port — all methods work)
cast rpc <method> <params> --rpc-url http://127.0.0.1:8545

# Python (direct to Anvil port — all methods work)
client.call("<method>", [params])

# curl (direct to Anvil port — all methods work)
curl -s http://127.0.0.1:8545 -d '{"method":"<method>","params":[...]}'

Proxy vs Direct: When using the instrumentation proxy URL, only a subset of Anvil methods are forwarded (see the proxy allowlist in Instrumentation Architecture). For unrestricted access to all cheatcodes, connect to the raw Anvil port directly (http://127.0.0.1:8545).


15. RPC Endpoints Reference

Chain Default Port RPC URL Notes
Ethereum 8545 http://127.0.0.1:8545 Default for --topology single
Polygon 8546 http://127.0.0.1:8546 For --topology dual
BSC 8547 http://127.0.0.1:8547 For custom topologies
Harmony 8548 http://127.0.0.1:8548 For custom topologies
Proxy (Ethereum) Dynamic http://127.0.0.1:<dynamic> OS-assigned, printed by crucible setup

See Also

Doc What It Covers
Technical Overview System architecture, core concepts, design principles
User Guide Full setup, Docker vs local, environment config
CLI Reference All CLI commands and flags
Plugin Development Guide Writing attack, bridge, and agent plugins
Troubleshooting Guide Common errors and fixes
Fidelity Guide Fidelity levels and enforcement