#!/usr/bin/env bash # Clear EIP-7702 delegation on an EOA by signing authorization for the zero address (EIP-7702). # When the transaction sender is the same account as the authority, the authorization tuple # nonce must equal the account nonce AFTER the outer tx nonce is consumed (pending + 1). # # Usage (repo root): # ./scripts/deployment/revoke-eip7702-delegation.sh [--dry-run] [--rpc-url URL] [--chain ID] # # Env: PRIVATE_KEY (via scripts/lib/load-project-env.sh + smom-dbis-138/.env). # Default RPC: ETHEREUM_MAINNET_RPC; default chain: 1. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" # shellcheck source=../../lib/load-project-env.sh source "$PROJECT_ROOT/scripts/lib/load-project-env.sh" DRY_RUN=false RPC_URL="${ETHEREUM_MAINNET_RPC:-}" CHAIN_ID="${CHAIN_ID:-1}" while [[ $# -gt 0 ]]; do case "$1" in --dry-run) DRY_RUN=true ;; --rpc-url=*) RPC_URL="${1#*=}" ;; --rpc-url) RPC_URL="${2:-}"; shift ;; --chain=*) CHAIN_ID="${1#*=}" ;; --chain) CHAIN_ID="${2:-}"; shift ;; *) echo "Unknown option: $1" >&2; exit 2 ;; esac shift done [[ -n "${PRIVATE_KEY:-}" ]] || { echo "ERROR: PRIVATE_KEY not set" >&2; exit 1; } [[ -n "$RPC_URL" ]] || { echo "ERROR: Set ETHEREUM_MAINNET_RPC or pass --rpc-url" >&2; exit 1; } DEPLOYER="$(cast wallet address --private-key "$PRIVATE_KEY")" CODE="$(cast code "$DEPLOYER" --rpc-url "$RPC_URL" 2>/dev/null || true)" if [[ "$CODE" == "0x" || -z "$CODE" ]]; then echo "No contract/delegation code at $DEPLOYER (already plain EOA on this RPC)." exit 0 fi NEXT_NONCE="$(cast nonce "$DEPLOYER" --rpc-url "$RPC_URL")" AUTH_NONCE=$((NEXT_NONCE + 1)) echo "Deployer $DEPLOYER — pending tx nonce $NEXT_NONCE; EIP-7702 auth nonce (must be +1) $AUTH_NONCE" if [[ "$DRY_RUN" == true ]]; then echo "Dry-run: would sign auth for 0x0 with --nonce $AUTH_NONCE and cast send (type 4) to self." exit 0 fi AUTH="$(cast wallet sign-auth 0x0000000000000000000000000000000000000000 \ --rpc-url "$RPC_URL" --chain "$CHAIN_ID" --private-key "$PRIVATE_KEY" --nonce "$AUTH_NONCE")" cast send "$DEPLOYER" \ --rpc-url "$RPC_URL" --chain "$CHAIN_ID" --private-key "$PRIVATE_KEY" \ --value 0 --auth "$AUTH" \ --gas-limit 100000 echo "Verify: cast code $DEPLOYER --rpc-url "