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

[WIP]Adding the Anvil Fork on the multiples tasks. #438

Draft
wants to merge 12 commits into
base: feat/sim-stacked-tasks
Choose a base branch
from
Draft
55 changes: 48 additions & 7 deletions script/utils/sim-sequence.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/bin/bash


### ADDRESS SHOULD BE GET FROM SUPERCHAIN-OPS IN THE FUTURE ###


## ETHEREUM
Security_Council_Safe=0xc2819DC788505Aac350142A7A707BF9D03E3Bd03
Foundation_Upgrade_Safe=0x847B5c174615B1B7fDF770882256e2D3E95b9D92
Foundation_Operation_Safe=0x9BA6e03D8B90dE867373Db8cF1A58d2F7F006b3A
Proxy_Admin_Owner_Safe=0x5a0Aae59D09fccBdDb6C6CcEB07B7279367C3d2A
##############################################################
# Simulates a sequence of tasks for a given network by running them against an Anvil
# fork with state overrides disabled.
#
Expand Down Expand Up @@ -51,6 +61,29 @@ cleanup() {
if [[ -f "$backup_file" ]]; then
mv "$backup_file" "$simulation_file"
fi
# Kill the anvil fork at the end
# ps aux | grep anvil | grep -v grep | awk '{print $2}' | xargs kill
}
createFork() {
# Start a fork
echo "Starting anvil fork..."
# check if the port is already open
if lsof -Pi :8545 -sTCP:LISTEN -t >/dev/null ; then
echo "Port 8545 is already in use. Please make sure to kill the process using the port before running the script."
exit 1
fi
anvil --auto-impersonate -f $RPC_URL --fork-block-number 21573136 >> /tmp/anvil.logs &
sleep 5
}

