• Mark Tyneway's avatar
    contracts-bedrock: delete dead code (#10359) · 40421e86
    Mark Tyneway authored
    * 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>
    40421e86
make-summary-deployment.sh 3.47 KB
#!/bin/bash
set -euo pipefail

export FOUNDRY_PROFILE=kdeploy

SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# shellcheck source=/dev/null
source "$SCRIPT_HOME/common.sh"
# Sanity check on arguments
if [ $# -gt 1 ]; then
  echo "At most one argument can be provided. Instead $# were provided" 1>&2
  exit 1
elif [ $# -eq 1 ]; then
  if [ "$1" != "-h" ] && [ "$1" != "--help" ] && [ "$1" != "container" ] && [ "$1" != "local" ] && [ "$1" != "dev" ]; then
    notif "Invalid argument. Must be \`container\`, \`local\`, \`dev\`, \`-h\` or \`--help\`"
    exit 1
  else
    parse_first_arg "$@"
  fi
fi

cleanup() {
  trap
  # Restore the original script from the backup
  if [ -f "$DEPLOY_SCRIPT.bak" ]; then
    cp "$DEPLOY_SCRIPT.bak" "$DEPLOY_SCRIPT"
    rm "$DEPLOY_SCRIPT.bak"
  fi

  if [ -f "snapshots/state-diff/Deploy.json" ]; then
    rm "snapshots/state-diff/Deploy.json"
  fi

  if [ "$LOCAL" = false ]; then
    clean_docker
  fi
}

# Set trap to call cleanup function on exit
trap cleanup EXIT ERR

# create deployments/hardhat/.deploy and snapshots/state-diff/Deploy.json if necessary
if [ ! -d "deployments/hardhat" ]; then
  mkdir deployments/hardhat;
fi
if [ ! -f "deployments/hardhat/.deploy" ]; then
  touch deployments/hardhat/.deploy;
fi
if [ ! -d "snapshots/state-diff" ]; then
  mkdir snapshots/state-diff;
fi
if [ ! -f "snapshots/state-diff/Deploy.json" ]; then
  touch snapshots/state-diff/Deploy.json;
fi

DEPLOY_SCRIPT="./scripts/Deploy.s.sol"
conditionally_start_docker

# Create a backup
cp $DEPLOY_SCRIPT $DEPLOY_SCRIPT.bak

# Replace mustGetAddress by getAddress in Deploy.s.sol
# This is needed because the Kontrol deployment is only a partial
# version of the full Optimism deployment. Since not all the components
# 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

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"

# Clean and store the state diff json in snapshots/state-diff/Kontrol-Deploy.json
JSON_SCRIPTS=test/kontrol/scripts/json
GENERATED_STATEDIFF=31337.json # Name of the statediff json produced by the deployment script
STATEDIFF=Kontrol-$GENERATED_STATEDIFF # Name of the Kontrol statediff
mv snapshots/state-diff/$GENERATED_STATEDIFF 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
echo "Cleaned state diff json"

python3 $JSON_SCRIPTS/reverse_key_values.py $CONTRACT_NAMES ${CONTRACT_NAMES}Reversed
CONTRACT_NAMES=${CONTRACT_NAMES}Reversed

SUMMARY_DIR=test/kontrol/proofs/utils
SUMMARY_NAME=DeploymentSummary
LICENSE=MIT

copy_to_docker # Copy the newly generated files to the docker container
run kontrol load-state-diff $SUMMARY_NAME snapshots/state-diff/$STATEDIFF --contract-names $CONTRACT_NAMES --output-dir $SUMMARY_DIR --license $LICENSE
if [ "$LOCAL" = false ]; then
    # Sync Snapshot updates to the host
    docker cp "$CONTAINER_NAME:/home/user/workspace/$SUMMARY_DIR" "$WORKSPACE_DIR/$SUMMARY_DIR/.."
fi
forge fmt $SUMMARY_DIR/$SUMMARY_NAME.sol
forge fmt $SUMMARY_DIR/${SUMMARY_NAME}Code.sol
echo "Added state updates to $SUMMARY_DIR/$SUMMARY_NAME.sol"