Skip to content

Use Etherscan V2 API for contract verification #34

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

Merged
merged 2 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# cast wallet address --keystore keystore/dcap_prod
OWNER=
OWNER=0xDf841B239bE7a6b37366005107069b7410da4Ff9

ETHERSCAN_API_KEY_OG=
ETHERSCAN_API_KEY_BASE=
ETHERSCAN_API_KEY_OPTIMISM=
ETHERSCAN_API_KEY_ARBITRUM=
ETHERSCAN_API_KEY_WORLDCHAIN=
ETHERSCAN_API_KEY_BSC=
ETHERSCAN_API_KEY_POLYGON=
ETHERSCAN_API_KEY=
ETHERSCAN_API_VERSION=V2
74 changes: 51 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ else
$(error RPC_URL is not set)
endif

# Get the Owner's Wallet Address
# Get the Owner's Wallet Address from private key or keystore
get_owner:
ifdef PRIVATE_KEY
$(eval OWNER := $(shell cast wallet address --private-key $(PRIVATE_KEY)))
Expand All @@ -26,6 +26,14 @@ else
endif
@echo "\nWallet Owner: $(OWNER)"

# Get the Owner's wallet address from env
get_owner_env:
ifdef OWNER
@echo "\nUsing Owner from environment: $(OWNER)"
else
$(error OWNER is not set. Please set the OWNER environment variable.)
endif

# Deployment targets
deploy-helpers: check_env get_owner
@echo "Deploying helper contracts..."
Expand Down Expand Up @@ -79,33 +87,53 @@ verify-helpers: check_env
fi \
done

verify-dao: check_env
verify-dao: check_env get_owner_env
@echo "Verifying DAO contracts..."
@if [ ! -f deployment/$(CHAIN_ID).json ]; then \
echo "DAO addresses not found. Deploy DAOs first."; \
exit 1; \
fi
@for contract in AutomataDaoStorage AutomataPcsDao AutomataPckDao AutomataEnclaveIdentityDao AutomataFmspcTcbDao; do \
addr=$$(jq -r ".$$contract" deployment/$(CHAIN_ID).json); \
if [ "$$addr" != "null" ]; then \
if [ "$$contract" != "AutomataDaoStorage" ]; then \
forge verify-contract \
--rpc-url $(RPC_URL) \
--verifier $(VERIFIER) \
--watch \
$(if $(VERIFIER_URL),--verifier-url $(VERIFIER_URL)) \
$$addr \
src/automata_pccs/$$contract.sol:$$contract || true; \
else \
forge verify-contract \
--rpc-url $(RPC_URL) \
--verifier $(VERIFIER) \
--watch \
$(if $(VERIFIER_URL),--verifier-url $(VERIFIER_URL)) \
$$addr \
src/automata_pccs/shared/AutomataDaoStorage.sol:AutomataDaoStorage || true; \
fi \
fi \
@echo "Determining P256 Verifier address..."
@P256_ADDRESS_VAL=$$(forge script script/utils/P256Configuration.sol:P256Configuration --rpc-url $(RPC_URL) --sig "simulateVerify()" -vv | awk '/P256Verifier address:/ { print $$NF; exit }'); \
echo "Using P256 Verifier address: $$P256_ADDRESS_VAL"; \
STORAGE_ADDR=$$(jq -r ".AutomataDaoStorage" deployment/$(CHAIN_ID).json); \
X509_HELPER_ADDR=$$(jq -r ".PCKHelper" deployment/$(CHAIN_ID).json); \
CRL_HELPER_ADDR=$$(jq -r ".X509CRLHelper" deployment/$(CHAIN_ID).json); \
PCS_DAO_ADDR=$$(jq -r ".AutomataPcsDao" deployment/$(CHAIN_ID).json); \
ENCLAVE_IDENTITY_HELPER_ADDR=$$(jq -r ".EnclaveIdentityHelper" deployment/$(CHAIN_ID).json); \
FMSPC_TCB_HELPER_ADDR=$$(jq -r ".FmspcTcbHelper" deployment/$(CHAIN_ID).json); \
for contract_name_loop in AutomataDaoStorage AutomataPcsDao AutomataPckDao AutomataEnclaveIdentityDao AutomataFmspcTcbDao; do \
contract_addr=$$(jq -r ".$$contract_name_loop" deployment/$(CHAIN_ID).json); \
current_encoded_args=""; \
current_contract_path_name=""; \
if [ "$$contract_addr" != "null" ]; then \
echo "Preparing to verify $$contract_name_loop at $$contract_addr..."; \
if [ "$$contract_name_loop" = "AutomataDaoStorage" ]; then \
current_encoded_args=$$(cast abi-encode "constructor(address)" $(OWNER)); \
current_contract_path_name="src/automata_pccs/shared/AutomataDaoStorage.sol:AutomataDaoStorage"; \
elif [ "$$contract_name_loop" = "AutomataPcsDao" ]; then \
current_encoded_args=$$(cast abi-encode "constructor(address,address,address,address)" $$STORAGE_ADDR $$P256_ADDRESS_VAL $$X509_HELPER_ADDR $$CRL_HELPER_ADDR); \
current_contract_path_name="src/automata_pccs/AutomataPcsDao.sol:AutomataPcsDao"; \
elif [ "$$contract_name_loop" = "AutomataPckDao" ]; then \
current_encoded_args=$$(cast abi-encode "constructor(address,address,address,address,address)" $$STORAGE_ADDR $$P256_ADDRESS_VAL $$PCS_DAO_ADDR $$X509_HELPER_ADDR $$CRL_HELPER_ADDR); \
current_contract_path_name="src/automata_pccs/AutomataPckDao.sol:AutomataPckDao"; \
elif [ "$$contract_name_loop" = "AutomataEnclaveIdentityDao" ]; then \
current_encoded_args=$$(cast abi-encode "constructor(address,address,address,address,address,address)" $$STORAGE_ADDR $$P256_ADDRESS_VAL $$PCS_DAO_ADDR $$ENCLAVE_IDENTITY_HELPER_ADDR $$X509_HELPER_ADDR $$CRL_HELPER_ADDR); \
current_contract_path_name="src/automata_pccs/AutomataEnclaveIdentityDao.sol:AutomataEnclaveIdentityDao"; \
elif [ "$$contract_name_loop" = "AutomataFmspcTcbDao" ]; then \
current_encoded_args=$$(cast abi-encode "constructor(address,address,address,address,address,address)" $$STORAGE_ADDR $$P256_ADDRESS_VAL $$PCS_DAO_ADDR $$FMSPC_TCB_HELPER_ADDR $$X509_HELPER_ADDR $$CRL_HELPER_ADDR); \
current_contract_path_name="src/automata_pccs/AutomataFmspcTcbDao.sol:AutomataFmspcTcbDao"; \
fi; \
echo "Verifying $$contract_name_loop with encoded args: $$current_encoded_args"; \
forge verify-contract \
--rpc-url $(RPC_URL) \
--verifier $(VERIFIER) \
--watch \
$(if $(VERIFIER_URL),--verifier-url $(VERIFIER_URL)) \
$$contract_addr \
$$current_contract_path_name \
--constructor-args $$current_encoded_args || true; \
fi; \
done

