Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak #3

Open
wants to merge 146 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
4197856
feat:support forge clone
ZhangZhuoSJTU Mar 27, 2024
fc79b73
feat: update configuration based on metadate from EtherScan 👷
ZhangZhuoSJTU Mar 27, 2024
5aef84b
doc: update the documenation for
ZhangZhuoSJTU Mar 27, 2024
6a38f4a
add dump_sources function
Troublor Mar 27, 2024
cf1196b
fix: add existing remapping into remappings.txt
ZhangZhuoSJTU Mar 27, 2024
65f3678
apply remapping on libraries
Troublor Mar 27, 2024
f7988b7
add tests
Troublor Mar 27, 2024
bfa9697
feat: update remappings in config file
ZhangZhuoSJTU Mar 27, 2024
d3ef05f
add two more test cases
Troublor Mar 27, 2024
eaf8005
fix library remapping bug
Troublor Mar 27, 2024
b890f0a
test: add e2e test cases for forge clone
ZhangZhuoSJTU Mar 27, 2024
6f61ba7
Merge branch 'foundry-rs:master' into forge_clone
ZhangZhuoSJTU Mar 27, 2024
8432289
Merge pull request #1 from Troublor/forge_clone
ZhangZhuoSJTU Mar 27, 2024
c21f805
test: fix rate limit issue for forge clone tests
ZhangZhuoSJTU Mar 27, 2024
1fd2b18
Merge pull request #2 from Troublor/forge_clone
ZhangZhuoSJTU Mar 27, 2024
0fcd6d8
add tongs crate
Troublor Mar 28, 2024
10b8b98
fix missing dependency
Troublor Mar 28, 2024
fc9dd8f
rename to tweak
Troublor Mar 28, 2024
0c67265
feat: disable git by default for forge clone
ZhangZhuoSJTU Mar 28, 2024
58a2758
dump clone.toml metadata in cloned projects
Troublor Mar 28, 2024
d43e20c
Merge pull request #3 from EtherDebug/forge_clone
Troublor Mar 28, 2024
d39c166
Merge remote-tracking branch 'origin/master' into tweak
Troublor Mar 28, 2024
13a2a7d
skeleton of compatibility check
Troublor Mar 28, 2024
4fdb30d
add storage layout to the clone metadata
Troublor Mar 28, 2024
8d6374a
dump clone metadata in a hidden, readonly, compact json file
Troublor Mar 28, 2024
0f0ba58
Merge pull request #4 from EtherDebug/forge_clone
Troublor Mar 28, 2024
2d546f5
Merge remote-tracking branch 'origin/master' into tweak
Troublor Mar 28, 2024
4846c90
update clone metadata
Troublor Mar 28, 2024
9a6bf0f
fix: move project compilation and metadate collection into lib.rs
ZhangZhuoSJTU Mar 28, 2024
ca09563
fix compilation error
Troublor Mar 28, 2024
431a2d8
fix: fix compilation error
ZhangZhuoSJTU Mar 28, 2024
564ad45
add constructor arguments in clone metadata
Troublor Mar 28, 2024
bc2c8b4
Merge pull request #5 from EtherDebug/forge_clone
Troublor Mar 28, 2024
cec29f7
Merge remote-tracking branch 'origin/master' into tweak
Troublor Mar 28, 2024
baed172
add constructor arguments in the metadata
Troublor Mar 28, 2024
7537ad7
storage layout compatibility check
Troublor Mar 28, 2024
e63ce6d
update docstring
Troublor Mar 28, 2024
38751a0
abstract cloned project
Troublor Mar 29, 2024
b1290da
add TweakExecutor
Troublor Mar 29, 2024
61f5a42
add forge replay command
Troublor Mar 29, 2024
740b2cb
feat (WIP): support tweaking contract code
ZhangZhuoSJTU Mar 29, 2024
bd74ab9
perf: use `jemalloc` as the global allocator on unix (try 2) (#7448)
DaniPopes Mar 28, 2024
ea397e6
chore: remove misleading/unneeded FxIndexSet type (#7511)
grandizzy Mar 28, 2024
b1f1ee9
feat: `vm.sign` for scripts (#7454)
klkvr Mar 28, 2024
8af08b2
fix(anvil): clean up `eth_estimateGas` (#7515)
klkvr Mar 28, 2024
13a3495
fix: coverage for libraries (#7510)
klkvr Mar 29, 2024
4d5e738
chore: upgrade nix deps & migrate to stable (#7517)
rkrasiuk Mar 29, 2024
74c466b
Merge branch 'foundry-rs:master' into tweak
ZhangZhuoSJTU Mar 29, 2024
d91966c
feat (WIP): support tweaked code generation
ZhangZhuoSJTU Mar 29, 2024
4807c6e
feat (WIP): support tweating code and hook into the subject tx
ZhangZhuoSJTU Mar 29, 2024
7de1f43
chore: refactor tests for tweak::code
ZhangZhuoSJTU Mar 29, 2024
138c614
forge replay!
Troublor Mar 29, 2024
c5c4cd1
feat: support effective code tweaking
ZhangZhuoSJTU Mar 29, 2024
96cc2bd
fix: update the algo about how to get config
ZhangZhuoSJTU Mar 29, 2024
ecfa8f7
improve tests
Troublor Mar 29, 2024
7e13f72
chore: refactor tests for code tweaking
ZhangZhuoSJTU Mar 29, 2024
cb9c0fd
add more options to replay cmd
Troublor Mar 29, 2024
9877df0
fix: fix tests in code tweaking
ZhangZhuoSJTU Mar 29, 2024
ec41dda
chore: refactor
ZhangZhuoSJTU Mar 29, 2024
c62b6ab
fix: typo field name
Troublor Mar 30, 2024
1e150a3
Merge remote-tracking branch 'origin/master' into forge_clone
Troublor Mar 30, 2024
8fe27de
Merge pull request #6 from EtherDebug/forge_clone
Troublor Mar 30, 2024
25f7c35
fix: typo field name
Troublor Mar 30, 2024
49aad50
fix: cloned project didn't output storage layout
Troublor Mar 30, 2024
6406452
feat: fine-grained gas control
Troublor Mar 30, 2024
9eea140
print console logs
Troublor Mar 30, 2024
1e986fe
console logs for reverted transction
Troublor Mar 30, 2024
c14dde6
remove unnecessary executor
Troublor Mar 30, 2024
db3fb1b
tweak in cast run!
Troublor Mar 30, 2024
65781eb
fix: fix potential out-of-gas bugs when the creation code is signific…
ZhangZhuoSJTU Mar 30, 2024
4ed1e9f
chore: avoid modifying evm crate
ZhangZhuoSJTU Mar 30, 2024
a61690a
chore: use nightly fmt to be consistent with foundry-rs
ZhangZhuoSJTU Mar 30, 2024
861172f
chore: rewrite replay.rs:replay_tx_hash to reduce the number of its p…
ZhangZhuoSJTU Mar 30, 2024
24c26c1
chore: restore files in crate/anvil to be consistent with foundry-rs
ZhangZhuoSJTU Mar 30, 2024
fbc43a6
chore: restore files in crate/cheatcodes to be consistent with foundr…
ZhangZhuoSJTU Mar 30, 2024
8156f77
chore: restore files in crate/cli to be consistent with foundry-rs
ZhangZhuoSJTU Mar 30, 2024
cd557f1
chore: restore files in crate/config to be consistent with foundry-rs
ZhangZhuoSJTU Mar 30, 2024
2d48710
chore: restore files in crate/doc to be consistent with foundry-rs
ZhangZhuoSJTU Mar 30, 2024
7c010fd
chore: restore files in crate/fmt to be consistent with foundry-rs
ZhangZhuoSJTU Mar 30, 2024
c9624ef
chore: restore files in crate/script, crate/wallets, and crate/chisel…
ZhangZhuoSJTU Mar 30, 2024
ca57742
chore: restore files in crate/common and crate/evm to be consistent w…
ZhangZhuoSJTU Mar 30, 2024
7fe2121
chore: restore files in crate/macros, crate/test-utils, and crate/ver…
ZhangZhuoSJTU Mar 30, 2024
4243d55
chore: restore files in crates/cast to be consistent with foundry-rs
ZhangZhuoSJTU Mar 30, 2024
77e7a25
chore: restore files in crates/forge to be consistent with foundry-rs
ZhangZhuoSJTU Mar 30, 2024
8877ef0
chore: restore files in crates/forge/tests to be consistent with foun…
ZhangZhuoSJTU Mar 30, 2024
c6ae6f9
feat (WIP): finish tweak support for forge debug and script, but do n…
ZhangZhuoSJTU Mar 30, 2024
bbef533
improve cloned project compilation by caching
Troublor Mar 30, 2024
9dae84b
fix: when using forge script w/ tweat, we first use script_config's r…
ZhangZhuoSJTU Mar 31, 2024
184acc6
fix: bug in remapping
Troublor Mar 31, 2024
4ff474b
Merge pull request #7 from EtherDebug/forge_clone
Troublor Mar 31, 2024
a068631
fix: bug in remapping
Troublor Mar 31, 2024
f46468c
fix: loosen the storage compatibility check
Troublor Mar 31, 2024
6f37cec
fix clippy warnings
Troublor Mar 31, 2024
2ad6e2e
fix: remapping disorder for verified foundry contracts
Troublor Mar 31, 2024
175a2bd
fix clippy and fmt warnings
Troublor Mar 31, 2024
6677953
fmt in the foundry way
Troublor Mar 31, 2024
6faa4bf
chore: restore files to be consistent with foundry fmt style
Troublor Mar 31, 2024
10b2fdc
Merge pull request #8 from EtherDebug/forge_clone
Troublor Mar 31, 2024
04d0c37
Merge remote-tracking branch 'origin/master' into tweak
Troublor Mar 31, 2024
5f13afe
fix merge bug
Troublor Mar 31, 2024
99e044f
temp fix
Troublor Apr 1, 2024
a5a48e0
fix: correct remapping on libraries
Troublor Apr 1, 2024
820d0af
fix: fix the bug when the etherscan's evm version (i.e., solc one) is…
ZhangZhuoSJTU Apr 1, 2024
8c59c86
feat: print more information for
ZhangZhuoSJTU Apr 1, 2024
120949d
chore: use eyre::ensure to refactor the code
ZhangZhuoSJTU Apr 1, 2024
fd0579b
fix: merge original remappings from etherscan
Troublor Apr 1, 2024
d0371f2
fix: compilation error
Troublor Apr 1, 2024
5a764d7
improve error message
Troublor Apr 1, 2024
b0d779d
disable block gas limit
Troublor Apr 1, 2024
be34a99
fix: add chain_id into config
ZhangZhuoSJTU Apr 1, 2024
0b97c85
fix: fix bugs when interacting with non-standard chains like BSC, als…
ZhangZhuoSJTU Apr 1, 2024
9709f74
feat: support quick mode for tweaking code
ZhangZhuoSJTU Apr 1, 2024
10fc5c0
chore: use eyre::ensure to refine some code
ZhangZhuoSJTU Apr 1, 2024
9b573ba
fix: fix bugs when calling to a non-standard precompiled contracts, e…
ZhangZhuoSJTU Apr 2, 2024
45a37bb
fix: convert all paths to absolute before loading project
Troublor Apr 2, 2024
69a14c8
fix: regulate project root path
Troublor Apr 2, 2024
9644620
fix: storage layout is missing
Troublor Apr 2, 2024
26577ff
chore: improve progress bar
Troublor Apr 2, 2024
4c7a529
fix: fix bug when there are multiple creation in the creation transac…
ZhangZhuoSJTU Apr 2, 2024
ebb00d5
fix: fix bug when address(this) is involved to assign an immutable va…
ZhangZhuoSJTU Apr 2, 2024
9b9bf08
feat: print console log in cast run
Troublor Apr 2, 2024
edf8d87
fix: improve executing previous txs progress bar
Troublor Apr 2, 2024
4bf7284
fix: hooked ADDRESS opcodes return different addresses
Troublor Apr 2, 2024
01da45e
chore: better error message on BSC
Troublor Apr 2, 2024
e19db76
add doc
Troublor Apr 3, 2024
f5861c0
add demo and ack
Troublor Apr 3, 2024
8b1fe08
refer to tweak.md in readme
Troublor Apr 3, 2024
8e6b4d1
chore: sync with the master branch
ZhangZhuoSJTU Apr 20, 2024
1cb2e01
Merge branch 'foundry-rs:master' into tweak
ZhangZhuoSJTU Apr 21, 2024
18ec355
Merge branch 'foundry-rs:master' into tweak
ZhangZhuoSJTU Apr 22, 2024
ef71c62
Merge branch 'foundry-rs:master' into tweak
ZhangZhuoSJTU Apr 22, 2024
139d2f9
Merge branch 'foundry-rs:master' into tweak
ZhangZhuoSJTU May 12, 2024
cfa15d8
resolve merge conflicts
ZhangZhuoSJTU Jun 25, 2024
b5d4153
resolve merge conflicts
ZhangZhuoSJTU Jun 25, 2024
077720f
Merge branch 'foundry-rs:master' into tweak
ZhangZhuoSJTU Jun 25, 2024
872edb1
fix CI test
ZhangZhuoSJTU Jun 25, 2024
4a465f0
fix CI test
ZhangZhuoSJTU Jun 25, 2024
bf5bd15
fix CI test
ZhangZhuoSJTU Jun 25, 2024
9423ffa
Merge branch 'foundry-rs:master' into tweak
ZhangZhuoSJTU Jun 27, 2024
505e665
Merge branch 'foundry-rs:master' into tweak
ZhangZhuoSJTU Jun 28, 2024
962783d
Merge branch 'foundry-rs:master' into tweak
ZhangZhuoSJTU Jun 30, 2024
4c890fc
Merge branch 'foundry-rs:master' into tweak
ZhangZhuoSJTU Jul 3, 2024
b639a69
Merge branch 'foundry-rs:master' into tweak
ZhangZhuoSJTU Jul 5, 2024
3f87f29
Merge branch 'foundry-rs:master' into tweak
ZhangZhuoSJTU Jul 9, 2024
6add3ce
Fixed `.clone.meta` file deserialization bug
0xstonegm Sep 6, 2024
97eef0a
Merge pull request #18 from 0xstonegm/tweak
Troublor Oct 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ members = [
"crates/forge/",
"crates/macros/",
"crates/test-utils/",
"crates/tweak/"
]
resolver = "2"

Expand Down Expand Up @@ -153,6 +154,7 @@ foundry-evm-fuzz = { path = "crates/evm/fuzz" }
foundry-evm-traces = { path = "crates/evm/traces" }
foundry-macros = { path = "crates/macros" }
foundry-test-utils = { path = "crates/test-utils" }
foundry-tweak = { path = "crates/tweak" }
foundry-wallets = { path = "crates/wallets" }
foundry-linking = { path = "crates/linking" }

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

![Github Actions][gha-badge] [![Telegram Chat][tg-badge]][tg-url] [![Telegram Support][tg-support-badge]][tg-support-url]

### Foundry tweak is available to tweak the code of on-chain contracts, please see [TWEAK.md](./TWEAK.md)!

[gha-badge]: https://img.shields.io/github/actions/workflow/status/foundry-rs/foundry/test.yml?branch=master
[tg-badge]: https://img.shields.io/endpoint?color=neon&logo=telegram&label=chat&style=flat-square&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Ffoundry_rs
[tg-url]: https://t.me/foundry_rs
Expand Down
72 changes: 72 additions & 0 deletions TWEAK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Foundry with on-chain contract Tweak!

**Tweak** allows users/developers to alter the code of an on-chain contract with the on-chain state untouched.
Almost any modification is allowed, as long as the storage layout is preserved.

With **Tweak**, you can:
- Add `console.log()` in any on-chain contracts with source code available on Etherscan.
- Change the logic of an on-chain contract (e.g., fixing bugs, conduct what-if analysis, etc.)

Tweaking on-chain contracts are especially useful when:
- inspecting the execution on-chain transactions;
- investigating the logic of a complex contract (e.g., UniswapV3) on chain;
- debug the interaction with on-chain contracts which produce unexpected revert errors.

Here's the demo!
[![asciicast](https://asciinema.org/a/650466.svg)](https://asciinema.org/a/650466)

## Installation

This project is a fork of foundry.
The easiest way to install is to compile this project and replace the foundry toolchain originally on your machine.

```
cargo build
```

The executables are available in `target/debug` folder.
All the tools that you are familiar in foundry are still there.

What is enhanced is the `cast` and `forge` command.

## Usage 1: Clone a verified contract code from Etherscan

```
forge clone <address> <path>
```

`forge clone` is a new feature that downloads the source code of a verified contract at `<address>` from Etherscan (or other block explorers supported by foundry) and save as a foundry project in the specified `<path>`.

The cloned project is fully compilable foundry project, guaranteed to generate exactly the same bytecode as the on-chain contract.

## Usage 2: Tweak one on-chain contract and replay a historical transaction invoking it

```
cd path/to/cloned/contract/project
forge replay <transaction_hash>
```

If the current working directory is a foundry project created by `forge clone`, then the command `forge replay` is available to replay a historical transaction with the on-chain contract's code tweaked by the current project.
Note that the cloned project "knows" which contract address it should tweak.

You may want to modify the code of the cloned contract (e.g., add `console.log`s) before running `forge replay`.

## Usage 3: Tweak multiple on-chain contracts and replay a historical transaction invoking them

```
cast run --tweak <path/to/cloned/project1> --tweak <path/to/cloned/project2> <transaction_hash>
```

`cast run` is also enhanced by allowing specified cloned projects to tweak the code of multiple on-chain contracts.
Note that each cloned project "knows" which contract address it should tweak.

## Disclaimer

The **Tweak** feature is still under active development as part of the __EtherDebug__ project, whose ultimate goal is improve the overall development and debugging experience of EVM-compatibla smart contracts.

The functionality is not stable yet and may suffer from breaking change in the future.
Any contribution (bug reports, PRs, documentation, etc.) is welcome and greatly appreciated.

## Acknowledgement

Contributed by @Troublor and @ZhangZhuoSJTU with passion.
1 change: 1 addition & 0 deletions crates/cast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ foundry-compilers.workspace = true
foundry-config.workspace = true
foundry-evm.workspace = true
foundry-wallets.workspace = true
foundry-tweak.workspace = true

alloy-chains.workspace = true
alloy-consensus = { workspace = true, features = ["serde", "kzg"] }
Expand Down
71 changes: 63 additions & 8 deletions crates/cast/bin/cmd/run.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::path::PathBuf;

use alloy_primitives::U256;
use alloy_provider::Provider;
use alloy_rpc_types::BlockTransactions;
use cast::{revm::primitives::EnvWithHandlerCfg, traces::TraceKind};
use cast::{decode::decode_console_logs, revm::primitives::EnvWithHandlerCfg, traces::TraceKind};
use clap::Parser;
use eyre::{Result, WrapErr};
use foundry_cli::{
Expand All @@ -16,6 +18,7 @@ use foundry_evm::{
opts::EvmOpts,
utils::configure_tx_env,
};
use foundry_tweak::tweak_backend;

/// CLI arguments for `cast run`.
#[derive(Clone, Debug, Parser)]
Expand All @@ -32,6 +35,7 @@ pub struct RunArgs {
trace_printer: bool,

/// Executes the transaction only with the state from the previous block.
/// Note that this also include transactions that are used for tweaking code.
///
/// May result in different results than the live execution!
#[arg(long, short)]
Expand Down Expand Up @@ -71,6 +75,13 @@ pub struct RunArgs {
/// See also, https://docs.alchemy.com/reference/compute-units#what-are-cups-compute-units-per-second
#[arg(long, value_name = "NO_RATE_LIMITS", visible_alias = "no-rpc-rate-limit")]
pub no_rate_limit: bool,

/// One `forge clone`d project that will be used to tweak the code of the corresponding
/// on-chain contract.
///
/// This option can be used multiple times to tweak multiple contracts.
#[arg(long, value_name = "CLONED_PROJECT")]
pub tweak: Vec<PathBuf>,
}

impl RunArgs {
Expand All @@ -80,8 +91,8 @@ impl RunArgs {
///
/// Note: This executes the transaction(s) as is: Cheatcodes are disabled
pub async fn run(self) -> Result<()> {
let figment =
Config::figment_with_root(find_project_root_path(None).unwrap()).merge(self.rpc);
let figment = Config::figment_with_root(find_project_root_path(None).unwrap())
.merge(self.rpc.clone());
let evm_opts = figment.extract::<EvmOpts>()?;
let mut config = Config::try_from(figment)?.sanitized();

Expand Down Expand Up @@ -143,6 +154,24 @@ impl RunArgs {
}

let mut executor = TracingExecutor::new(env.clone(), fork, evm_version, self.debug);
if !self.tweak.is_empty() {
// If user specified tweak projects, we need to tweak the code of the contracts
let mut cloned_projects: Vec<foundry_tweak::ClonedProject> = vec![];
for path in self.tweak.iter() {
let path = dunce::canonicalize(path)
.map_err(|e| eyre::eyre!("failed to load tweak project: {:?}", e))?;
let project =
foundry_tweak::ClonedProject::load_with_root(&path).wrap_err_with(|| {
format!("failed to load tweak project from path: {:?}", &path)
})?;
cloned_projects.push(project);
}
let tweak_map =
foundry_tweak::build_tweak_data(&cloned_projects, &self.rpc, self.quick).await?;
tweak_backend(executor.backend_mut(), &tweak_map)?;
}
println!("Executing transaction: {:?}", tx.hash);

let mut env =
EnvWithHandlerCfg::new_with_spec_id(Box::new(env.clone()), executor.spec_id());

Expand All @@ -158,6 +187,10 @@ impl RunArgs {
return Err(eyre::eyre!("Could not get block txs"))
};

let txs = txs.into_iter().take_while(|tx| tx.hash != tx_hash).collect::<Vec<_>>();
let pb = init_progress(txs.len() as u64, "tx");
pb.set_position(0);

for (index, tx) in txs.into_iter().enumerate() {
// System transactions such as on L2s don't contain any pricing info so
// we skip them otherwise this would cause
Expand Down Expand Up @@ -206,22 +239,44 @@ impl RunArgs {
}

// Execute our transaction
let result = {
executor.set_trace_printer(self.trace_printer);

let (result, console_logs) = {
configure_tx_env(&mut env, &tx);

if let Some(to) = tx.to {
trace!(tx=?tx.hash, to=?to, "executing call transaction");
TraceResult::from_raw(executor.transact_with_env(env)?, TraceKind::Execution)
let result = executor.transact_with_env(env)?;
let logs = decode_console_logs(&result.logs);
(TraceResult::from_raw(result, TraceKind::Execution), logs)
} else {
trace!(tx=?tx.hash, "executing create transaction");
TraceResult::try_from(executor.deploy_with_env(env, None))?
let deploy_result = executor.deploy_with_env(env, None);
match deploy_result {
Ok(res) => {
let logs = decode_console_logs(&res.logs);
(TraceResult::from(res), logs)
}
Err(ref err) => {
let logs = match &err {
EvmError::Execution(e) => decode_console_logs(&e.logs),
_ => vec![],
};
(TraceResult::try_from(deploy_result)?, logs)
}
}
}
};

handle_traces(result, &config, chain, self.label, self.debug).await?;

// print logs if any
if !console_logs.is_empty() {
println!("Logs:");
for log in console_logs {
println!(" {log}");
}
println!();
}

Ok(())
}
}
5 changes: 5 additions & 0 deletions crates/evm/evm/src/executors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ impl Executor {
&self.env.env
}

/// Returns a reference to the EVM environment with the handler configuration.
pub fn env_with_handler_cfg(&self) -> &EnvWithHandlerCfg {
&self.env
}

/// Returns a mutable reference to the EVM environment.
pub fn env_mut(&mut self) -> &mut Env {
&mut self.env.env
Expand Down
1 change: 1 addition & 0 deletions crates/forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ foundry-config.workspace = true
foundry-evm.workspace = true
foundry-wallets.workspace = true
foundry-linking.workspace = true
foundry-tweak.workspace = true

ethers-contract-abigen = { workspace = true, features = ["providers"] }

Expand Down
18 changes: 17 additions & 1 deletion crates/forge/bin/cmd/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ pub struct DebugArgs {
#[arg(long, short, default_value = "run()", value_name = "SIGNATURE")]
pub sig: String,

/// One `forge clone`d project that will be used to tweak the code of the corresponding
/// on-chain contract.
///
/// This option can be used multiple times to tweak multiple contracts.
#[arg(long, value_name = "CLONED_PROJECT")]
pub tweak: Vec<PathBuf>,

/// When tweaking the contract, use the quick mode where we replay the creation transaction
/// only with the state from the previous block.
///
/// May result in different results than the live execution!
#[arg(long, requires = "tweak")]
pub tweak_quick: bool,

/// Open the script in the debugger.
#[arg(long)]
pub debug: bool,
Expand All @@ -50,8 +64,10 @@ impl DebugArgs {
gas_estimate_multiplier: 130,
opts: self.opts,
evm_opts: self.evm_opts,
debug: true,
debug: self.debug,
retry: RETRY_VERIFY_ON_CREATE,
tweak: self.tweak,
tweak_quick: self.tweak_quick,
..Default::default()
};
script.run_script().await
Expand Down
1 change: 1 addition & 0 deletions crates/forge/bin/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ pub mod inspect;
pub mod install;
pub mod remappings;
pub mod remove;
pub mod replay;
pub mod selectors;
pub mod snapshot;
pub mod soldeer;
Expand Down
Loading