NonceDisplay(){
echo "=====================[$1] NONCES STATUS ==================="
echo "Foundation Upgrade Safe Nonce: "$(cast call $Foundation_Upgrade_Safe "nonce()(uint256)" --rpc-url http://localhost:8545)"."
echo "Foundation Operation Safe Nonce: "$(cast call $Foundation_Operation_Safe "nonce()(uint256)" --rpc-url http://localhost:8545)"."
echo "Security Council Safe Nonce: "$(cast call $Security_Council_Safe "nonce()(uint256)" --rpc-url http://localhost:8545)"."
echo "ProxyAdminOwner Nonce: "$(cast call $Proxy_Admin_Owner_Safe "nonce()(uint256)" --rpc-url http://localhost:8545)"."

echo "==========================================================="
}

# Find unique task folder(s) for a given task ID
Expand Down Expand Up @@ -82,12 +115,10 @@ fi

network="$1"
task_ids="$2"

# Determine root directory.
base_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
root_dir="$base_dir/../.."
task_base_dir="${root_dir}/tasks/${network}"

# Verify task_base_dir exists.
if [[ ! -d "$task_base_dir" ]]; then
error_exit "Task base directory '$task_base_dir' does not exist."
Expand All @@ -100,28 +131,38 @@ for task_id in $task_ids; do
task_folders+=("$matching_folders")
done


source ${task_folders[0]}/.env
echo "RPC: $ETH_RPC_URL"
RPC_URL=$ETH_RPC_URL
unset ETH_RPC_URL
echo "Simulating the following tasks in order:"
for task_folder in "${task_folders[@]}"; do
echo " $(realpath "$task_folder")"
done

# Create the anvil Fork
createFork
# Disable state overrides and execute tasks.
disable_state_overrides
export SIMULATE_WITHOUT_LEDGER=1
for task_folder in "${task_folders[@]}"; do
echo -e "\n---- Simulating task $task_folder ----"

NonceDisplay "🟧Before Simulation $(echo "$task_folder" | sed 's/.*tasks//')"
pushd "$task_folder" >/dev/null || error_exit "Failed to navigate to '$task_folder'."

# add the RPC_URL to the .env file
# echo "ETH_RPC_URL=http://localhost:8545" >> "${PWD}/.env" # Replace with the anvil fork URL
if [[ -f "${task_folder}/NestedSignFromJson.s.sol" ]]; then
echo "Task type: nested"
# TODO This currently hardcodes the council but we should also run as Foundation.
just --dotenv-path "${PWD}/.env" --justfile "${root_dir}/nested.just" simulate council
just --dotenv-path "${PWD}/.env" --justfile "${root_dir}/nested.just" simulate council > /dev/null
else
echo "Task type: single"
just --dotenv-path "${PWD}/.env" --justfile "${root_dir}/single.just" simulate
just --dotenv-path "${PWD}/.env" --justfile "${root_dir}/single.just" simulate \ 0 "http://localhost:8545" true
fi

sleep 5
NonceDisplay "🟩After Simulation $task_folder"
exit 1
popd >/dev/null || error_exit "Failed to return to previous directory."
done

Expand Down
45 changes: 43 additions & 2 deletions single.just
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ export bundleName := env_var_or_default('BUNDLE_NAME', 'input')
export taskPath := invocation_directory()
export ownerSafe := env_var('OWNER_SAFE')

simulate hdPath='0':
simulate hdPath='0' rpcUrlExternal="" broadcast="false":
#!/usr/bin/env bash
if [[ {{rpcUrlExternal}} == "" ]]; then
rpcUrl=${rpcUrl}
else
rpcUrl={{rpcUrlExternal}}
fi
echo "rpcUrl: ${rpcUrl}"
echo "value of the broadcast {{broadcast}}"
bundlePath=${taskPath}/${bundleName}.json
script=SignFromJson
if [ -f "${taskPath}/SignFromJson.s.sol" ]; then
Expand All @@ -27,11 +34,45 @@ simulate hdPath='0':
echo ""

forge build
if [[ "{{broadcast}}" == "true" ]]; then
echo "Broadcasting transaction..."
echo ${rpcUrl}
# cast rpc anvil_impersonateAccount 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url ${rpcUrl} #Impersonate the account 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 that has prefunded ETH.
# cast send ${signer} --value 10ether --rpc-url ${rpcUrl} --from 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --unlocked # Prefund some ETH


# cast rpc anvil_stopImpersonatingAccount 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url ${rpcUrl} #Stop impersonating the account 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
#
# cast rpc anvil_setStorageAt ${ownerSafe} 0x0000000000000000000000000000000000000000000000000000000000000004 0x0000000000000000000000000000000000000000000000000000000000000001 --rpc-url ${rpcUrl}
## 1. Set the threshold to 1.
echo "============ OVERRIDE SAFE SETTINGS ============"
echo "1. Set the threshold to 1."
cast rpc anvil_setStorageAt ${ownerSafe} 0x0000000000000000000000000000000000000000000000000000000000000004 0x0000000000000000000000000000000000000000000000000000000000000001 --rpc-url ${rpcUrl}

echo "2.set the owner count to 1."
## 2. Set the owner count to 1.
cast rpc anvil_setStorageAt ${ownerSafe} 0x0000000000000000000000000000000000000000000000000000000000000003 0x0000000000000000000000000000000000000000000000000000000000000001 --rpc-url ${rpcUrl}

echo "3.Insert the address 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 as the sole owner of the safe."
## 3. Set the 0xf39 address to the sole signer of the safe.
# cast keccak 1 || 2 => 0xe90b7bceb6e7df5418fb78d8ee546e97c83a08bbccc01a0644d599ccd2a7c2e0 expected owner mapping: {0x1 -> 0xf39..., 0xf39 -> 0x1}
cast rpc anvil_setStorageAt ${ownerSafe} 0xe90b7bceb6e7df5418fb78d8ee546e97c83a08bbccc01a0644d599ccd2a7c2e0 0x000000000000000000000000f39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url ${rpcUrl}
## 4. Set the owner (abi.encode(owner, uint256(2)))-> to sentinel_address (0x1).
echo "4.Close the mapping of the owners to the sentinel address."
cast rpc anvil_setStorageAt ${ownerSafe} 0xbc40fbf4394cd00f78fae9763b0c2c71b21ea442c42fdadc5b720537240ebac1 0x0000000000000000000000000000000000000000000000000000000000000001 --rpc-url ${rpcUrl}

cast call 0x847B5C174615B1B7FDF770882256E2D3E95B9D92 "getOwners()" --rpc-url http://localhost:8545
echo "================================================"
forge script -vvvvvvvv ${script} \
--rpc-url ${rpcUrl} \
--sig "runJson(string,bytes)" ${bundlePath} 9f9b94a443b6934cbb00b4285156da7264eb1d85773bb0a904ecfbe830d2b79a0a34afca4a77cf0e022567ac1c898010cac632ec66bdff2f6602b7dfab87c65b \
--broadcast --unlocked --sender 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --skip-simulation # 0x3041..1623 is a signer that contains ethers.
else
forge script ${script} \
--rpc-url ${rpcUrl} \
--sig "signJson(string)" ${bundlePath} \
--sender ${signer}

fi
sign hdPath='0':
#!/usr/bin/env bash
bundlePath=${taskPath}/${bundleName}.json
Expand Down
22 changes: 15 additions & 7 deletions tasks/eth/021-holocene-protocol-versions/SignFromJson.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,34 @@ import {Simulation} from "@base-contracts/script/universal/Simulation.sol";

contract SignFromJson is OriginalSignFromJson, ProtocolVersionsBump {
constructor()
ProtocolVersionsBump(vm.envAddress("OWNER_SAFE"), ProtoVer(9, 0, 0, 0), ProtoVer(9, 0, 0, 0))
ProtocolVersionsBump(
vm.envAddress("OWNER_SAFE"),
ProtoVer(9, 0, 0, 0),
ProtoVer(9, 0, 0, 0)
)
// In the next line, "op" and ""v1.8.0-rc.4" are not relevant.
// This is because we only need to read superchain-wide information from the registry.
// We can use any valid values here.
SuperchainRegistry("mainnet", "op", "v1.8.0-rc.4")
{}

/// @notice Checks the correctness of the deployment
function _postCheck(Vm.AccountAccess[] memory accesses, Simulation.Payload memory /* simPayload */ )
internal
view
override
{
function _postCheck(
Vm.AccountAccess[] memory accesses,
Simulation.Payload memory /* simPayload */
) internal view override {
console.log("Running assertions");
checkStateDiff(accesses);
checkProtocolVersions();
console.log("All assertions passed!");
}

function getAllowedStorageAccess() internal view override returns (address[] memory) {
function getAllowedStorageAccess()
internal
view
override
returns (address[] memory)
{
return allowedStorageAccess;
}

Expand Down