- 设置与预检:启动环境、为钱包注资、在签名之前检查交易。
- 调试与事后分析:弄清一笔交易为何失败、资金去哪儿了,或者一笔 swap 为何返回低于预期的金额。高级追踪导航工具在此处尤为出色。
- Virtual Environment 工作流:冒充、多步骤测试、快照、时间旅行、代币余额覆盖。
- 优化与检查:gas 拆解、合约元数据。
创建 Virtual Environment 并为钱包注资
如何提问:“Create a Virtual Environment forked from Ethereum mainnet and fund my wallet 0xd8da6bf26964af9d7eed9e03e53415d37aa96045 with 100 ETH.”Claude 会做什么:
- 调用
list_projects查找您的项目,然后调用set_active_project选择一个。 - 调用
get_networks找到 Ethereum Mainnet 的网络 ID。 - 使用网络 ID 调用
create_vnet,创建一个 fork 的环境。新的 Virtual Environment 自动设为激活。 - 使用您的钱包地址调用
fund_account,将余额设置为 100 ETH(十六进制 wei)。自动在激活的 Virtual Environment 上运行。 - 返回 Virtual Environment 的详情,包括 Admin RPC 和 Public RPC URL,可在 Hardhat、Foundry 或任何 Web3 库中使用。
模拟一笔 Uniswap swap
如何提问:“Simulate a swap of 1 ETH for USDC on Uniswap V3 from 0xd8da6bf26964af9d7eed9e03e53415d37aa96045 on Ethereum mainnet. Show me the expected output and any token transfers.”Claude 会做什么:
- 调用
simulate_transaction,传入 Uniswap V3 router 地址、您的发送者地址、swap calldata 和 1 ETH 作为 value。 - 模拟针对当前 Mainnet 状态运行,返回:成功/回滚状态、gas 消耗和解码后的方法名。
- 调用
get_simulation_asset_transfers展示所有代币变动,包括流入的 ETH 和流出的 USDC。 - 调用
get_simulation_balance_changes展示对您余额的净影响,附带美元价值。
在发送前对交易进行预检
如何提问:
“I’m about to call approve on 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 to give 0xE592427A0AEce92De3Edee1F18E0157C05861564 unlimited USDC allowance. Simulate it first and show me exactly what approvals and state changes it will create.”
Claude 会做什么:
- 调用
simulate_transaction,以您的钱包作为发送者、代币合约作为接收者,并传入approvecalldata。 - 调用
get_simulation_exposure_changes展示每笔授权和额度变更——哪个 spender 得到了什么权限,以及多少。 - 调用
get_simulation_state_changes展示被修改的具体存储槽。
调试一笔失败的链上交易
如何提问:“Why did transaction 0x6c5df5a1e6b34e2432ae19706e38a84239495cdbf40c2a9d4d79806443c4aa0d revert on Ethereum?”Claude 会做什么:
- 使用交易哈希调用
trace_transaction。返回状态(false= 回滚)、gas 消耗、解码后的方法名和错误消息。 - 调用
get_simulation_call_trace获取完整的内部调用树——每次函数调用,包含解码后的名称、输入、输出,以及具体是哪个调用失败。 - 调用
get_simulation_events查看 revert 点之前发出的事件。 - 可选调用
get_simulation_state_changes查看直到失败为止被修改的状态。
"ERC20: transfer amount exceeds balance"),以及完整的调用追踪,让您能看到通往失败的执行路径。
在深度嵌套的交易中找出 revert 的根本原因
如何提问:“Transaction 0x… reverted on Ethereum. It’s a complex DeFi call with lots of internal calls, find the actual error and show me the path that led to it.”Claude 会做什么:
- 调用
trace_transaction获取顶层摘要并确认 revert。 - 调用
find_failures列出交易中每个失败的调用,而不仅仅是最外层。这会同时暴露原始 revert 以及任何包装的require或 try-catch 失败。 - 调用
get_error_path返回从根调用到最深失败调用的追责链条,每一层都包含解码后的输入和输出。 - 如果仍有节点存在被截断的子节点,则对特定位置调用
get_call_trace_node以展开。
get_simulation_call_trace 输出快得多。
导航一个非常大的追踪
如何提问:
“This transaction has hundreds of internal calls and get_simulation_call_trace is truncated. Help me understand its structure and drill into the part that matters.”
Claude 会做什么:
- 调用
get_trace_stats报告总调用数、最大深度、错误数和唯一合约数——快速的大小检查,决定策略。 - 调用
get_trace_skeleton获取压缩的调用树:每个节点的函数名、合约、深度和错误标志,不含解码参数。 - 使用 skeleton 中的
absolute_position值识别有意思的子树(一个失败分支、一个特定协议或一个可疑合约)。 - 调用
get_call_trace_node展开该子树,附带完整解码的输入和输出。 - 可选调用
get_subtree_events和get_subtree_state_changes仅查看该子树的事件和存储差异。
在追踪中搜索特定合约或函数
如何提问:
“Did this transaction ever call transferFrom on USDC? If so, show me every call with the decoded args.”
Claude 会做什么:
- 调用
search_call_trace,以 USDC 地址和transferFrom作为过滤条件,仅返回匹配的调用,包括解码后的输入、输出和绝对位置。 - 对于任何有意思的匹配,调用
get_call_trace_node获取其周围完整的嵌套上下文。
追踪一笔交易中的资金流向
如何提问:“For transaction 0x… on Ethereum, show me who sent what to whom, in order, with USD values.”Claude 会做什么:
- 使用交易哈希调用
get_transaction_fund_flow。返回按顺序排列的代币和原生转移,每一笔都有 from/to 地址和美元价值,以及每个地址的净流量。 - 可选对任何不熟悉的地址调用
get_contract_info以识别其身份(协议 router、pool、treasury 等)。
调试失败的 Safe 多签批处理执行
如何提问:“Our Safe batch execution at 0x… reverted on Ethereum. The batch has 12 calls. Which one actually failed and why?”Claude 会做什么:
- 调用
trace_transaction确认 revert 并获得顶层方法(execTransaction或multiSend)。 - 调用
get_trace_stats——Safe 批处理很快会展开成大型追踪,因此统计信息决定下一步。 - 调用
find_failures——因为multiSend在任何子调用失败时通常会 revert 整个批处理,这是查看 12 个操作中具体哪个爆掉的最快方式,而不仅仅是外层 Safe 的 revert。 - 对失败的子调用调用
get_error_path,获得每一层完整解码的输入/输出链条。 - 如果任何相关节点被截断,可选调用
get_call_trace_node。
对漏洞攻击或可疑交易进行事后分析
如何提问:“0x… on Ethereum drained funds from our protocol. Walk me through what happened: who ended up with the money, what the attacker called, and where the exploit entered our contracts.”Claude 会做什么:
- 首先调用
get_transaction_fund_flow——按顺序排列的代币与原生资金流以及每个地址的净流量会立刻暴露攻击者的钱包和被抽干的协议地址。 - 调用
get_trace_skeleton绘制攻击者的调用结构图,而无需加载每个参数。 - 调用
search_call_trace搜索对协议合约的调用(按地址)以隔离入口点。 - 对入口点调用
get_call_trace_node获取解码参数,然后调用get_subtree_state_changes查看该攻击改变了哪些状态。 - 对攻击者交互过的任何未知合约(helper、代理、已知的漏洞合约)调用
get_contract_info。
调查一次意外的清算
如何提问:“My Aave position got liquidated in 0x…, figure out why. I want to know the oracle price at liquidation time and the exact health-factor path.”Claude 会做什么:
- 调用
trace_transaction和get_trace_skeleton绘制清算调用树。 - 调用
search_call_trace搜索预言机调用(例如latestAnswer、getAssetPrice)以找到清算使用的价格读取。 - 对每个匹配调用
get_call_trace_node获取解码后的返回值——用于健康因子计算的确切价格。 - 调用
get_transaction_fund_flow展示扣押了多少抵押品、偿还的债务,以及清算人的奖励。 - 可选对清算子树调用
get_subtree_events按顺序查看LiquidationCall和Transfer事件。
审计一笔 1inch/聚合器 swap 收益低于预期的问题
如何提问:“0x… was a 1inch swap where I got significantly less USDC than the quote. Which pool or hop gave the bad price?”Claude 会做什么:
- 调用
get_trace_stats——聚合器路径可能很深,涉及许多 pool hop。 - 调用
get_trace_skeleton按顺序查看 pool 调用序列。 - 调用
search_call_trace搜索swap、exactInput或 router 的 pool 交互 selector,把每一跳都拉出来。 - 对每一跳调用
get_call_trace_node获取解码后的amountIn/amountOut值。 - 调用
get_transaction_fund_flow确认最终净收到的金额和任何意外的转账(手续费、返利)。
使用修复方案重新模拟一笔失败交易
如何提问:“Transaction 0x… failed with ‘ERC20: transfer amount exceeds balance’. Re-simulate it but override my USDC balance to 10,000 USDC to confirm that’s the only issue.”Claude 会做什么:
- 使用原交易哈希调用
resimulate_transaction,并附加一个将您的代币余额设置为 10,000 USDC 的状态覆盖。 - 如果模拟成功,确认根本原因是余额不足。
- 调用
get_simulation_call_trace验证执行路径现在能无错误完成。 - 可选调用
get_simulation_asset_transfers展示如果成功交易会做什么。
理解一笔交易做了什么
如何提问:“Walk me through everything that happened in transaction 0x… on Ethereum, every internal call, who called who, and what changed.”Claude 会做什么:
- 调用
trace_transaction获取顶层摘要:方法名、发送者、接收者、gas 消耗和状态。 - 调用
get_simulation_call_trace获取完整的内部调用树——每次嵌套调用及其解码后的函数名、输入、输出和每次调用的 gas。 - 调用
get_simulation_events按顺序列出所有发出的事件。 - 调用
get_simulation_state_changes展示每个变化的存储槽和余额。
检查一个智能合约
如何提问:“What contract is deployed at 0xdAC17F958D2ee523a2206206994597C13D831ec7 on Ethereum?”Claude 会做什么:
- 使用该地址和 Ethereum 的网络 ID 调用
get_contract_info。
在 Virtual Environment 上发送冒充交易并进行追踪
如何提问:
“On my Virtual Environment, send a transaction from the Uniswap V2 deployer 0x1a9C8182C09F50C8318d769245beA52c32BE35BC to the USDC contract 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 calling the transfer function to send 1000 USDC to my wallet. Then trace the execution.”
Claude 会做什么:
- 在激活的 Virtual Environment 上调用
send_vnet_transaction,以部署者作为from、USDC 作为to,并传入 ABI 编码的transfercalldata。发送者被冒充——无需私钥。 - 调用
get_vnet_transactions获取已执行交易的operation_id。 - 调用
trace_vnet_transaction获取解码后的执行摘要——合约名、函数名、解码后的输入参数和输出。 - 可选调用
get_vnet_simulation_events和get_vnet_simulation_state_changes获取更深入的细节。
transfer 调用成功的解码追踪,以及发出的事件(以您的钱包为接收方的 Transfer 事件)。
在 Virtual Environment 上测试多步骤合约交互
如何提问:“On my Virtual Environment, run the full approval and swap flow: first approve the Uniswap router to spend 1000 USDC from my wallet, then execute the swap. Show me my balances before and after.”Claude 会做什么:
- 在激活的 Virtual Environment 上调用
send_vnet_transaction提交approve交易,冒充您的钱包——无需私钥。 - 再次调用
send_vnet_transaction传入 swap calldata。 - 对每笔交易调用
get_vnet_simulation_asset_changes展示每一步的代币变动。 - 在最后一步之后调用
get_vnet_simulation_balance_changes展示净余额影响。
分析 gas 使用以进行优化
如何提问:“Simulate this transaction and show me a gas breakdown so I can find the most expensive function calls: [paste calldata or describe the transaction]”Claude 会做什么:
- 使用您的交易参数调用
simulate_transaction。 - 调用
get_simulation_gas_breakdown获取每次调用的 gas 消耗,包括固有 gas 和退款。 - 调用
get_simulation_call_trace将 gas 成本映射到执行树中的特定函数调用。
使用
get_simulation_generated_access_list 生成 EIP-2930 access list,可通过预先声明交易将访问的存储槽和地址来降低 gas 成本。Fork Virtual Environment 用于并行测试
如何提问:“Fork my current Virtual Environment so I can test a different approach without losing the current state.”Claude 会做什么:
- 调用
list_vnets找到您当前的 Virtual Environment,如需要则调用set_active_vnet。 - 调用
fork_vnet创建一个保留所有状态(已部署合约、余额和交易历史)的新 Virtual Environment。fork 自动设为激活。 - 返回新的 Virtual Environment 详情,包含全新的 RPC URL。
快照、测试与回滚用于压力测试
如何提问:“On my Virtual Environment, snapshot the current state, then simulate a liquidation on Aave with different oracle prices. Revert to the snapshot between each attempt so I can compare outcomes.”Claude 会做什么:
- 调用
snapshot_vnet保存当前 Virtual Environment 状态,获得快照 ID。 - 调用
set_storage_at将预言机价格覆盖为特定值。 - 调用
send_vnet_transaction触发清算。 - 调用
get_vnet_simulation_balance_changes和get_vnet_simulation_asset_changes捕获结果。 - 调用
revert_vnet将 Virtual Environment 恢复到快照状态(快照被消耗)。 - 再次调用
snapshot_vnet用于下一次迭代,设置不同的预言机价格并重复。
为测试设置 ERC-20 余额
如何提问:“On my Virtual Environment, give my wallet 0xd8da6bf26964af9d7eed9e03e53415d37aa96045 a balance of 10,000 USDC and 5 WETH so I can test a swap.”Claude 会做什么:
- 调用
set_erc20_balance传入 USDC 代币地址、您的钱包和所需金额。 - 再次调用
set_erc20_balance传入 WETH 代币地址和金额。 - 可选通过
balanceOf调用使用vnet_call验证余额已正确设置。
set_erc20_balance 自动处理代币的存储布局。
时间旅行以测试 timelock 和 vesting
如何提问:“On my Virtual Environment, advance the clock by 7 days to test whether my timelock contract unlocks correctly.”Claude 会做什么:
- 调用
increase_time传入 604800 秒(7 天)以推进 Virtual Environment 的时钟。 - 调用
mine_block将时间变化提交到新区块。 - 调用
vnet_call读取 timelock 合约的状态(例如isUnlocked()或releaseTime())。 - 可选调用
send_vnet_transaction执行解锁并验证是否成功。