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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
skeleton of compatibility check
Troublor committed Mar 28, 2024
commit 13a2a7ddbfc9bd7a949068ed4d115679ac059271
5 changes: 5 additions & 0 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions crates/tweak/Cargo.toml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ vergen = { workspace = true, default-features = false, features = [
# lib
foundry-block-explorers = { workspace = true, features = ["foundry-compilers"] }
foundry-common.workspace = true
# foundry-compilers = { workspace = true, features = ["full"] }
foundry-compilers = { workspace = true, features = ["full"] }
foundry-config.workspace = true
foundry-evm.workspace = true
# foundry-wallets.workspace = true
@@ -35,10 +35,10 @@ foundry-evm.workspace = true
# revm-inspectors.workspace = true

# comfy-table = "7"
# eyre.workspace = true
eyre.workspace = true
# proptest = "1"
# rayon = "1"
# serde.workspace = true
serde.workspace = true
# tracing.workspace = true
# yansi = "0.5"

@@ -52,7 +52,7 @@ foundry-evm.workspace = true

# alloy-dyn-abi.workspace = true
# alloy-json-abi.workspace = true
# alloy-primitives = { workspace = true, features = ["serde"] }
alloy-primitives = { workspace = true, features = ["serde"] }
# alloy-rpc-types.workspace = true

# async-trait = "0.1"
@@ -76,7 +76,7 @@ foundry-evm.workspace = true
# strum = { workspace = true, features = ["derive"] }
# thiserror = "1"
# tokio = { version = "1", features = ["time"] }
# toml = { version = "0.8", features = ["preserve_order"] }
toml = { version = "0.8", features = ["preserve_order"] }
# toml_edit = "0.21"
# watchexec = "2.3.2"
# evm-disassembler.workspace = true
42 changes: 42 additions & 0 deletions crates/tweak/src/compatibility.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//! Compatibility check of tweaking an on-chain contract with a local cloned project.
//! The local project usually should be created by `forge clone` command.
//! The `clone.toml` metadata file should be present in the root directory of the project.
//! Users may modify the source code of the cloned project, but the storage layout should remain the same as the original contract.

use std::path::PathBuf;

use foundry_compilers::artifacts::StorageLayout;

use crate::metadata::CloneMetadata;

/// Check the tweak compatibility of the project with the given root.
/// The project is compatible if:
/// 1. the project has the `clone.toml` metadata file in the root directory, which defines its original contract on chain.
/// 2. the project's storage layout is the same as the original contract.
/// If the project is not compatible, an error is returned.
pub fn check_compatibility(root: &PathBuf) -> eyre::Result<()> {
// the clone metadata
let clone_metadata = CloneMetadata::load_with_root(root).map_err(|e| {
eyre::eyre!("the clone metadata file (clone.toml) does not exist or is invalid: {}", e)
})?;

// to check the storage layout compatibility, we need to download the original contract's code from etherscan and compile.
let original_layout = get_original_storage_layout(&clone_metadata)?;
let current_layout = get_current_storage_layout(root)?;
check_storage_layout_compatibility(original_layout, current_layout)
}

pub fn get_original_storage_layout(_clone_metadata: &CloneMetadata) -> eyre::Result<StorageLayout> {
todo!()
}

pub fn get_current_storage_layout(_root: &PathBuf) -> eyre::Result<StorageLayout> {
todo!()
}

pub fn check_storage_layout_compatibility(
_original: StorageLayout,
_current: StorageLayout,
) -> eyre::Result<()> {
todo!()
}
2 changes: 2 additions & 0 deletions crates/tweak/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod compatibility;
mod metadata;
35 changes: 35 additions & 0 deletions crates/tweak/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::path::PathBuf;

use alloy_primitives::{Address, ChainId, TxHash};
use eyre::Result;

/// CloneMetadata stores the metadata that are not included by `foundry.toml` but necessary for a cloned contract.
/// The metadata can be serialized to the `clone.toml` file in the cloned project root.
/// This struct is the twin of the `CloneMetadata` struct in the `clone` command of `forge` crate.
#[derive(Debug, Clone, serde::Deserialize)]
pub struct CloneMetadata {
/// The path to the source file that contains the contract declaration.
/// The path is relative to the root directory of the project.
pub path: PathBuf,
/// The name of the contract in the file.
pub target_contract: String,
/// The address of the contract on the blockchian.
pub address: Address,
/// The chain id.
pub chain_id: ChainId,
/// The transaction hash of the creation transaction.
pub creation_transaction: TxHash,
/// The address of the deployer (caller of the CREATE/CREATE2).
pub deployer: Address,
}

impl CloneMetadata {
/// Load the metadata from the `clone.toml` file in the root directory of the project.
/// If the file does not exist, an error is returned.
pub fn load_with_root(root: &PathBuf) -> Result<CloneMetadata> {
let path = root.join("clone.toml");
let metadata = std::fs::read_to_string(&path)?;
let metadata = toml::from_str(&metadata)?;
Ok(metadata)
}
}