verify-all: verify-helpers verify-dao
Expand Down
32 changes: 16 additions & 16 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ evm_version = "paris"
# sparse_mode = false

[etherscan]
base_sepolia = { key = "${ETHERSCAN_API_KEY_BASE}", url = "https://api-sepolia.basescan.org/api" }
holesky = { key = "${ETHERSCAN_API_KEY_OG}", url = "https://api-holesky.etherscan.io/api" }
sepolia = { key = "${ETHERSCAN_API_KEY_OG}", url = "https://api-sepolia.etherscan.io/api" }
optimism_sepolia = { key = "${ETHERSCAN_API_KEY_OPTIMISM}", url = "https://api-sepolia-optimistic.etherscan.io/api" }
arbitrum_sepolia = { key = "${ETHERSCAN_API_KEY_ARBITRUM}", url = "https://api-sepolia.arbiscan.io/api" }
world_sepolia = { key = "${ETHERSCAN_API_KEY_WORLDCHAIN}", url = "https://api-sepolia.worldscan.org/api" }
bsc_testnet = { key = "${ETHERSCAN_API_KEY_BSC}", url = "https://api-testnet.bscscan.com/api" }
polygon_amoy = { key = "${ETHERSCAN_API_KEY_POLYGON}", url = "https://api-amoy.polygonscan.com/api", chain = 80002 }
unichain_sepolia = { key = "${ETHERSCAN_API_KEY_UNICHAIN}", url = "https://api-sepolia.uniscan.xyz/api", chain = 1301 }
mainnet = { key = "${ETHERSCAN_API_KEY_OG}", url = "https://api.etherscan.io/api" }
base = { key = "${ETHERSCAN_API_KEY_BASE}", url = "https://api.basescan.org/api" }
optimism = { key = "${ETHERSCAN_API_KEY_OPTIMISM}", url = "https://api-optimistic.etherscan.io/api" }
arbitrum = { key = "${ETHERSCAN_API_KEY_ARBITRUM}", url = "https://api.arbiscan.io/api" }
world = { key = "${ETHERSCAN_API_KEY_WORLDCHAIN}", url = "https://api.worldscan.org/api" }
bsc = { key = "${ETHERSCAN_API_KEY_BSC}", url = "https://api.bscscan.com/api" }
polygon_pos = { key = "${ETHERSCAN_API_KEY_POLYGON}", url = "https://api.polygonscan.com/api" }
base_sepolia = { key = "${ETHERSCAN_API_KEY}" }
holesky = { key = "${ETHERSCAN_API_KEY}" }
sepolia = { key = "${ETHERSCAN_API_KEY}" }
optimism_sepolia = { key = "${ETHERSCAN_API_KEY}" }
arbitrum_sepolia = { key = "${ETHERSCAN_API_KEY}" }
world_sepolia = { key = "${ETHERSCAN_API_KEY}" }
bsc_testnet = { key = "${ETHERSCAN_API_KEY}" }
polygon_amoy = { key = "${ETHERSCAN_API_KEY}", chain = 80002 }
unichain_sepolia = { key = "${ETHERSCAN_API_KEY}", chain = 1301 }
mainnet = { key = "${ETHERSCAN_API_KEY}" }
base = { key = "${ETHERSCAN_API_KEY}" }
optimism = { key = "${ETHERSCAN_API_KEY}" }
arbitrum = { key = "${ETHERSCAN_API_KEY}" }
world = { key = "${ETHERSCAN_API_KEY}" }
bsc = { key = "${ETHERSCAN_API_KEY}" }
polygon_pos = { key = "${ETHERSCAN_API_KEY}" }

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
2 changes: 1 addition & 1 deletion script/utils/P256Configuration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "forge-std/Script.sol";

pragma solidity ^0.8.0;

abstract contract P256Configuration is Script {
contract P256Configuration is Script {
using BytesUtils for bytes;

address constant RIP7212_P256_PRECOMPILE = 0x0000000000000000000000000000000000000100;
Expand Down