Module tweak

Module tweak 

Source
Expand description

Contract bytecode modification for debugging through creation transaction replay.

This module provides the CodeTweaker utility for modifying deployed contract bytecode by replaying their creation transactions with replacement init code. This enables debugging with instrumented or modified contracts without requiring redeployment to the network.

§Core Functionality

§Contract Bytecode Replacement

The CodeTweaker handles the complete process of:

  1. Creation Transaction Discovery: Finding the original deployment transaction
  2. Transaction Replay: Re-executing the creation with modified init code
  3. Bytecode Extraction: Capturing the resulting runtime bytecode
  4. State Update: Replacing the deployed bytecode in the debugging database

§Etherscan Integration

  • Creation Data Caching: Local caching of contract creation transaction data
  • API Key Management: Automatic API key rotation for rate limit handling
  • Chain Support: Multi-chain support through configurable Etherscan endpoints

§Workflow Integration

The code tweaking process is typically used in the debugging workflow to:

  1. Replace original contracts with instrumented versions for hook-based debugging
  2. Substitute contracts with modified versions for testing different scenarios
  3. Enable debugging of contracts that weren’t originally compiled with debug information

§Usage Example

let mut tweaker = CodeTweaker::new(&mut edb_context, rpc_url, etherscan_api_key);
tweaker.tweak(&contract_address, &original_artifact, &instrumented_artifact, false).await?;

This replaces the deployed bytecode at contract_address with the instrumented version, enabling advanced debugging features on the modified contract.

Structs§

CodeTweaker
Utility for modifying deployed contract bytecode through creation transaction replay.