Commit 40421e86 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

contracts-bedrock: delete dead code (#10359)

* contracts-bedrock: simplify L1 state dump

Removes the need to specify the L1 chainid via CLI.
Follows similar patterns to L2 genesis generation that
were done recently.

Follow up PRs can potentially use the same sort of deployer pattern
as in https://github.com/ethereum-optimism/optimism/pull/10343
for when doing the L1 genesis dump to remove the need to specify the
private key.

* contracts-bedrock: explicit deploy config

Remove the concept of implicit deploy config for explicit deploy config.
This removes confusing implicit behavior as well as makes it much
more straight forward for deploying multiple superchain targets
to the same L1. This is a breaking change but the error message
makes it very obvious and the docs are being updated in a way
that should include this information.

* contracts-bedrock: fix possible error

* config: cleanup

* deploy-config: fixup

* contracts-bedrock: delete name function

The `name()` function existed due to legacy
purposes when dealing with hardhat artifacts
and no longer is necessary. This commit removes
it in favor of a simpler approach of just using
the chainid instead of the name. The files that
are written are not committed into the repo.

* contracts: delete dead code

* lint: fix

* kontrol: fixup

* contracts-bedrock: prevent error

* kontrol: fixup

* kontrol: fix script

* gitignore: update

* devnet: simplify

* Update packages/contracts-bedrock/scripts/Config.sol
Co-authored-by: default avatarMatt Solomon <matt@mattsolomon.dev>

---------
Co-authored-by: default avatarMatt Solomon <matt@mattsolomon.dev>
parent 2b1c99b3
...@@ -142,10 +142,12 @@ def devnet_l1_allocs(paths): ...@@ -142,10 +142,12 @@ def devnet_l1_allocs(paths):
init_devnet_l1_deploy_config(paths) init_devnet_l1_deploy_config(paths)
fqn = 'scripts/Deploy.s.sol:Deploy' fqn = 'scripts/Deploy.s.sol:Deploy'
# Use foundry pre-funded account #1 for the deployer
run_command([ run_command([
'forge', 'script', '--chain-id', '900', fqn, "--sig", "runWithStateDump()", "--private-key", "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" 'forge', 'script', fqn, "--sig", "runWithStateDump()"
], env={}, cwd=paths.contracts_bedrock_dir) ], env={
'DEPLOYMENT_OUTFILE': paths.l1_deployments_path,
'DEPLOY_CONFIG_PATH': paths.devnet_config_path,
}, cwd=paths.contracts_bedrock_dir)
forge_dump = read_json(paths.forge_l1_dump_path) forge_dump = read_json(paths.forge_l1_dump_path)
write_json(paths.allocs_l1_path, { "accounts": forge_dump }) write_json(paths.allocs_l1_path, { "accounts": forge_dump })
...@@ -162,6 +164,7 @@ def devnet_l2_allocs(paths): ...@@ -162,6 +164,7 @@ def devnet_l2_allocs(paths):
'forge', 'script', fqn, "--sig", "runWithAllUpgrades()" 'forge', 'script', fqn, "--sig", "runWithAllUpgrades()"
], env={ ], env={
'CONTRACT_ADDRESSES_PATH': paths.l1_deployments_path, 'CONTRACT_ADDRESSES_PATH': paths.l1_deployments_path,
'DEPLOY_CONFIG_PATH': paths.devnet_config_path,
}, cwd=paths.contracts_bedrock_dir) }, cwd=paths.contracts_bedrock_dir)
# For the previous forks, and the latest fork (default, thus empty prefix), # For the previous forks, and the latest fork (default, thus empty prefix),
......
...@@ -29,6 +29,10 @@ deployments/hardhat ...@@ -29,6 +29,10 @@ deployments/hardhat
deployments/getting-started deployments/getting-started
deployments/*/.deploy deployments/*/.deploy
deployments/1337 deployments/1337
deployments/31337-deploy.json
deployments/kontrol.json
deployments/kontrol.jsonReversed
snapshots/state-diff/Kontrol-31337.json
# Devnet config which changes with each 'make devnet-up' # Devnet config which changes with each 'make devnet-up'
deploy-config/devnetL1.json deploy-config/devnetL1.json
......
Subproject commit bb4ceea94d6f10eeb5b41dc2391c6c8bf8e734ef Subproject commit 2d8b7b876a5b328d6a73e13c4740ed7a0d72d5f4
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.0; pragma solidity ^0.8.0;
import { Vm } from "forge-std/Vm.sol"; import { Vm, VmSafe } from "forge-std/Vm.sol";
import { Chains } from "scripts/Chains.sol";
/// @title Config /// @title Config
/// @notice Contains all env var based config. Add any new env var parsing to this file /// @notice Contains all env var based config. Add any new env var parsing to this file
...@@ -15,15 +14,19 @@ library Config { ...@@ -15,15 +14,19 @@ library Config {
/// written to disk after doing a deployment. /// written to disk after doing a deployment.
function deploymentOutfile() internal view returns (string memory _env) { function deploymentOutfile() internal view returns (string memory _env) {
_env = vm.envOr( _env = vm.envOr(
"DEPLOYMENT_OUTFILE", string.concat(vm.projectRoot(), "/deployments/", _getDeploymentContext(), "/.deploy") "DEPLOYMENT_OUTFILE",
string.concat(vm.projectRoot(), "/deployments/", vm.toString(block.chainid), "-deploy.json")
); );
} }
/// @notice Returns the path on the local filesystem where the deploy config is /// @notice Returns the path on the local filesystem where the deploy config is
function deployConfigPath() internal view returns (string memory _env) { function deployConfigPath() internal view returns (string memory _env) {
_env = vm.envOr( if (vm.isContext(VmSafe.ForgeContext.TestGroup)) {
"DEPLOY_CONFIG_PATH", string.concat(vm.projectRoot(), "/deploy-config/", _getDeploymentContext(), ".json") _env = string.concat(vm.projectRoot(), "/deploy-config/hardhat.json");
); } else {
_env = vm.envOr("DEPLOY_CONFIG_PATH", string(""));
require(bytes(_env).length > 0, "Config: must set DEPLOY_CONFIG_PATH to filesystem path of deploy config");
}
} }
/// @notice Returns the chainid from the EVM context or the value of the CHAIN_ID env var as /// @notice Returns the chainid from the EVM context or the value of the CHAIN_ID env var as
...@@ -39,12 +42,6 @@ library Config { ...@@ -39,12 +42,6 @@ library Config {
_env = vm.envOr("CONTRACT_ADDRESSES_PATH", string("")); _env = vm.envOr("CONTRACT_ADDRESSES_PATH", string(""));
} }
/// @notice Returns the deployment context which was only useful in the hardhat deploy style
/// of deployments. It is now DEPRECATED and will be removed in the future.
function deploymentContext() internal view returns (string memory _env) {
_env = vm.envOr("DEPLOYMENT_CONTEXT", string(""));
}
/// @notice The CREATE2 salt to be used when deploying the implementations. /// @notice The CREATE2 salt to be used when deploying the implementations.
function implSalt() internal view returns (string memory _env) { function implSalt() internal view returns (string memory _env) {
_env = vm.envOr("IMPL_SALT", string("ethers phoenix")); _env = vm.envOr("IMPL_SALT", string("ethers phoenix"));
...@@ -59,12 +56,6 @@ library Config { ...@@ -59,12 +56,6 @@ library Config {
); );
} }
/// @notice Returns the sig of the entrypoint to the deploy script. By default, it is `run`.
/// This was useful for creating hardhat deploy style artifacts and will be removed in a future release.
function sig() internal view returns (string memory _env) {
_env = vm.envOr("SIG", string("run"));
}
/// @notice Returns the name of the file that the forge deployment artifact is written to on the local /// @notice Returns the name of the file that the forge deployment artifact is written to on the local
/// filesystem. By default, it is the name of the deploy script with the suffix `-latest.json`. /// filesystem. By default, it is the name of the deploy script with the suffix `-latest.json`.
/// This was useful for creating hardhat deploy style artifacts and will be removed in a future release. /// This was useful for creating hardhat deploy style artifacts and will be removed in a future release.
...@@ -76,35 +67,4 @@ library Config { ...@@ -76,35 +67,4 @@ library Config {
function drippieOwnerPrivateKey() internal view returns (uint256 _env) { function drippieOwnerPrivateKey() internal view returns (uint256 _env) {
_env = vm.envUint("DRIPPIE_OWNER_PRIVATE_KEY"); _env = vm.envUint("DRIPPIE_OWNER_PRIVATE_KEY");
} }
/// @notice The context of the deployment is used to namespace the artifacts.
/// An unknown context will use the chainid as the context name.
/// This is legacy code and should be removed in the future.
function _getDeploymentContext() private view returns (string memory) {
string memory context = deploymentContext();
if (bytes(context).length > 0) {
return context;
}
uint256 chainid = Config.chainID();
if (chainid == Chains.Mainnet) {
return "mainnet";
} else if (chainid == Chains.Goerli) {
return "goerli";
} else if (chainid == Chains.OPGoerli) {
return "optimism-goerli";
} else if (chainid == Chains.OPMainnet) {
return "optimism-mainnet";
} else if (chainid == Chains.LocalDevnet || chainid == Chains.GethDevnet || chainid == Chains.OPLocalDevnet) {
return "devnetL1";
} else if (chainid == Chains.Hardhat) {
return "hardhat";
} else if (chainid == Chains.Sepolia) {
return "sepolia";
} else if (chainid == Chains.OPSepolia) {
return "optimism-sepolia";
} else {
return vm.toString(chainid);
}
}
} }
...@@ -116,9 +116,14 @@ contract Deploy is Deployer { ...@@ -116,9 +116,14 @@ contract Deploy is Deployer {
vm.startStateDiffRecording(); vm.startStateDiffRecording();
_; _;
VmSafe.AccountAccess[] memory accesses = vm.stopAndReturnStateDiff(); VmSafe.AccountAccess[] memory accesses = vm.stopAndReturnStateDiff();
console.log("Writing %d state diff account accesses to snapshots/state-diff/%s.json", accesses.length, name()); console.log(
"Writing %d state diff account accesses to snapshots/state-diff/%s.json",
accesses.length,
vm.toString(block.chainid)
);
string memory json = LibStateDiff.encodeAccountAccesses(accesses); string memory json = LibStateDiff.encodeAccountAccesses(accesses);
string memory statediffPath = string.concat(vm.projectRoot(), "/snapshots/state-diff/", name(), ".json"); string memory statediffPath =
string.concat(vm.projectRoot(), "/snapshots/state-diff/", vm.toString(block.chainid), ".json");
vm.writeJson({ json: json, path: statediffPath }); vm.writeJson({ json: json, path: statediffPath });
} }
...@@ -126,11 +131,6 @@ contract Deploy is Deployer { ...@@ -126,11 +131,6 @@ contract Deploy is Deployer {
// Accessors // // Accessors //
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
/// @inheritdoc Deployer
function name() public pure override returns (string memory name_) {
name_ = "Deploy";
}
/// @notice The create2 salt used for deployment of the contract implementations. /// @notice The create2 salt used for deployment of the contract implementations.
/// Using this helps to reduce config across networks as the implementation /// Using this helps to reduce config across networks as the implementation
/// addresses will be the same across networks when deployed with create2. /// addresses will be the same across networks when deployed with create2.
...@@ -261,6 +261,7 @@ contract Deploy is Deployer { ...@@ -261,6 +261,7 @@ contract Deploy is Deployer {
} }
function runWithStateDump() public { function runWithStateDump() public {
vm.chainId(cfg.l1ChainID());
_run(); _run();
vm.dumpState(Config.stateDumpPath("")); vm.dumpState(Config.stateDumpPath(""));
} }
......
...@@ -26,11 +26,6 @@ import { Config } from "scripts/Config.sol"; ...@@ -26,11 +26,6 @@ import { Config } from "scripts/Config.sol";
contract DeployPeriphery is Script, Artifacts { contract DeployPeriphery is Script, Artifacts {
PeripheryDeployConfig cfg; PeripheryDeployConfig cfg;
/// @notice The name of the script, used to ensure the right deploy artifacts are used.
function name() public pure returns (string memory name_) {
name_ = "DeployPeriphery";
}
/// @notice Sets up the deployment script. /// @notice Sets up the deployment script.
function setUp() public override { function setUp() public override {
Artifacts.setUp(); Artifacts.setUp();
......
...@@ -26,10 +26,4 @@ abstract contract Deployer is Script, Artifacts { ...@@ -26,10 +26,4 @@ abstract contract Deployer is Script, Artifacts {
vm.allowCheatcodes(address(cfg)); vm.allowCheatcodes(address(cfg));
cfg.read(Config.deployConfigPath()); cfg.read(Config.deployConfigPath());
} }
/// @notice Returns the name of the deployment script. Children contracts
/// must implement this to ensure that the deploy artifacts can be found.
/// This should be the same as the name of the script and is used as the file
/// name inside of the `broadcast` directory when looking up deployment artifacts.
function name() public pure virtual returns (string memory);
} }
...@@ -105,10 +105,6 @@ contract L2Genesis is Deployer { ...@@ -105,10 +105,6 @@ contract L2Genesis is Deployer {
super.setUp(); super.setUp();
} }
function name() public pure override returns (string memory) {
return "L2Genesis";
}
function artifactDependencies() internal view returns (L1Dependencies memory l1Dependencies_) { function artifactDependencies() internal view returns (L1Dependencies memory l1Dependencies_) {
return L1Dependencies({ return L1Dependencies({
l1CrossDomainMessengerProxy: mustGetAddress("L1CrossDomainMessengerProxy"), l1CrossDomainMessengerProxy: mustGetAddress("L1CrossDomainMessengerProxy"),
......
...@@ -65,19 +65,22 @@ cp $DEPLOY_SCRIPT $DEPLOY_SCRIPT.bak ...@@ -65,19 +65,22 @@ cp $DEPLOY_SCRIPT $DEPLOY_SCRIPT.bak
# of the system are deployed, we'd get some reverts on the `mustGetAddress` functions # of the system are deployed, we'd get some reverts on the `mustGetAddress` functions
awk '{gsub(/mustGetAddress/, "getAddress")}1' $DEPLOY_SCRIPT > temp && mv temp $DEPLOY_SCRIPT awk '{gsub(/mustGetAddress/, "getAddress")}1' $DEPLOY_SCRIPT > temp && mv temp $DEPLOY_SCRIPT
forge script -vvv test/kontrol/deployment/KontrolDeployment.sol:KontrolDeployment --sig 'runKontrolDeployment()' CONTRACT_NAMES=deployments/kontrol.json
DEPLOY_CONFIG_PATH=deploy-config/hardhat.json \
DEPLOYMENT_OUTFILE="$CONTRACT_NAMES" \
forge script -vvv test/kontrol/deployment/KontrolDeployment.sol:KontrolDeployment --sig 'runKontrolDeployment()'
echo "Created state diff json" echo "Created state diff json"
# Clean and store the state diff json in snapshots/state-diff/Kontrol-Deploy.json # Clean and store the state diff json in snapshots/state-diff/Kontrol-Deploy.json
JSON_SCRIPTS=test/kontrol/scripts/json JSON_SCRIPTS=test/kontrol/scripts/json
GENERATED_STATEDIFF=Deploy.json # Name of the statediff json produced by the deployment script GENERATED_STATEDIFF=31337.json # Name of the statediff json produced by the deployment script
STATEDIFF=Kontrol-$GENERATED_STATEDIFF # Name of the Kontrol statediff STATEDIFF=Kontrol-$GENERATED_STATEDIFF # Name of the Kontrol statediff
mv snapshots/state-diff/$GENERATED_STATEDIFF snapshots/state-diff/$STATEDIFF mv snapshots/state-diff/$GENERATED_STATEDIFF snapshots/state-diff/$STATEDIFF
python3 $JSON_SCRIPTS/clean_json.py snapshots/state-diff/$STATEDIFF python3 $JSON_SCRIPTS/clean_json.py snapshots/state-diff/$STATEDIFF
jq . snapshots/state-diff/$STATEDIFF > temp && mv temp snapshots/state-diff/$STATEDIFF # Prettify json jq . snapshots/state-diff/$STATEDIFF > temp && mv temp snapshots/state-diff/$STATEDIFF # Prettify json
echo "Cleaned state diff json" echo "Cleaned state diff json"
CONTRACT_NAMES=deployments/hardhat/.deploy
python3 $JSON_SCRIPTS/reverse_key_values.py $CONTRACT_NAMES ${CONTRACT_NAMES}Reversed python3 $JSON_SCRIPTS/reverse_key_values.py $CONTRACT_NAMES ${CONTRACT_NAMES}Reversed
CONTRACT_NAMES=${CONTRACT_NAMES}Reversed CONTRACT_NAMES=${CONTRACT_NAMES}Reversed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment