Enabling foundry-esque Fork Tests on Sui

I am working on adding a feature which allows us to run fork tests on Mainnet state without committing the effects

Foundry (development framework for the EVM) creates a local fork of the EVM state at a given block, allowing users to write tests on that fork as a superuser. This is useful for getting a local copy of arbitrary mainnet/devnet state to test with, especially so for the security community (where a POC for a vulnerability would need to be tested with as the alternative would be executing it on-chain)

You can read more about it here: Fork Testing - Foundry Book
Code: https://github.com/foundry-rs/foundry/blob/d15450758ae3744dc6861956d5ebde554356683a/crates/anvil/src/eth/backend/fork.rs

You might think that this is an unecessary feature as there are sui_devInspectTransactionBlock and sui_dryRunTransactionBlock, however these only return transaction effects and do not keep a local copy of the entire blockchain state. What if we want the option of executing some fake transactions now, and waiting a bit for new transactions to run against the state? What if we want to go back in time at a given checkpoint and execute tests from that state? Even if the clock itself can be rewinded (as Sam mentioned), that will only get us so far. It seems to me that we can’t do these things currently with devInspect alone. Additionally, for long sequences of transactions exceeding the PTB limit of 1024, we cannot fit all the transactions into one block

After discussion with members of the Mysten Labs Team and Sam Blackshear I’ve determined the following requirements

Here are the requirements:

  • wind and unwind the clock object (provide helper methods to do so easily)
  • get local network state from mainnet/devnet at any given checkpoint
  • have persistent state changes after individual transactions
  • execute transactions from any account

currently, I am looking into how to isolate AuthorityState after it has caught up to the desired checkpoint. would appreciate any pointers from the mysten team, I will continue to post updates.



Create a local Sui network | Sui Docs is the base of what I will build from
(sui-test-validator crate)

I am trying to figure out how to sync the state up to a certain checkpoint on mainnet. I will try to create the local-cluster with the state sync of a full node running on mainnet. Stopping it will be a challenge as I don’t know how yet to specify a state sync to a certain checkpoint only. Since the canonical full node should not be participating in consensus as it doesn’t have voting capability, I think this is theoretically possible. We only care about the transaction data.

Configuring the node seems difficult (NodeConfig)
I’m also not sure if creating a node from scratch is the best option (all we need is the Arc of the handle)

Some Important Files:

is a script that starts a LocalCluster, a Faucet (rich account), and an (optional) indexer.

LocalNewCluster - can pass in a config file
if we pass in the fullnode config for a devnet/mainnet instance into this cluster - what happens?

  • Has the test_cluster field, which no other “cluster” has

RemoteRunningCluster - a handle to an existing (remote) cluster



1 Like