audit-infra
Infrastructure-first security audit — secrets, supply chain, CI/CD, LLM/skill security, OWASP, STRIDE. Complements /audit-solana (program-level)
Reproduce and debug a user-reported failing transaction against forked cluster state, mapping the failure back to source code
> /plugin marketplace add solanabr/solana-ai-kit > /plugin install solana-ai-kit@stbr
How it fires
How this command gets triggered: by you, by Claude, or both.
/debug-user-txContext preview
What this command does when you run it.
Reproduce and debug a user-reported failing transaction against forked cluster state, mapping the failure back to source code
description: "Reproduce and debug a user-reported failing transaction against forked cluster state, mapping the failure back to source code"
You are debugging a transaction that a user reports as failing. You have the project's source code locally; the goal is to reproduce the failure against forked cluster state, then map the on-chain error back to the exact line of Rust / IDL that produced it and suggest a fix.
Collect from the user (at least one of `signature` or `instruction` is required):
| Input | Required | Notes | |-------|----------|-------| | `signature` | preferred | On-chain tx signature. Fastest path — fetch + replay. | | `wallet` | optional | User's pubkey. Auto-extracted from tx if signature given. | | `instruction` | fallback | Raw ix JSON when the tx never landed (serialized tx / accounts + data). | | `cluster` | optional | `mainnet` / `devnet`. Default: infer from `Anchor.toml` or `.env`. | | `rpc` | optional | Override RPC endpoint. Default: cluster default or project `.env`. | | `program` | optional | Program ID. Auto-detected from workspace. |
If the user only pasted an error message, ask for the signature before proceeding — it's the difference between 30 seconds and guessing.
echo "Detecting project..."
FRAMEWORK="unknown"
if [ -f "Anchor.toml" ]; then
FRAMEWORK="anchor"
echo "Anchor project detected"
elif [ -f "Cargo.toml" ] && grep -q "pinocchio" Cargo.toml 2>/dev/null; then
FRAMEWORK="pinocchio"
echo "Pinocchio project detected"
elif [ -f "Cargo.toml" ] && grep -q "solana-program" Cargo.toml 2>/dev/null; then
FRAMEWORK="native"
echo "Native Solana program detected"
else
echo "No Solana program workspace detected. Debug will proceed RPC-only (no source mapping)."
fi
# Infer cluster
CLUSTER="${CLUSTER:-mainnet}"
if [ -f "Anchor.toml" ]; then
DETECTED=$(grep -m1 'cluster' Anchor.toml | sed 's/.*= *//' | tr -d '"')
[ -n "$DETECTED" ] && CLUSTER="$DETECTED"
fi
echo "Cluster: $CLUSTER"
# Collect program IDs + IDLs
ls target/idl/*.json 2>/dev/null || echo "No IDLs found at target/idl/ — run 'anchor build' for best results"If a signature was provided, fetch it with full detail. Use the project's RPC if configured; otherwise fall back to the cluster default.
SIG="<signature>"
RPC="${RPC:-https://api.$CLUSTER.solana.com}"
mkdir -p .claude/debug
OUT=".claude/debug/tx-${SIG:0:8}.json"
curl -s -X POST "$RPC" \
-H "Content-Type: application/json" \
-d "$(cat <<EOF
{
"jsonrpc":"2.0","id":1,"method":"getTransaction",
"params":["$SIG",{"encoding":"json","maxSupportedTransactionVersion":0,"commitment":"confirmed"}]
}
EOF
)" > "$OUT"
# Sanity check
jq -e '.result != null' "$OUT" >/dev/null || { echo "Tx not found or not yet confirmed"; exit 1; }Extract from the JSON (Claude: read `$OUT` with `jq` or the Read tool):
From `meta.err`, extract the instruction index. For `InstructionError: [N, ...]`, instruction `N` failed.
FAILING_IX=$(jq -r '.result.meta.err.InstructionError[0]' "$OUT") FAILING_PROGRAM=$(jq -r --argjson i "$FAILING_IX" \ '.result.transaction.message.accountKeys[.result.transaction.message.instructions[$i].programIdIndex]' \ "$OUT") echo "Failing instruction #$FAILING_IX → program $FAILING_PROGRAM"
> **Note**: Index 0 is almost always `ComputeBudget` (`setComputeUnitLimit` / `setComputeUnitPrice`). The real failure is usually index ≥ 1. Trust `meta.err.InstructionError[0]`, not position.
> **Address Table Lookups**: If `transaction.message.addressTableLookups` is non-empty, extend the account list before indexing: `accountKeys ++ meta.loadedAddresses.writable ++ meta.loadedAddresses.readonly`. Otherwise you'll resolve the wrong program for CPI-heavy txs.
Compare `$FAILING_PROGRAM` against the project's program IDs (from `declare_id!` or `Anchor.toml`). If it matches, source mapping is possible. If not (e.g. Jupiter, Token Program), the failure is inside a CPI target — note this and proceed with log-based diagnosis.
`instructions[N].data` is **base58-encoded** when fetched with `encoding: "json"` (what Step 2 uses). Decode before slicing.
For the project's own program:
Record the handler name.
**Fast path — scan `meta.logMessages`
Production-ready Claude Code configuration for full-stack Solana development. Combines best practices from multiple sources into an agent-optimized, token-efficient config you can install and adapt to your specific project.
Repo: solanabr/solana-ai-kit
Infrastructure-first security audit — secrets, supply chain, CI/CD, LLM/skill security, OWASP, STRIDE. Complements /audit-solana (program-level)
Benchmark CU usage and compare against baseline for regression detection