Skip to content

forge clone: Clone verified contracts as foundry project #7575

@Troublor

Description

@Troublor

Component

Forge

Describe the feature you would like

Problem

Currently, foundry provides a feature that downloads the source code of contracts from Etherscan: cast etherscan-source. However, cast etherscan-source only dumps the sources of contract in the filesystem simply, without being able to compile.
This creates an obstacle on blockchain developers, who may want to re-compile the contracts of popular DApps, customize it, deploy in a local chain, write foundry tests/scripts with the contract, etc.

Proposal

We propose to add a new subcommand for forge: forge clone, which clones source code of a verified contract on Etherscan and creates a foundry project on local file system. The usage of the command is forge clone <address> <path/to/cloned/project>.
Our fork of foundry, EtherDebug/foundry, has already implement this feature. We encourage developers to try out this subcommand on our fork of foundry.

We welcome any comments and suggestions helping us improve this feature and contribute to a better smart contract development and debugging experience.

Downstream Application

Cloning the source code of contracts from Etherscan also enables multiple downstream usage, one of which is on-chain contract tweak feature that we introduce in our fork EtherDebug/foundry.

The on-chain contract tweak allows users to alter the code of an on-chain contract with its on-chain state preserved. This feature enables a very handy feature that developers can insert "printf" into on-chain contracts and replay transactions.
The first step of tweaking an on-chain contract is to clone the source code of an on-chain contract. So we presume introducing forge clone to foundry is a significant step forward.

This tweak feature has recently attracted much attention on Twitter. We would like to bring the discussion to a broader audience regarding upstreaming the forge clone and tweak features to the main foundry project.

Disclosure

@ZhangZhuoSJTU and me (@Troublor) are the authors of EtherDebug/foundry, which introduces the On-chain Contract Tweak features in foundry. Please take a look at our demo on Twitter.

Additional context

A demo of forge clone and on-chain contract tweak feature:
asciicast

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions